stephanecoinon / papertrail
Integrate Papertrail log monitor in your PHP applications
Installs: 55 597
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 2
Forks: 3
Open Issues: 0
Requires
- php: >=5.4
Requires (Dev)
- guzzlehttp/guzzle: ^6.1
- monolog/monolog: ~1.11
- phpunit/phpunit: ^7.0
- vlucas/phpdotenv: ^2.4
Suggests
- monolog/monolog: Allows more advanced logging of the application flow
This package is auto-updated.
Last update: 2024-11-11 14:43:31 UTC
README
Easily integrate Papertrail log monitor in your PHP applications. This package provides integration for plain vanilla PHP and Laravel.
Installation
composer require stephanecoinon/papertrail
Configuration
It is good practice not to include credentials in your code so passwords are not stored in version control. Keeping sensitive info in your code could become an issue when you need to open source or share your code with other developers. For this reason, this package will get your papertrail log server details from environment variables PAPERTRAIL_HOST
and PAPERTRAIL_PORT
by default.
This package ships with 2 drivers:
Php
for plain PHP applicationsLaravel
for Laravel applications from version 4.2 to 5.6
Plain Vanilla PHP
For plain PHP applications, we recommend also installing Monolog:
composer require monolog/monolog
then integrate the papertrail package like so:
require __DIR__ . '/vendor/autoload.php'; use StephaneCoinon\Papertrail\Php as Papertrail; // Boot using default settings (ie Papertrail log server and port // from environment variables and no log message prefix). // It also gives you a monolog instance in the process. $logger = Papertrail::boot(); // Now your logs will appear in Papertrail dashboard. $logger->info('test log');
Laravel 4
Add these lines in your start/global.php
:
// Pass all parameters \StephaneCoinon\Papertrail\Laravel::boot($host, $port, $prefix);
or
// Grab log server details from environment variables and use a prefix \StephaneCoinon\Papertrail\Laravel::bootWithPrefix('MY_APP');
Laravel 5
Edit app/Providers/AppServiceProvider.php
and add this line in boot
method:
\StephaneCoinon\Papertrail\Laravel::boot();
then test it's working:
// routes/web.php Route::get('log', function () { Log::info('test log', ['foo' => 'bar']); return 'Logged'; });
API reference
All drivers provide the following interface:
/** * Boot connector with given host, port and log message prefix. * * If host or port are omitted, we'll try to get them from the environment * variables PAPERTRAIL_HOST and PAPERTRAIL_PORT. * * @param string $host Papertrail log server, ie log.papertrailapp.com * @param int $port Papertrail port number for log server * @param string $prefix Prefix to use for each log message * @return \Psr\Log\LoggerInterface */ public static function boot($host = null, $port = null, $prefix = '')
/** * Boot connector using credentials set in environment variables and the * given log message prefix. * * @param string $prefix Prefix to use for each log message * @return \Psr\Log\LoggerInterface */ public static function bootWithPrefix($prefix)
Tests
First, copy .env.dist
as .env
and set your Papertrail host, port and API key in it.
Then run PHPUnit:
./vendor/bin/phpunit