Giter Club home page Giter Club logo

timber-laravel's Introduction

Timber

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 [email protected] instead of using the issue tracker.

Credits

License

MIT. Please see the license file for more information.

timber-laravel's People

Contributors

snurges avatar

Watchers

Eudald Arranz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.