A Laravel 5+ wrapper for the Timber Logger service. Use it to log HTTP requests or custom events to Timber.
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
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,
];
}
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]);
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();
You can disable sending logs to Timber by updating your .env file with
TIMBER_ENABLED=false
$ phpunit
Please see contributing.md for details and a todolist.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
MIT. Please see the license file for more information.