Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
/ php-logger Public archive

System logs in php, with options to register in syslog or in a custom file. No dependency.

License

Notifications You must be signed in to change notification settings

ddniel16/php-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Php-Logger

System logs in php, with options to register in syslog or in a custom file, with different priorities and in the case of logs to the console, with distinctive colors for each type.

Install

Using composer:

composer require ddniel16/php-logger

Methods

available methods:

$logs->alert($message, $context);
$logs->critical($message, $context);
$logs->custom($message, $context);
$logs->debug($message, $context);
$logs->emergency($message, $context);
$logs->error($message, $context);
$logs->info($message, $context);
$logs->log(0, $message, $context);
$logs->notice($message, $context);
$logs->success($message, $context);
$logs->warning($message, $context);

Examples

<?php

$logs = new \PhpLogger\PhpLogger();
$logs->setOutput(true);

$message = 'Hello Mr. {name} {lastname} Matrix awaits you!';
$context = array('name' => 'Jack', 'lastname' => 'Sparrow');

$logs->debug($message, $context);

Syslog

Write to syslog with the severity of the method or be instructed.

<?php

$syslog = new \PhpLogger\Syslog('testting');

$logger = new \PhpLogger\PhpLogger();
$logger->setSyslog($syslog);

$logger->debug('--> syslog <--');

File

Written to the file with a message depending on the severity

<?php

$optionsFile = array(
    'logDir' => __DIR__ . '/logs',
    'name' => 'php-logger',
    'ext' => 'log',
    'dateFormat' => 'd-m-Y H:i:s P',
    'maxLogs' => 3,
    'maxSize' => 700
);

$file = new \PhpLogger\File($logFile);

$logger = new \PhpLogger\PhpLogger();
$logger->setFile($file);

$logger->debug('debug message');

Custom

class CustomLogger implements PhpLogger\CustomInterface
{

    public function writeLog(
        $message,
        $priority = LOG_DEBUG,
        $priorityMsg = '[debug]'
    )
    {

        if ($priority === LOG_CRIT) {
            mail('[email protected]', $priorityMsg, $message);
        }

    }

}

$logs = new \PhpLogger\PhpLogger();
$logs->setCustom(new CustomLogger());
$logs->setOutput(false);

$message = 'Hola Sr. {name} {lastname}';
$context = array('name' => 'Jack', 'lastname' => 'Sparrow');

$logs->critical($message, $context);

About

System logs in php, with options to register in syslog or in a custom file. No dependency.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages