PHP Classes

File: readme.md

Recommend this page to a friend!
  Classes of Mateo   Simple PHP Logger   readme.md   Download  
File: readme.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: Simple PHP Logger
Log messages to storage implemented by streams
Author: By
Last change:
Date: 2 months ago
Size: 736 bytes
 

Contents

Class file image Download

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
    }
}