2017 © Pedro Peláez
 

library logdb

image

consigliere/logdb

  • Saturday, May 27, 2017
  • by b7d6f001
  • Repository
  • 1 Watchers
  • 0 Stars
  • 22 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

Log data into database for laravel

The logger provides the eight logging levels defined in RFC 5424: emergency, alert, critical, error, warning, notice, info and debug. Passing message into event and It will automatically detect request url, request method, client ip, browser, user os etc and save it into database. In event it failed it will simply log data into storage log., (*1)

Install

composer require consigliere/logdb

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

'providers' => [
        // ...
        App\Components\LogDB\Providers\LogDBServiceProvider::class,
        // ...
    ],

Migration

php artisan migrate

Publish config

php artisan vendor:publish --tag=config-logdb

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 array, example of firing events using default package config., (*2)

Emergency

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

Alert

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

Critical

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

Error

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

Warning

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

Notice

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

Info

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

Debug

if ((config('logdb.logActivity')) && (config('logdb.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, (*3)

use App\Components\LogDB\Traits\LogDB;

class BaseModel extends Model
{
    use LogDB;

    protected $fillable = [];
}

Event wrapper, (*4)

# 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

27/05 2017

dev-master

9999999-dev

  Sources   Download

The Requires

 

27/05 2017

dev-dev-master

dev-dev-master

  Sources   Download

The Requires

 

27/05 2017

v0.1.5

0.1.5.0

  Sources   Download

The Requires

 

26/05 2017

v0.1.4

0.1.4.0

  Sources   Download

The Requires

 

25/05 2017

v0.1.3

0.1.3.0

  Sources   Download

The Requires

 

24/05 2017

v0.1.2

0.1.2.0

  Sources   Download

The Requires

 

23/05 2017

v0.1.1

0.1.1.0

  Sources   Download

The Requires

 

22/05 2017

v0.1.0

0.1.0.0

  Sources   Download

The Requires