logvice/phplogger

Sends your logs to LogVice.com web services or your personal LogVice installation or to a local file.

0.1.4 2017-01-12 22:19 UTC

This package is not auto-updated.

Last update: 2024-04-13 16:07:24 UTC


README

Build Status Coverage Status Total Downloads Software License

LogVice\PHPLogger sends your logs to LogVice.com service or to your own LogVice platform installation. This library implements the PSR-3 standards.

Installation

Install the latest version

composer require logvice/phplogger

Basic Usage

<?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');

Register Error, Exception and Shutdown handlers

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();
});

About

Requirements

  • PHPLogger works with PHP 5.4 or above..

Submitting bugs and feature requests

Bugs and feature request use GitHub

Author

Alban Kora - ankdeveloper@gmail.com - http://twitter.com/albankora

License

PHPLogger is licensed under the MIT License - see the LICENSE file for details