2017 © Pedro Peláez
 

library logger

Logging package for Laravel 5

image

nztim/logger

Logging package for Laravel 5

  • Wednesday, June 13, 2018
  • by nztim
  • Repository
  • 1 Watchers
  • 7 Stars
  • 10,165 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 19 Versions
  • 9 % Grown

The README.md

Logger

Logger complements or replaces standard Laravel logging. It logs to local files and optionally provides email alerts., (*1)

Installation

Register the service provider:
NZTim\Logger\LoggerServiceProvider::class,, (*2)

Add facade reference:
'Logger' => NZTim\Logger\LoggerFacade::class,, (*3)

Configuration

Publish the configuration file with: php artisan vendor:publish --provider=NZTim\Logger\LoggerServiceProvider., (*4)

  • 'laravel' => true, captures Laravel log facade messages
  • 'folder' => 'custom' sets the default subfolder for custom logs
  • 'daily' => [] list of log files to be handled as daily logs
  • 'max_daily' => 7 maximum number of daily log files to keep
  • 'email.send' => false turns sending of error emails on/off
  • 'email.level' => 'ERROR' sets the level at which email notifications are sent
  • 'email.recipient' => 'recipient@example.com', sets the email recipient

Usage

Use the facade to write to custom log files. By default files are stored in storage/logs/custom:, (*5)

Logger::info('auth', 'User login from 1.2.3.4');
Logger::warning('audit', 'A record was updated');
Logger::error('exceptions', 'Fatal exception: ');  

If you wish to store a logfile in a subfolder, use dot notation:, (*6)

Logger::info('audit.auth', 'User login from 1.2.3.4'); // Logs to `storage/logs/custom/audit/auth.log`

A requestInfo() method is available to provide context for the message, including IP address, request type/URL, Auth::user()->id and input data, (*7)

Logger::warning('audit', 'An unusual request', Logger::requestInfo());

Fatal errors occurring during the logging process, are stored in storage/logs/fatal-logger-errors.log. For example, a message will be logged here when the system is unable to send an error notification., (*8)

Hook into Laravel exceptions:

Make sure the logger.laravel configuration option is set to true, and update your error handler:, (*9)

// app/Exceptions/Handler.php
use Logger;

public function report(Exception $e)
{
    $class = (new \ReflectionClass($e))->getShortName();
    Logger::error('exceptions', "Exception {$class} | {$e->getMessage()}", Logger::requestInfo());
    return parent::report($e);
}

Email alerts

Emails are only triggered if email sending is turned on, app.debug is false and the relevant error level meets the requirement. The Laravel mail system must be configured for emails to function., (*10)

Database handler

  • Add the table using php artisan logger:migration and php artisan migrate
  • Use the config file to set which channels should be logged to the database
  • You may now query the database using the Eloquent model DbEntry

Changelog

  • v0.6: Enable daily log files by configuration
    • Upgrade: add new config file entries: 'daily' => [], 'max_daily' => 7,
  • v0.5: Enable configuration of base folder and dot notation for subfolders
    • Upgrade: add new config file entry: 'folder' => 'custom',
  • v0.4: Add database handler.
    • Upgrade: add new config file entries. To log entries to the database, add and run the migration, then update config file settings accordingly.
  • v0.3: Remove Papertrail handler, use config file instead of .env, require PHP7.
    • Upgrade: publish and update the config file, make sure Papertrail handler is not required.

The Versions

13/06 2018

dev-master

9999999-dev

Logging package for Laravel 5

  Sources   Download

MIT

The Requires

 

13/06 2018

v0.8

0.8.0.0

Logging package for Laravel 5

  Sources   Download

MIT

The Requires

 

23/03 2017

v0.7

0.7.0.0

Logging package for Laravel 5

  Sources   Download

MIT

The Requires

 

01/02 2017

v0.6.0

0.6.0.0

Logging package for Laravel 5

  Sources   Download

MIT

The Requires

 

01/02 2017

v0.5.2

0.5.2.0

Logging package for Laravel 5

  Sources   Download

MIT

The Requires

 

01/02 2017

v0.5.1

0.5.1.0

Logging package for Laravel 5

  Sources   Download

MIT

The Requires

 

31/01 2017

v0.5.0

0.5.0.0

Logging package for Laravel 5

  Sources   Download

MIT

The Requires

 

10/01 2017

v0.4.0

0.4.0.0

Logging package for Laravel 5

  Sources   Download

MIT

The Requires

 

10/01 2017

v0.3.1

0.3.1.0

Logging package for Laravel 5

  Sources   Download

MIT

The Requires

 

31/05 2015

v0.2.3

0.2.3.0

Logging package for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

31/05 2015

v0.2.2

0.2.2.0

Logging package for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

31/05 2015

0.2.1

0.2.1.0

Logging package for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

31/05 2015

0.2.0

0.2.0.0

Logging package for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

29/05 2015

v0.1.10

0.1.10.0

Logging package for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

28/05 2015

v0.1.9

0.1.9.0

Logging package for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

27/05 2015

v0.1.8

0.1.8.0

Logging package for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

27/05 2015

v0.1.7

0.1.7.0

Logging package for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

27/05 2015

v0.1.6

0.1.6.0

Logging package for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

27/05 2015

v0.1.5

0.1.5.0

Logging package for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires