Download the PHP package vrza/simplogger without Composer
On this page you can find all versions of the php package vrza/simplogger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vrza/simplogger
More information about vrza/simplogger
Files in vrza/simplogger
Package simplogger
Short Description Lightweight PHP logging library
License Apache-2.0
Homepage https://github.com/vrza/simplogger/
Informations about the package simplogger
= Simplogger: Simple PHP logging utility
== Overview
The goal of Simplogger is to provide a logging utility library for PHP that is lightweight, simple to use, and simple to integrate.
Simplogger can log to:
- stdout/stderr
- local syslogd (/dev/log)
- remote syslogd (UDP)
- file
Typical use case is a PHP microservice that uses syslogd for logging when deployed, but can just as easily use stdout/stderr (e.g. in the development environment).
[source,php]
use \VladimirVrzic\Simplogger\StdouterrLogger; use \VladimirVrzic\Simplogger\SyslogLogger;
$ident = basename($argv[0]); $opts = getopt('s', ['syslog']); $logger = array_key_exists('s', $opts) || array_key_exists('syslog', $opts) ? new SyslogLogger($ident, LOG_CONS, LOG_LOCAL1) : new StdoutLogger; $logger->notice('Hello world!');
== Setup
=== Installation
Assuming you have PHP Composer installed, and that the composer
executable is in your $PATH
:
[source,shell]
composer require vrza/simplogger
=== Log to local syslog
[source,php]
$ident = 'my-program-name'; $facility = LOG_LOCAL1; $options = LOG_CONS; $logger = new SyslogLogger($ident, $options, $facility);
SyslogLogger
logs using PHP's
http://php.net/manual/en/function.syslog.php[syslog()]
function. Parameters are the same as passed to
http://php.net/manual/en/function.openlog.php[openlog()]
.
=== Log to remote syslogd via UDP
[source,php]
$syslogHost = 192.0.2.22; $syslogPort = 514; $logger = new RemoteSysLogger($ident, $facility, $syslogHost, $syslogPort);
RemoteSysLogger
sends all messages to syslogd over UDP.
Default host is 127.0.0.1
, default port number is 514.
=== Log to stdout/stderr
[source,php]
$logger = new StdoutLogger;
StdoutLogger
writes all messages to stdout.
StderrLogger
writes all messages to stderr.
StdouterrLogger
writes WARNING and higher severity messages to stderr,
writes other messages to stdout.
These loggers can be optionally set up to include timestamp, ident and severity with each message:
[source,php]
$timestamp = TRUE; $severity = TRUE; $logger = new StdoutLogger($timestamp, $severity, $ident);
=== Log to file
[source,php]
$logFile = '/var/log/my.log'; $logger = new FileLogger($logFile);
FileLogger
writes all messages to a given file.
Like the stdout/stderr loggers, FileLogger
has an option to include
timestamp, ident and severity with each message.
[source,php]
$logger = new FileLogger($logFile, $timestamp, $severity, $ident);
== Usage
[source,php]
$logger->alert('A message with ALERT severity'); $logger->crit('A message with CRIT severity'); $logger->err('A message with ERR severity'); $logger->warning('A message with WARNING severity'); $logger->notice('A message with NOTICE severity'); $logger->info('A message with INFO severity'); $logger->debug('A messsage with DEBUG severity');
All versions of simplogger with dependencies
ext-sockets Version *