Get support for yiisoft/log
If you're new to LTH, please see our FAQ for more information on what it is we do.
Support Options
Unfortunately, there are currently no active helpers for this repository on the platform. Until they become available, we reccomend the following actions:
View Open IssuesTake a look to see if anyone else has experienced the same issue as you and if they managed to solve it.
Open an IssueMake sure to read any relevant guidelines for opening issues on this repo before posting a new issue.
Sponsor directlyCheck out the page and see if there are any options to sponsor this project or it's developers directly.
yiisoft/log
This package provides PSR-3 compatible logging library. It is used in Yii Framework but is usable separately.
The logger sends passes messages to multiple targets. Each target may filter messages by their severity levels and categories and then export them to some medium such as file, email or syslog.
Requirements
- PHP 8.0 or higher.
Installation
The package could be installed with Composer:
composer require yiisoft/log
General usage
Creating a logger:
/**
* List of class instances that extend the \Yiisoft\Log\Target abstract class.
*
* @var \Yiisoft\Log\Target[] $targets
*/
$logger = new \Yiisoft\Log\Logger($targets);
Writing logs:
$logger->emergency('Emergency message', ['key' => 'value']);
$logger->alert('Alert message', ['key' => 'value']);
$logger->critical('Critical message', ['key' => 'value']);
$logger->warning('Warning message', ['key' => 'value']);
$logger->notice('Notice message', ['key' => 'value']);
$logger->info('Info message', ['key' => 'value']);
$logger->debug('Debug message', ['key' => 'value']);
Message Flushing and Exporting
Log messages are collected and stored in memory. To limit memory consumption, the logger will flush
the recorded messages to the log targets each time a certain number of log messages accumulate.
You can customize this number by calling the \Yiisoft\Log\Logger::setFlushInterval()
method:
$logger->setFlushInterval(100); // default is 1000
Each log target also collects and stores messages in memory.
Message exporting in a target follows the same principle as in the logger.
To change the number of stored messages, call the \Yiisoft\Log\Target::setExportInterval()
method:
$target->setExportInterval(100); // default is 1000
Note: All message flushing and exporting also occurs when the application ends.
Logging targets
This package contains two targets:
-
Yiisoft\Log\PsrTarget
- passes log messages to another PSR-3 compatible logger. -
Yiisoft\Log\StreamTarget
- writes log messages to the specified output stream.
Extra logging targets are implemented as separate packages:
Context providers
Context providers are used to provide additional context data for log messages. You can define your own context provider
in Logger
constructor:
$logger = new \Yiisoft\Log\Logger(contextProvider: $myContextProvider);
By default, the logger uses built-in Yiisoft\Log\ContextProvider\ContextProvider
that added following data to context:
-
time
— current Unix timestamp with microseconds (float value); -
trace
— array of call stack information; -
memory
— memory usage in bytes. -
category
— category of the log message (always "application").
Yiisoft\Log\ContextProvider\ContextProvider
constructor parameters:
-
traceLevel
— how much call stack information (file name and line number) should be logged for each log message. If it is greater than 0, at most that number of call stacks will be logged. Note that only application call stacks are counted. -
excludedTracePaths
— array of paths to exclude from tracing when tracing is enabled withtraceLevel
.
Example of custom parameters' usage:
$logger = new \Yiisoft\Log\Logger(
contextProvider: new Yiisoft\Log\ContextProvider\ContextProvider(
traceLevel: 3,
excludedTracePaths: [
'/vendor/yiisoft/di',
],
)
);
Documentation
If you need help or have a question, the Yii Forum is a good place for that. You may also check out other Yii Community Resources.
License
The Yii Logging Library is free software. It is released under the terms of the BSD License.
Please see LICENSE
for more information.
Maintained by Yii Software.
Support the project
Follow updates
Our Mission
We want to make open source more sustainable. The entire platform was born from this and everything we do is in aid of this.
From the Blog
Interesting Articles
-
Generating income from open source
Jun 23 • 8 min read
-
2023 State of OSS
Apr 23 • 45 min read ★
-
A funding experiment...
Aug 19 • 10 min read
-
But You Said I could
Aug 19 • 2 min read
Thank you for checking out LiveTechHelper |
2025 © lth-dev incorporated
p-e622a1a2