phlib/logger

Additional Logging Classes

4.1.1 2023-10-16 16:03 UTC

This package is auto-updated.

Last update: 2024-10-31 00:18:37 UTC


README

Code Checks Codecov Latest Stable Version Total Downloads Licence

PHP PSR-3-compatible logger

Install

Via Composer

$ composer require phlib/logger

Usage

Example config for a logger pool

$loggerConfig = [
    'default' => [ // logger config identifier, used as facility/name in log messages
        // multiple logger entries becomes a collection logger
        [
            // logger type (stream, gelf...)
            'type'  => 'stream',
            // the level of log messages to include (optional)
            'level' => \Psr\Log\LogLevel::ERROR, 
             // logger specific parameters
            'path'  => '/var/log/my_app.log'
        ],
        [
            'type'  => 'gelf',                
            'level' => \Psr\Log\LogLevel::INFO,
             // logger specific parameters
            'host'  => '127.0.0.1',
            'port'  => 12201
        ]
    ],
    'application' => 'default', // alias to another logger config
    'api' => [
        'type' => 'gelf',
        'host' => '127.0.0.1',
        'port' => 12201 
    ]
];

Creation of logger pool

$loggerPool = new \Phlib\Logger\Pool(
    new \Phlib\Logger\Config($loggerConfig), 
    new \Phlib\Logger\Factory()
);

Get a logger instance

$applicationLogger = $loggerPool->getLogger('application');
// or
$applicationLogger = $loggerPool->application;

$applicationLogger->info('Logging is initialised');

License

This package is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see http://www.gnu.org/licenses/.