nestednet/timber-laravel-sentinel

Laravel package for communicating with Timber (timber.io) logger API

v1.0.10 2019-10-04 15:08 UTC

This package is auto-updated.

Last update: 2024-12-05 02:49:39 UTC


README

Latest Version on Packagist Total Downloads Build Status

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/graphql.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.