Download the PHP package firehed/simplelogger without Composer
On this page you can find all versions of the php package firehed/simplelogger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download firehed/simplelogger
More information about firehed/simplelogger
Files in firehed/simplelogger
Package simplelogger
Short Description Logger compatible with PSR-3. Supports writing to files, STDOUT, STDERR, and syslog. Also provides a chain logger which can write to multiple destinations.
License MIT
Homepage https://github.com/firehed/simpleLogger
Informations about the package simplelogger
SimpleLogger
SimpleLogger is a PHP library to write logs.
- Drivers: Syslog, stdout, stderr and text file
- Compatible with PSR-3 Standard Logger Interface
- Requirements: PHP >= 7.2 (older versions may work, but are not tested)
- Author: Frédéric Guillot, Eric Stern
- License: MIT
This is a fork from Frédéric Guillot's original SimpleLogger package, which has since been abandoned. I intend to actively maintain this as needed.
Usage
Installation
Syslog
Send log messages to Syslog:
Stdout
Stderr
Text file
Send log messages to a text file:
Multiple loggers
Send log messages to multiple loggers:
Minimum log level for loggers
In this example, only messages with the level >= "error" will be sent to the Syslog handler but everything is sent to the File handler:
The minimum log level is LogLevel::DEBUG
by default.
Formatting
Starting in 2.1.0, custom message formatting can be configured with the setFormat(string $format)
method.
The format provided MUST include %s
, which is where the actual interpolated message will be placed.
Formats MAY include {date}
and/or {level}
, which are placeholders for the timestamp and log level respectively.
The default format is [{date}] [{level}] %s
, which will result in a log message like this:
The date defaults to ATOM format, but can also be customized via setDateFormat(string $format)
using any format string that date()
accepts.
Note: at this time, the Syslog
logger does not use these formats.
Exception rendering
Starting in 2.4.0, the loggers in this library have the ability to automatically render exceptions when passed to $context
in the exception
index.
To avoid changing existing logging formats, this behavior must be explicitly adopted:
If configured AND $context['exception'] instanceof \Throwable
, then the exception will be cast to a string and appended to the end of the message.