toanlk / codeigniter_telescope
A simple log viewer for Codeigniter
Package info
github.com/toanlk/codeigniter-telescope
Language:HTML
pkg:composer/toanlk/codeigniter_telescope
Requires
- php: >=5.4.8
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Install
Install via composer
composer require toanlk/codeigniter_telescope
Autoload
Edit application/config/config.php:
$config['composer_autoload'] = FALSE;
↓
$config['composer_autoload'] = realpath(APPPATH . '../vendor/autoload.php');
The folder path for log files can be configured by adding ci_telescope_log_folder_path to Codeigniter config.php file e.g.
$config['ci_telescope_log_folder_path'] = STORAGE_PATH.'/storage/logs/';
Other optional settings:
// which files of the folder are logs (default: log-*.php)
$config['ci_telescope_log_file_pattern'] = 'log-*.php';
// larger files are offered as a download instead of being opened (default: 50 MB)
$config['ci_telescope_max_file_size'] = 52428800;
Features
- Search every entry of a file, stack traces included. Plain text by default; press
.*to use a regular expression. - Filter by level, with a count for each level found in the file.
- Pagination, newest or oldest first, 10 to 250 entries per page.
- Click a
[req:id]tag to see every entry of that request. - Light (default), dark and system themes, usable on a phone. No external scripts, styles or fonts.
- The search, filters and page are kept in the URL, so a link can be shared.
Security
Logs often contain personal data such as IP addresses and emails, and this page can delete them.
The library does not authenticate anyone: protect the route in your controller, for example with your admin login check.
The delete buttons and the api=delete command only accept a POST request with a CSRF token.
Upgrading from 1.0.x
The view now renders directly from this package, so upgrades take effect immediately.
application/views/ci_telescope/logs_view.php, copied there by older versions, is no longer used and can be deleted. Any changes you made to that copy no longer apply.
?del= in the URL no longer deletes anything. Use the delete buttons on the page, or api=delete from code.
api=delete no longer works over GET. Send a POST with any 32 character hex value as both the ci_telescope_token cookie and field, and keep api and f in the query string:
curl -X POST -b "ci_telescope_token=$TOKEN" -d "ci_telescope_token=$TOKEN" "https://example.com/logs?api=delete&f=$BASE64_FILE"
If your application enables csrf_protection, the request also needs CI's own CSRF cookie and field, or the URI listed in csrf_exclude_uris.
Integration
All that is required is to execute the show() method in a Controller that is mapped to a route:
A typical Controller (Logs.php) will have the following content:
class Logs extends CI_Controller
{
private $logViewer;
public function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->logViewer = new \CI_Telescope\CI_Telescope();
}
public function index()
{
echo $this->logViewer->show();
}
// --------------------------------------------------------------------
public function get_last_logs()
{
echo $this->logViewer->get_last_logs();
}
}
Tests
php tests/run.php
php -d memory_limit=128M tests/run.php --large
Release
Update VERSION in both build.sh and src/CI_Telescope.php, then:
git tag 1.0.1
git push origin 1.0.1
git push --tags