rebing / timber-laravel
Laravel package for communicating with Timber (timber.io) logger API
Installs: 31 703
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 3
Forks: 5
Open Issues: 3
Requires
- php: >=7.1
- guzzlehttp/guzzle: ^7.0
- illuminate/support: 5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0
- symfony/psr-http-message-bridge: ^1.1|^2.0
Requires (Dev)
- mockery/mockery: ^1.1
- orchestra/testbench: ~3.0
- phpunit/phpunit: ~7.0
- sempro/phpunit-pretty-print: ^1.0
This package is auto-updated.
Last update: 2024-12-21 23:13:52 UTC
README
A Laravel 5+ wrapper for the Timber Logger service. Use it to log HTTP requests or custom events to Timber.
Installation
1. Require the package via Composer
$ composer require rebing/timber-laravel
2. Laravel 5.5+ will autodiscover the package, for older versions add the following service provider
Rebing\Timber\TimberServiceProvider::class,
and alias
'Timber' => 'Rebing\Timber\Support\Facades\Timber',
in your config/app.php
file.
3. Publish the configuration file
$ php artisan vendor:publish --provider="Rebing\Timber\TimberServiceProvider"
4. Review the configuration file
config/timber.php
and add your Timber API key to .env
5. (Optional) Log incoming requests
Check HTTP Requests
6. (Optional) Log all messages
Check Log all messages
Usage
HTTP Requests
To log HTTP requests use the Rebing\Timber\Middleware\LogRequest::class
middleware.
This will log all incoming requests and responses, including context and Auth data.
For example, you can add it to Kernel.php
:
class Kernel extends HttpKernel { /** * The application's global HTTP middleware stack. * * These middleware are run during every request to your application. */ protected $middleware = [ Rebing\Timber\Middleware\LogRequest::class, ]; }
Log all messages
This requires Laravel 5.6+
You can leverage Laravel's Logger
facade to log all messages to Timber.
Add a new channel to config/logging.php
'channels' => [ 'timber' => [ 'driver' => 'monolog', 'handler' => Rebing\Timber\Handlers\TimberHandler::class, ], ];
And update your .env with LOG_CHANNEL=timber
You can then easily log custom data by providing a message, type and data. For example:
$data = [ 'key' => 'value', ]; \Log::info('Some message', ['type' => $data]);
Custom Events
You can also log custom data. Context will be added automatically.
use Rebing\Timber\Requests\Events\CustomEvent; $data = [ 'some' => 'data', ]; $customEvent = new CustomEvent('Log message', 'custom', $data); dispatch($customEvent); // Or $customEvent->send();
Disable logging
You can disable sending logs to Timber by updating your .env file with
TIMBER_ENABLED=false
Testing
$ phpunit
Contributing
Please see contributing.md for details and a todolist.
Security
If you discover any security related issues, please email mikk.nurges@rebing.ee instead of using the issue tracker.
Credits
License
MIT. Please see the license file for more information.