golin/monologgly

Loggly helpers for php

v1.0.4 2016-07-05 12:10 UTC

This package is not auto-updated.

Last update: 2024-11-09 20:17:34 UTC


README

This extends the basic loggly handler provided by monolog, adding the following information as context:

  • the environment
  • whether the log happened on a request, or CLI call
  • information about the http request (url, method)
  • information about the origin of the log call (file and line, class and method (if relevant))
  • some simplified exception information (if the log comes from a "normal" exception log - ie. logging, or __toString-ing the exception)

Note: there is currently a bug with the class and method origin / backtrace information.

Installation

composer require golin/monologgly

Exceptions

To log exception information, simply add the exception to the context:

$logger->debug('Oh No!', ['exception' => $e]);

The exception object will be removed before final logging, and replaced with an array interpretation of it. It will still be available to all other processors added (as long as they are added before the exception information processor (which they will be using the provided service provider)).

Setup with Laravel

Config

Add the following to config/app.php:

    'loggly-token' => env('LOGGLY_TOKEN'),

and add your loggly token to your .env file. Ommitting this will mean that the loggly monlog handler will not be loaded (and nothing will be sent to loggly) - basically, it's safe to not have this key when developing locally.

Provider

Add the following file, as LogglyServiceProvider.php, and put it in your application's service providers config in config/app.php.

Update the $name property with your application's name.

<?php

namespace App\Providers;

use Golin\MonoLoggly\LogglyServiceProvider as BaseProvider;
use Monolog\Monolog;

class LogglyServiceProvider extends BaseProvider {

    /**
     * The log name. This should uniquely identify the log.
     *
     * @var string
     */
    protected $name;

    /**
     * The minimum log level.
     *
     * @var int
     */
    protected $level = Monolog::DEBUG;

    /**
     * A place to construct any other processors that will be added to 
     * the loggly handler.
     *
     * @return array   An array of callables objects
     */
    protected function processors()
    {
        return [];
    }

}