There is no license information available for the latest version (v0.2.2) of this package.

v0.2.2 2017-05-09 07:22 UTC

This package is not auto-updated.

Last update: 2020-03-20 18:20:20 UTC


README

composer require componentsv/dblog

Add into service provider array in ./config/app.php

'providers' => [
        // Component
        App\Components\DBLog\Providers\DBLogServiceProvider::class,

    ],

Optional : Publish config (Onsigbaar framework only)

php artisan component:publish-config DBLog

Fire events basic

Emergency

\Event::fire('event.emergency', [['message' => $message]]);

Alert

\Event::fire('event.alert', [['message' => $message]]);

Critical

\Event::fire('event.critical', [['message' => $message]]);

Error

\Event::fire('event.error', [['message' => $param['e']->getMessage()]]); // use try - catch to get error message

Warning

\Event::fire('event.warning', [['message' => $message]]);

Notice

\Event::fire('event.notice', [['message' => $message]]);

Info

\Event::fire('event.info', [['message' => $message]]);

Debug

\Event::fire('event.debug', [['message' => $message]]);

Fire events using default config example

Event should be wrapped in an configuration variable array, example of firing events using default package config.

Emergency

if ((config('dblog.logActivity')) && (config('dblog.emergency'))) {
    \Event::fire('event.emergency', [['message' => $message]]);
}

Alert

if ((config('dblog.logActivity')) && (config('dblog.alert'))) {
    \Event::fire('event.alert', [['message' => $message]]);
}

Critical

if ((config('dblog.logActivity')) && (config('dblog.critical'))) {
    \Event::fire('event.critical', [['message' => $message]]);
}

Error

if ((config('dblog.logActivity')) && (config('dblog.error'))) {
    \Event::fire('event.error', [['message' => $param['e']->getMessage()]]);
}

Warning

if ((config('dblog.logActivity')) && (config('dblog.warning'))) {
    \Event::fire('event.warning', [['message' => $message]]);
}

Notice

if ((config('dblog.logActivity')) && (config('dblog.notice'))) {
    \Event::fire('event.notice', [['message' => $message]]);
}

Info

if ((config('dblog.logActivity')) && (config('dblog.info'))) {
    \Event::fire('event.info', [['message' => $message]]);
}

Debug

if ((config('dblog.logActivity')) && (config('dblog.debug'))) {
    if (isset($param['construct'])) {
        $query      = $construct->toSql();
        $queryCount = $construct->count();

        \Event::fire('event.debug', [
            ['message' => 'Success get data from ' . $table . ' table, count records "' . $queryCount . '", with query : "' . $query . '"']
        ]);
    } else {
        \Event::fire('event.debug', [['message' => $message]]);
    }
}

Fire events using wrapper

Example in model class

use App\Components\DBLog\Traits\DBLog;

class BaseModel extends Model
{
    use DBLog;

    protected $fillable = [];
}

Event wrapper

# Emergency
$this->fireLog('emergencyOrError', $message, ['somethingElse' => $something]);

# Alert
$this->fireLog('alertOrError', $message, []);

# Critical
$this->fireLog('criticalOrError', $message);

# Error
$this->fireLog('error', $e->getMessage());

# Warning
$this->fireLog('warningOrError', $message);

# Notice
$this->fireLog('noticeOrError', $message);

# Info
$this->fireLog('infoOrError', $message);

# Debug
$this->fireLog('debugOrError', $message);