Last Updated | | Ratings | | Unique User Downloads | | Download Rankings |
2024-03-30 (6 days ago) | | Not enough user ratings | | Total: 36 This week: 36 | | All time: 10,919 This week: 2 |
|
Description | | Author |
This package can log messages to storage implemented by streams.
It provides a class that can be taken as a parameter, a stream object that will handle the storage of the log message.
The log class uses a log result class to format the log message before sending the formatted log message to the stream object.
The package provides several stream classes that can store log messages in regular files:
1. Synchronously waiting for the messages to be stored in the files
2. Asynchronously without waiting for the messages to be stored in the files Innovation Award
March 2024
Nominee
Vote |
Logging application messages is helpful to debug issues that those applications may have.
Developers may check the application logs to discover details that may be incorrect and causing issues that must be fixed as soon as possible.
This package can generate log messages in two ways. One way is synchronous. That is the slower way because the applications need to wait for the messages to be stored in files to carry on with the execution of the application code.
The other way is asynchronous. This way, applications can send messages to log files and continue with the execution of the application code without waiting for the messages to be stored in the files.
The asynchronous way of storing log messages is faster.
Manuel Lemos |
| |
|
|
Innovation award
Nominee: 10x
Winner: 3x |
|
Example
<?php
declare (strict_types=1);
use SimpleLogger\Logger;
use SimpleLogger\streams\{CollectionStream, FileStream, StdoutStream};
require __DIR__ . '/vendor/autoload.php';
$logger = new Logger(stream: new CollectionStream([
new StdoutStream(),
FileStream::async(__DIR__ . '/log.log'),
]));
$logger->info('This is an info message', ['exception' => new Exception('This is an exception')]);
$logger->warning('This is a warning message');
$logger->debug('This is a debug message with {msg}', ['msg' => 'parameters']);
|
Details
Simple psr logger
Installation
composer require mateodioev/simple-logger
Usage
use SimpleLogger\Logger;
use SimpleLogger\streams\{CollectionStream, FileStream, StdoutStream};
$logger = new Logger(stream: new CollectionStream([
new StdoutStream(),
FileStream::async(__DIR__ . '/log.log'),
]));
$logger->debug('The debug message');
Creating a new stream
A stream is a class that implements the SimpleLogger\streams\LogStream
interface. You can create your own stream by implementing the write
method.
use SimpleLogger\streams\LogStream;
class MyStream implements LogStream
{
public function write(LogResult $message): void
{
// Write the message
}
}
|
Applications that use this package |
|
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.