kod / logger
Psr 3 logger implementation
Installs: 30
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/kod/logger
Requires
- php: ^7.1
- psr/log: ~1.0.0
Requires (Dev)
- phpunit/phpunit: ~7.4.0
- squizlabs/php_codesniffer: ~3.3.0
This package is auto-updated.
Last update: 2025-12-15 13:29:18 UTC
README
Lightweight and easy customizable logger implementation of the PSR-3 standard.
Requirements
Logger works with PHP >=7.1.
Installation
Install the latest version with composer
$ composer require kod/logger
Usage
Basic usage. Use default logger settings to log a message into 'php://stderr' in json format. Perfect for docker environment and works out of the box.
<?php
use Kod\Logger;
$log = new Logger();
$log->debug('Debug message', [
'client_login' => 'login@domain.com',
]);
Note the context data (client_login field) is simply merged into the default data structure.
{
"message": "Debug message",
"level": "debug",
"level_code": 7,
"datetime": "2018-11-07T19:10:33.757+01:00",
"client_login": "login@domain.com"
}
Here is a little bit more advanced setup for logging into a file. In this example we extend a default log data structure with fields that must be appended to every log. Those fields, if not overridden with context data, will have a default value.
<?php
use Kod\Logger;
$log = new Logger([
'message' => [
// extend default log's data
'fields' => [
'client_name' => '',
'client_login' => '',
'request_uri' => $_SERVER['REQUEST_URI'],
'client_ip' => $_SERVER['REMOTE_ADDR'],
],
],
// distribution channels: places where logs must be written
'channels' => [
[
'handler' => [
'path' => '/var/tmp/debug.log'
],
],
],
]);
$log->debug('Debug message', [
'client_login' => 'login@domain.com',
]);
And here is our log message:
{
"message": "Debug message",
"level": "debug",
"level_code": 7,
"datetime": "2018-11-07T19:10:33.757+01:00",
"client_name": "",
"client_login": "login@domain.com",
"request_uri": "/",
"client_ip": "127.0.0.1"
}
Documentation
About
Submitting bugs and feature requests
Bugs and feature requests are tracked on GitHub
Author
Konstantin Deryabin - kderyabin@orange.fr
License
Logger is licensed under the MIT License - see the LICENSE file for details