2017 © Pedro Peláez
 

library dblog

image

componentsv/dblog

  • Sunday, May 21, 2017
  • by b7d6f001
  • Repository
  • 1 Watchers
  • 0 Stars
  • 54 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

Install

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., (*1)

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, (*2)

use App\Components\DBLog\Traits\DBLog;

class BaseModel extends Model
{
    use DBLog;

    protected $fillable = [];
}

Event wrapper, (*3)

# 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);

The Versions