From abc83ccc5f89bcba319923c08b3a5d2b5a1827b1 Mon Sep 17 00:00:00 2001 From: Carlos Umanzor Date: Mon, 4 Dec 2017 12:10:11 -0600 Subject: [PATCH 1/3] Adding papertrail support via SyslogUDPHandler --- .idea/php.xml | 4 ++++ .idea/vcs.xml | 6 ++++++ README.md | 4 ++-- application/config/monolog.php | 12 +++++++++--- application/libraries/Log.php | 13 +++++++------ composer.json | 2 +- 6 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 .idea/php.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000..10b171f --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 490c651..f6c05bc 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Codeigniter-Monolog +Codeigniter-Monolog - with PaperTrail support =================== Simple integration of the Monolog Package (https://github.com/Seldaek/monolog) into CodeIgniter by overwriting the CI_Log class. @@ -7,7 +7,7 @@ Based on https://github.com/pfote/Codeigniter-Monolog, but updating monolog to 1 This library registers Monolog as the PHP error handler to catch all errors and adds support for IntrospectionProcessor for additional meta data. -Supports File (RotatingFileHandler), New Relic (NewRelicHandler) and HipChat (HipChatHandler). +Supports File (RotatingFileHandler), New Relic (NewRelicHandler), HipChat (HipChatHandler) and Papertrail via SyslogUdpHandler. Installation ------------ diff --git a/application/config/monolog.php b/application/config/monolog.php index 1dae050..53ee99c 100644 --- a/application/config/monolog.php +++ b/application/config/monolog.php @@ -2,9 +2,10 @@ exit('No direct script access allowed'); } /* - * CodeIgniter Monolog integration + * CodeIgniter Monolog integration - Plus Papertrail support * - * (c) Steve Thomas + * (adjustments) Carlos Umanzor + * (original idea and concept) Steve Thomas * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -12,11 +13,16 @@ /* GENERAL OPTIONS */ -$config['handlers'] = array('file', 'new_relic', 'hipchat'); // valid handlers are file | new_relic | hipchat +//$config['handlers'] = array('file', 'new_relic', 'hipchat', 'papertrail'); // valid handlers are file | new_relic | hipchat | papertrail +$config['handlers'] = array('papertrail'); // Send logs to papertrail only $config['channel'] = ENVIRONMENT; // channel name which appears on each line of log $config['threshold'] = '4'; // 'ERROR' => '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4' $config['introspection_processor'] = TRUE; // add some meta data such as controller and line number to log messages +/* PAPERTRAIL OPTIONS*/ +$config['papertrail_hostname'] = 'logsX.papertrailapp.com"'; +$config['papertrail_port'] = 49643; + /* FILE HANDLER OPTIONS * Log to default CI log directory (must be writable ie. chmod 757). * Filename will be encoded to current system date, ie. YYYY-MM-DD-ci.log diff --git a/application/libraries/Log.php b/application/libraries/Log.php index db5da65..513bb81 100644 --- a/application/libraries/Log.php +++ b/application/libraries/Log.php @@ -3,10 +3,10 @@ } /* - * CodeIgniter Monolog integration + * CodeIgniter Monolog integration - Plus Papertrail support * - * Version 1.1.1 - * (c) Steve Thomas + * (adjustments) Carlos Umanzor + * (original idea and concept) Steve Thomas * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -18,6 +18,7 @@ use Monolog\Handler\NewRelicHandler; use Monolog\Handler\HipChatHandler; use Monolog\Processor\IntrospectionProcessor; +use Monolog\Handler\SyslogUdpHandler; /** * replaces CI's Logger class, use Monolog instead @@ -72,14 +73,15 @@ public function __construct() // decide which handler(s) to use foreach ($this->config['handlers'] as $value) { switch ($value) { + case 'papertrail': + $handler = new SyslogUdpHandler($this->config['papertrail_hostname'], $this->config['papertrail_port']); + break; case 'file': $handler = new RotatingFileHandler($this->config['file_logfile']); break; - case 'new_relic': $handler = new NewRelicHandler(Logger::ERROR, true, $this->config['new_relic_app_name']); break; - case 'hipchat': $handler = new HipChatHandler( $config['hipchat_app_token'], @@ -88,7 +90,6 @@ public function __construct() $config['hipchat_app_notify'], $config['hipchat_app_loglevel']); break; - default: exit('log handler not supported: ' . $this->config['handler']); } diff --git a/composer.json b/composer.json index 70737d1..2c9b3a8 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { "require": { - "monolog/monolog": "~1.17" + "monolog/monolog": "1.22.0" } } From 895c03c9b88b29d3b076411b657bf3ebf8465f78 Mon Sep 17 00:00:00 2001 From: Carlos Umanzor Date: Mon, 4 Dec 2017 13:04:40 -0600 Subject: [PATCH 2/3] Adding papertrail support via SyslogUDPHandler --- README.md | 6 ++++-- application/config/monolog.php | 12 +++++++----- application/{libraries/Log.php => core/MY_Log.php} | 6 ++++-- 3 files changed, 15 insertions(+), 9 deletions(-) rename application/{libraries/Log.php => core/MY_Log.php} (98%) diff --git a/README.md b/README.md index f6c05bc..2017977 100644 --- a/README.md +++ b/README.md @@ -3,17 +3,19 @@ Codeigniter-Monolog - with PaperTrail support Simple integration of the Monolog Package (https://github.com/Seldaek/monolog) into CodeIgniter by overwriting the CI_Log class. -Based on https://github.com/pfote/Codeigniter-Monolog, but updating monolog to 1.7.* and supporting file logging more akin to native CodeIgniter logging. +Based on https://github.com/pfote/Codeigniter-Monolog, but updating monolog to 1.22.* and supporting file logging more akin to native CodeIgniter logging. This library registers Monolog as the PHP error handler to catch all errors and adds support for IntrospectionProcessor for additional meta data. Supports File (RotatingFileHandler), New Relic (NewRelicHandler), HipChat (HipChatHandler) and Papertrail via SyslogUdpHandler. +Compatible with Codeigniter 3.6 and up + Installation ------------ * Install monolog with ```composer require monolog/monolog``` * Make sure your index.php contains ```include_once './vendor/autoload.php';``` -* Copy application/libraries/Log.php and application/config/monolog.php into your CodeIgniter application +* Copy application/core/MY_Log.php and application/config/monolog.php into your CodeIgniter application Usage ----- diff --git a/application/config/monolog.php b/application/config/monolog.php index 53ee99c..f2b74c8 100644 --- a/application/config/monolog.php +++ b/application/config/monolog.php @@ -1,6 +1,8 @@ '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4' +$config['channel'] = 'My log'; // channel name which appears on each line of log, use proper naming for control +$config['threshold'] = '2'; // 'ERROR' => '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4' $config['introspection_processor'] = TRUE; // add some meta data such as controller and line number to log messages -/* PAPERTRAIL OPTIONS*/ -$config['papertrail_hostname'] = 'logsX.papertrailapp.com"'; -$config['papertrail_port'] = 49643; +/* PAPERTRAIL OPTIONS - Make sure you add the right hostname and port*/ +$config['papertrail_hostname'] = 'logsX.papertrailapp.com'; +$config['papertrail_port'] = '#####'; /* FILE HANDLER OPTIONS * Log to default CI log directory (must be writable ie. chmod 757). diff --git a/application/libraries/Log.php b/application/core/MY_Log.php similarity index 98% rename from application/libraries/Log.php rename to application/core/MY_Log.php index 513bb81..b034c89 100644 --- a/application/libraries/Log.php +++ b/application/core/MY_Log.php @@ -12,6 +12,8 @@ * file that was distributed with this source code. */ +require_once APPPATH.'vendor/autoload.php'; + use Monolog\Logger; use Monolog\ErrorHandler; use Monolog\Handler\RotatingFileHandler; @@ -26,7 +28,7 @@ * see https://github.com/stevethomas/codeigniter-monolog & https://github.com/Seldaek/monolog * */ -class CI_Log +class MY_Log { // CI log levels protected $_levels = array( @@ -148,4 +150,4 @@ public function write_log( } return true; } -} +} \ No newline at end of file From 1653127c20488ec1803aff1199e426b0fcdd1605 Mon Sep 17 00:00:00 2001 From: Carlos Alberto Umanzor Arguedas Date: Mon, 4 Dec 2017 13:33:24 -0600 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2017977..991b048 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ This library registers Monolog as the PHP error handler to catch all errors and Supports File (RotatingFileHandler), New Relic (NewRelicHandler), HipChat (HipChatHandler) and Papertrail via SyslogUdpHandler. -Compatible with Codeigniter 3.6 and up +Compatible with Codeigniter 3.1.6 and up Installation ------------