axel-kummer/logbook-php

PSR compatible logger to send logs from php applications to the logbook server and client.

v0.2.1 2020-04-28 14:18 UTC

This package is auto-updated.

Last update: 2024-02-28 23:09:07 UTC


README

This package provides a PSR compatible Logger to send logs to the logbook server and client, https://github.com/alexgunkel/logbook. The Logger provides the logger itself and some Adapter to send the logs in several ways.

Installation

You can install the php component of logbook via git or composer. For both you need composer to get the dependencies installed which are necessary.

From github

    ## Cloning git repo
    git clone https://github.com/axel-kummer/logbook-php.git /path/to/checkout
    ## cd in to path
    cd /path/to/checkout
    ## Install dependencies
    composer install --no-dev

From pakageist

    composer require axel-kummer/logbook-php

Usage

Basic usage.

First you have to setup the request instance which is used to send the logs.

//Make a request instance
$request = \AxelKummer\LogBook\LoggerUtility::setupRequest(
    \AxelKummer\LogBook\Request\HttpRequest::class,
    'MyApplication',
    'myhost'
    8080
);

You can also add a unique request identifier for all logs within a request.

$request->setRequestId(\AxelKummer\LogBook\LoggerUtility::getRequestId('Prefix))

If it's done you can simply create logger which will have injected the request object.

//get a logger with injected request instance
$logger = \AxelKummer\LogBook\LoggerUtility::getLogger('MyLogger');

//Use the logger to send messages to the logbook server
$logger->info('My info mesage');

You can implement and use your own request class. Your Class have to extend \AxelKummer\LogBook\Request\AbstractRequest and implements the methods sendLog and getUrl