Loggers
, (*1)
, (*2)
This repository contains a set of loggers implementing the PSR-3 logger interface.
Pull-requests and feature requests welcome., (*3)
Php7 and Php8
v2.x tags requires php 7+
v3.x tags requires php 8+
v4.x tags requires php 8.1+, (*4)
Only latest (currently php8.1+) is maintained., (*5)
Implemented loggers
All loggers are able to set which logging levels they should actually log on via the setLogLevel
method., (*6)
StdLogger
Logs output to stdout and stderr.
It's possible to change the format of the output and of the timestamp via the setFormat
and setTimeFormat
methods
in the instance class., (*7)
FileLogger
The FileLogger is probably the most useful logger. All it does is to print the output to a file of choice
(defaults to /tmp/log.txt
).
It's (as with StdLogger
) possible to change the format of the output and of the timestamp., (*8)
JsonLogger
The JsonLogger is a StdLogger which logs a json object instead of the standard
formatted string.
The json object looks as the following:, (*9)
{ "severity": "error", "message": "Formatted message.", "context": { }, "time": "1977-04-22T06:00:00Z", "ts": 230533200 }
JsonFileLogger
The JsonFileLogger is a FileLogger which logs a json object instead of
the standard formatted string.
Each log entry will be a new object, the following format is used:, (*10)
{ "severity": "error", "message": "Formatted message.", "context": { }, "time": "1977-04-22T06:00:00Z", "ts": 230533200 }
PDOLogger
Logs output to a PDO connection of choice. The table that it expects to add data to should look like the following:, (*11)
level - varchar(255)
message - text
time - datetime
Convenience method:, (*12)
CREATE TABLE IF NOT EXISTS log_messages (`level` int, `message` TEXT, `time` TIME )
SysLogLogger
The SysLogLogger sends your logs to a local syslog server.
As of right now, it is not able to use a remote server, but should later on..., (*13)
Internally it uses the php syslog
and openlog
methods. Check the constructor docs for default values., (*14)
MultiLogger
The MultiLogger was created to make it possible to log with multiple loggers in a single logger.
This due to the fact that you often wish to bind the logger to the LoggerInterface for dependency injection
something that will not allow you to bind multiple loggers!
You can add and remove loggers via addLogger(LoggerInterface $logger, string $name = null)
and removeLogger(LoggerInterface|string $logger)
, (*15)
CallbackLogger
The CallbackLogger is basically just a callback which gets invoked on log.
The callback is passed the following arguments:, (*16)
string: loglevel
string: message (message with context placeholders replaced)
string: text (message without context placeholders replaced)
array: context
CompactJsonLogger
Logger using (Compact Log Event Format JSON)[https://clef-json.org/] output to streams., (*17)
Output format:, (*18)
{"@t":"DateTime as ISO8601 String","@l":"(int)level","@m":"Formatted message","@mt":"Message template","@r": {"context-key": "context-value"}}
CompactJsonFileLogger
Logger using (Compact Log Event Format JSON)[https://clef-json.org/] output to file., (*19)
{"@t":"DateTime as ISO8601 String","@l":"(int)level","@m":"Formatted message","@mt":"Message template","@r": {"context-key": "context-value"}}
License, (*20)
MIT License
Copyright (c) 2020 Jitesoft
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.