elephox / logging
Elephox Logging library.
v0.7.0
2022-07-03 13:19 UTC
Requires
- php: ^8.1 <8.3
- jetbrains/phpstorm-attributes: ^1.0
- psr/log: ^3.0
- ricardoboss/php-console-logger: ^2.1
Provides
- dev-develop
- 0.9.0.x-dev
- 0.8.0.x-dev
- v0.7.0
- v0.6.0
- v0.5.0
- v0.4.3
- 0.4.0
- 0.4.0-alpha5
- 0.4.0-alpha4
- 0.4.0-alpha3
- 0.4.0-alpha2
- 0.4.0-alpha1
- 0.3.27
- v0.3.25
- v0.3.24
- v0.3.23
- v0.3.22
- v0.3.21
- v0.3.20
- v0.3.18
- v0.3.17
- v0.3.16
- v0.3.15
- v0.3.14
- v0.3.13
- v0.3.12
- v0.3.11
- v0.3.10
- v0.3.9
- v0.3.8
- v0.3.7
- v0.3.6
- v0.3.5
- v0.3.4
- dev-release/0.9
- dev-release/0.8
- dev-release/0.6
- dev-release/0.7
- dev-16-psr-20-clock
- dev-18-make-servicecollection-more-extensible
- dev-25-improvements-to-logging
- dev-3-add-nunomadurotermwind-console-sink
- dev-release/0.5
- dev-release/0.4
- dev-release/0.3
This package is auto-updated.
Last update: 2024-12-18 05:14:49 UTC
README
This module is used by Elephox to log information to one or more destinations (sinks).
Example
use Elephox\Logging\StandardSink; use Elephox\Logging\SingleSinkLogger; use Elephox\Logging\Contract\Sink; use Elephox\Logging\LogLevel; // create a logger with only one sink, a sink which logs to STDOUT and STDERR $logger = new SingleSinkLogger(new StandardSink()); $logger->info('Hello world!'); // Prints to STDOUT: Hello world! $logger->warning('This is a warning!'); // Prints to STDERR: This is a warning! // You can also log meta data: $logger->info('Hello world!', ['foo' => 'bar']); // You can implement your own sink: class MySink implements Sink { public function write(string $message, LogLevel $level, array $metaData): void { $this->myThirdPartyLoggingService->log($message, $level->value, $metaData); } } $mySinkLogger = new SingleSinkLogger(new MySink()); $mySinkLogger->alert("This is an alert!");
You can also wrap sinks in decorator sinks (classes implementing SinkProxy
):
use Elephox\Logging\SimpleFormatColorSink; use Elephox\Logging\EnhancedMessageSink; $standardSink = new StandardSink(); $formattedSink = new SimpleFormatColorSink($standardSink); $formattedSink->write(LogLevel::INFO, '<blue>Hello</blue> <green>world</green>!', []); // Prints a blue "Hello" and a green "world" to STDOUT $enhancedSink = new EnhancedMessageSink($formattedSink); $enhancedSink->write(LogLevel::INFO, '<blue>Hello</blue> <green>world</green>!', []); // Prints a blue "Hello" and a green "world" to STDOUT, with a timestamp and a log level