Skip to content

Commit

Permalink
Using papertrail.ident instead of papertrail.channel
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Hallgren <[email protected]>
  • Loading branch information
challgren committed Feb 22, 2022
1 parent 2d4a030 commit 3d4edc7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 44 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"monolog/monolog": "^2.2"
},
"require-dev": {
"phpunit/phpunit": "^8.0"
"phpunit/phpunit": "^8.5 || ^9.3"
},
"autoload": {
"psr-4": {
Expand Down
48 changes: 5 additions & 43 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

use Cake\Core\BasePlugin;
use Cake\Core\PluginApplicationInterface;
use Cake\Http\MiddlewareQueue;
use Cake\Routing\RouteBuilder;
use Cake\Core\Configure;
use Cake\Log\Log;
use Monolog\Formatter\LineFormatter;
Expand All @@ -31,21 +29,21 @@ public function bootstrap(PluginApplicationInterface $app): void
{
if (
!Configure::read('debug')
&& Configure::read('papertrail.host', getenv('PAPERTRAIL_HOST') ?? getenv('PAPERTRAIL_URL'))
&& Configure::read('papertrail.port', getenv('PAPERTRAIL_PORT'))
&& Configure::read('papertrail.host', env('PAPERTRAIL_HOST') ?? env('PAPERTRAIL_URL'))
&& Configure::read('papertrail.port', env('PAPERTRAIL_PORT'))
) {
Log::setConfig('default', function () {
$output = "%level_name% %message%";
$formatter = new LineFormatter($output, 'Y-m-d H:i:s.v');

$log = new Logger(strval(Configure::read('papertrail.channel', 'cakephp')));
$sysLog = new SyslogUdpHandler(
strval(Configure::read('papertrail.host', getenv('PAPERTRAIL_HOST') ?? getenv('PAPERTRAIL_URL'))),
intval(Configure::read('papertrail.port', getenv('PAPERTRAIL_PORT'))),
strval(Configure::read('papertrail.host', env('PAPERTRAIL_HOST') ?? env('PAPERTRAIL_URL'))),
intval(Configure::read('papertrail.port', env('PAPERTRAIL_PORT'))),
LOG_USER,
Logger::DEBUG,
true,
strval(Configure::read('papertrail.channel', 'ident'))
strval(Configure::read('papertrail.ident', 'ident'))
);
$sysLog->setFormatter($formatter);
$log->pushHandler($sysLog);
Expand All @@ -59,40 +57,4 @@ public function bootstrap(PluginApplicationInterface $app): void
}
}
}

/**
* Add routes for the plugin.
*
* If your plugin has many routes and you would like to isolate them into a separate file,
* you can create `$plugin/config/routes.php` and delete this method.
*
* @param \Cake\Routing\RouteBuilder $routes The route builder to update.
* @return void
*/
public function routes(RouteBuilder $routes): void
{
$routes->plugin(
'PaperTrailLogger',
['path' => '/paper-trail-logger'],
function (RouteBuilder $builder) {
// Add custom routes here

$builder->fallbacks();
}
);
parent::routes($routes);
}

/**
* Add middleware for the plugin.
*
* @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to update.
* @return \Cake\Http\MiddlewareQueue
*/
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
{
// Add your middlewares here

return $middlewareQueue;
}
}

0 comments on commit 3d4edc7

Please sign in to comment.