Skip to content

0xRaffSarr/php-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PhpLogger

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' => [
        ...
    ]
]);

About

A simple PHP logger

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages