Lightweight Laravel package for writing custom logs and error messages to a database.

v1.0.0 2015-09-20 01:27 UTC

This package is not auto-updated.

Last update: 2024-05-15 09:20:57 UTC


README

Latest Version on Packagist Total Downloads Software License

DBlog is a lightweight and simple Laravel Package that allows you write custom logs and error messages to a database table.

Written to mirror the Laravel Logging conventions, DBlog provides 8 logging levels defined in RFC 5424 and the ability to add an optional context array to each log.

NOTE: This package DOES NOT integrate with the Laravel / Monolog logging system and does not capture system level events. It's purpose is to be used to capture your own custom log needs.

Installation

Via Composer:

$ composer require supersixtwo/dblog

Then add the service provider in config/app.php:

Supersixtwo\Dblog\DBlogServiceProvider::class,

And the alias in config/app.php:

'DBlog'		=> Supersixtwo\Dblog\DBlogClass::class,

Re-run the autoload:

$ composer dump-autoload

Publish the migrations:

$ php artisan vendor:publish

Run the migrations to install the tables in the database:

$ php artisan migrate

Usage

Logging Messages

We've provided DBlog with a familiar interface, mirroring Laravel's own built-in logging methods. These follow the same RFC 5424 defined logging levels including: emergency, alert, critical, error, warning, notice, info, and debug.

Include the DBlog at the top of your class or model:

use DBlog;

Use one of the 8 helper methods in your logic:

DBlog::emergency($msg);
DBlog::alert($msg);
DBlog::critical($msg);
DBlog::error($msg);
DBlog::warning($msg);
DBlog::notice($msg);
DBlog::info($msg);
DBlog::debug($msg);

Contextual Information

In addition to logging text based messages, you can also an array of contextual information to the logging methods. This contextual data will converted to a json array and stored in separate column.

DBlog::info('New User Creation', ['id' => 45, 'created_by' => 'jdoe']);

DBlog Model and Table

Model and Table Names

To avoid collisions and naming conflicts with the DBlog Facade or other tables, the database table can be accessed using the following:

  • Model Name: DBlogModel
  • Table Name: dblogs

dblogs Table Columns

Column Type Default Value Nullable Comments
id int(10) unsigned NO
level_id int(11) NO The RFC 5424 log level id
level_description varchar(255) NO The RFC 5424 log level description
message text NO
context text YES
created_at timestamp CURRENT_TIMESTAMP NO

Querying the Model

First, include the DBlogModel with the namespace:

use Supersixtwo\Dblog\DBlogModel;

Then via Query Builder:

$logs = DB::table('dblogs')->get();

or via Eloquent:

$logs = DBlogModel::all();

Change log

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email appsupport@supersixtwo.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Acknowledgements

This package is heavily inspired by the Monolog Logging Library.