makopov/simple-log

A simple log wrapper around syslog, loosely based on PSR-3

v1.0.8 2016-03-05 00:33 UTC

This package is not auto-updated.

Last update: 2024-04-13 16:29:17 UTC


README

A simple log wrapper around syslog

68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6d616b6f706f762f73696d706c652d6c6f672f6261646765732f6770612e737667

Simple Log is a singleton class that makes logging to syslog very easy.

Get an object instance:

$oLogger = SLog::getInstance();

Configure application name (optional). If not set syslog will show 'php' as the application name. Good to do upon a bootstrap or init of applications.

$oLogger->setApplicationName('MyApp');

Now log! Using any of the 8 log level

$oLogger->emergency('some message');
$oLogger->alert('some message');
$oLogger->critical('some message');
$oLogger->error('some message');
$oLogger->warning('some message');
$oLogger->notice('some message');
$oLogger->info('some message');
$oLogger->debug('some message');

Log messages will appear in syslog (/var/log/messages). By default Simple Log will include the file name and line number of where the log was made from.

Example:

Foo.php

function foo() {
    $oLogger->warning('something happened');
}

Will show up in syslog like so:

Feb 26 22:11:47 localhost MyApp: Foo.php:2 - something happened

Thats it! Please submit bugs as you see them. I will add tests in the near future.