xraffsarr/php-logger

A simple PHP logger

2.0.0 2022-02-19 18:06 UTC

This package is auto-updated.

Last update: 2024-04-26 05:46:32 UTC


README

GitHub release GitHub license GitHub top language Packagist PHP Version Support GitHub issues Packagist Downloads GitHub code size in bytes

A php logger based on psr/log interface.

Installation

The package can be installed via Composer:

composer require xraffsarr/php-logger

Configuration

FOr usage via Facade pattern within the project, you only need to indicate the path to save the log

use PhpLogger\Facade\Log;

Log::setLogPath('[pathToSave]');

Replacing pathToSave with the desired path.

You can configure the type of log and the method to. If you want the logs to be saved in JSON format, you can set the JSON writer with.

use PhpLogger\Facade\Log;
use PhpLogger\LoggerType;

Log::setLogType(LoggerType::JSON_WRITER);

In that case the resulting file log.json, will contain an array of JSON objects in the format:

{
    "date_time": "19\/02\/2022 14:47:50",
    "level": "emergency",
    "message": "Test debug logger Facade",
    "context": {
        "user": {
            "name": "Mario",
            "surname": "Rossi"
        },
        "data": [
            "a",
            "b",
            {
                "t": "a",
                "a": "b"
            }
        ]
    }
}

Usage

The Logger can be used via Facade or instantiating a logger with its own configurations.

Via Facade

You can use the logger via Facade, simply by invoking the desired methods related to the type of log.

use PhpLogger\Facade\Log;

Log::debug('Debug log', [
    'data' => [
        ...
    ]
]);