Giter VIP home page Giter VIP logo

laravel-log-enhancement's Introduction

laravel-log-enhancement

Software License CircleCI Total Downloads

A library with logging enhancement. Including:

  • Overriding Log facade

    • It extends default Laravel Log facade with logging adding class path and tracking id into context.
  • LogglyHandler class

    • It extends monolog's LogglyHandler with tags support
  • DatadogHandler class

    • It supports Datadog Logs

Install

composer require onramplab/laravel-log-enhancement
  • use Datadog APM to connect php logs and traces
curl -LO https://github.com/DataDog/dd-trace-php/releases/latest/download/datadog-setup.php
sudo php datadog-setup.php --php-bin=all

Usage

LoggerFacade

The log json will look like this:

{
  "message": "Test",
  "context": {
    "class_path": "App\\Fake",
    "tracking_id": "652c3456-1a17-42b8-9fa7-9bee65e655eb"
  },
  "level": 200,
  "level_name": "INFO",
  "channel": "local",
  "extra": {},
  "timestamp": "2021-01-04T22:47:56.598608-0800"
}

LogglyHandler

You can adding following block into config/logging.php.

use Monolog\Formatter\LogglyFormatter;
use Onramplab\LaravelLogEnhancement\Handlers\LogglyHandler;

return [
  //...


  'channels' => [
    //...

    'loggly' => [
        'driver' => 'monolog',
        'level' => 'info',
        'handler' => LogglyHandler::class,
        'handler_with' => [
            'token' => env('LOGGLY_TOKEN'),
            'tags' => env('LOGGLY_TAGS'),
        ],
        'formatter' => LogglyFormatter::class,
    ],
  ]
];

DatadogHandler

You can adding following block into config/logging.php.

use Monolog\Formatter\JsonFormatter;
use Onramplab\LaravelLogEnhancement\Handlers\DatadogHandler;

return [
  //...

  'channels' => [
    //...

    'datadog' => [
      'driver' => 'monolog',
      'level' => 'info',
      'handler' => DatadogHandler::class,
      'handler_with' => [
          'key' => env('DD_LOG_API_KEY'),
          'region' => env('DD_LOG_REGION', 'us5'),
          'attributes' => [
              'hostname' => gethostname(),
              'source' => env('DD_LOG_SOURCE', 'laravel'),
              'service' => env('DD_LOG_SERVICE'),
              'tags' => env('DD_LOG_TAG'),
          ],
      ],
      'formatter' => JsonFormatter::class,
    ],
  ]
];

Testing

Run the tests with:

vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security-related issues, please email [email protected] instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.# laravel-log-enhancement

laravel-log-enhancement's People

Contributors

koshuang avatar musigm avatar chenghung 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.