LogVice\PHPLogger sends your logs to LogVice.com service or to your own LogVice platform installation. This library implements the PSR-3 standards.
Install the latest version
composer require logvice/phplogger
<?php
use LogVice\PHPLogger\Logger;
use LogVice\PHPLogger\Config;
use LogVice\PHPLogger\Output\TCPOutput;
use LogVice\PHPLogger\Output\UDPOutput;
// create a config instance
$config = new Config();
$config->setAppKey('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
$config->setEnvironment('dev');
$config->setChannel('php');
$config->activateBacktrace();
$config->setOutputHandlers([
new TCPOutput('127.0.0.1', '8080'),
new UDPOutput('127.0.0.1', '514'),
]);
$config->setLogLevel(Logger::DEBUG);
// create a log instance
$log = new Logger($config);
// add records to the log
$log->debug('foo');
$log->info('bar');
$log->notice('foo');
$log->warning('bar');
$log->error('foo');
$log->critical('bar');
$log->alert('foo');
$log->emergency('bar');
$log->log(Logger::ERROR, 'foo');
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
// create a config instance
$config = new LogVice\PHPLogger\Config();
$config->setAppKey('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
$config->setEnvironment('dev');
$config->setChannel('php');
$config->setOutputHandlers([
new LogVice\PHPLogger\Output\TCPOutput('127.0.0.1', '8080'),
new LogVice\PHPLogger\Output\UDPOutput('127.0.0.1', '514'),
new LogVice\PHPLogger\Output\FileOutput('path/to/logs', 'file-name', true)
]);
$config->setLogLevel(Logger::ERROR);
// create a log instance
$logger = new LogVice\PHPLogger\Logger($config);
$logger->handleError($errno, $errstr, $errfile, $errline);
});
set_exception_handler(function ($exception) {
// create a config instance
$config = new LogVice\PHPLogger\Config();
$config->setAppKey('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
$config->setEnvironment('dev');
$config->setChannel('php');
$config->setOutputHandlers([
new LogVice\PHPLogger\Output\TCPOutput('127.0.0.1', '8080'),
new LogVice\PHPLogger\Output\UDPOutput('127.0.0.1', '514'),
new LogVice\PHPLogger\Output\FileOutput('path/to/logs', 'file-name', true)
]);
$config->setLogLevel(Logger::ERROR);
// create a log instance
$logger = new LogVice\PHPLogger\Logger($config);
$logger->handleException($exception);
});
register_shutdown_function(function () {
// create a config instance
$config = new LogVice\PHPLogger\Config();
$config->setAppKey('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
$config->setEnvironment('dev');
$config->setChannel('php');
$config->setOutputHandlers([
new LogVice\PHPLogger\Output\TCPOutput('127.0.0.1', '8080'),
new LogVice\PHPLogger\Output\UDPOutput('127.0.0.1', '514'),
new LogVice\PHPLogger\Output\FileOutput('path/to/logs', 'file-name', true)
]);
$config->setLogLevel(Logger::ERROR);
// create a log instance
$logger = new LogVice\PHPLogger\Logger($config);
$logger->handleShutdownError();
});
- PHPLogger works with PHP 5.4 or above..
Bugs and feature request use GitHub
Alban Kora - ankdeveloper@gmail.com - http://twitter.com/albankora
PHPLogger is licensed under the MIT License - see the LICENSE
file for details