nolikein / logger
Using a logger content. Respecting the PHP PSR-6
1.0.1
2020-11-03 17:28 UTC
Requires
- php: ^7.3
- psr/http-message: ^1.0.1
- psr/log: ^1.1.3
Requires (Dev)
- nolikein/http-message: ^1.0.0
- phpunit/phpunit: ^9
This package is auto-updated.
Last update: 2024-03-29 04:26:07 UTC
README
Description
Do you want to log any content in a file or... more widely, by a stream ! This librairy allows you to do that. Want database logs, system logs, connexion logs... anything you want is possible with a bit of knowledge.
This librairy use the PHP PSR-3.
Installation
This is a php package downloadable from packagist, which is used composer.
Composer from bash
composer require nolikein/logger ^1.0.0
Composer from Docker:
docker run --rm --interactive --tty -v $PWD:/app composer require nolikein/logger ^1.0.0
Usage
Level 1 - Bases
use Nolikein\Stream\StreamFactory;
use Nolikein\Logger\StreamLogger;
// Open a file with the Stream Manager librairy (a file is a stream opened)
$fileStream = (new StreamFactory())->createStreamFromFile(__DIR__.'/logfile_name.log', 'r+');
// Creating a new logger instance
$logger = new StreamLogger($fileStream);
// Write a log
$logger->log($level='notice', $message='My log message');
// There are as many methods as there are log levels.
$logger->notice('I want to notice you of something');
All log level are described in the Psr\Log\LogLevel class.
Level 2 - Replacing text
// Replace logged text by using "context"
$logger->notice($message='It is {something} time !', $context=['something', 'muffin']);
Will output:
It is muffin time !
Sources
Contributing
You can contribute as you want. I have no rules.
Licence
The project is under lincence MIT.