supersixtwo / dblog
Lightweight Laravel package for writing custom logs and error messages to a database.
Requires
- php: >=5.3.0
- illuminate/support: ~5.1
Requires (Dev)
- phpunit/phpunit: 4.*
- scrutinizer/ocular: ~1.1
This package is not auto-updated.
Last update: 2024-11-13 11:39:00 UTC
README
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
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.