Download the PHP package corpus/loggers without Composer
On this page you can find all versions of the php package corpus/loggers. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package loggers
(PSR-3) Loggers and Logging Utilities
Utilities for and Loggers for PSR-3: Logger Interface.
- LogLevelFilter - LogLevelFilter is a PSR Logger that filters logs based on the log level. It can be used to filter out log messages that are not needed for a specific use case.
- LogLevelLoggerMux - LogLevelLoggerMux is a PSR Logger that multiplexes logs to different loggers based on the log level.
- LoggerVerbosityFilter - LoggerVerbosityFilter mutes log messages based on a given integer verbosity level.
- LoggerWithContext - LoggerWithContext is a logger that adds a given context to all log messages before delegating to another logger.
- MemoryLogger - MemoryLogger is a PSR Logger that stores all logs in local memory.
- MultiLogger - MultiLogger is a PSR Logger that delegates logs to multiple other loggers.
- StreamResourceLogger - StreamResourceLogger is a PSR Logger that writes to a stream resource.
Requirements
- psr/log: ^1 || ^2 || ^3
- php: ^7.4 || ^8.0
Installing
Install the latest version with:
Example
This example demonstrates how the loggers may be chained together to create complex interactions
Documentation
Class: \Corpus\Loggers\Interfaces\LoggerWithContextInterface
Method: LoggerWithContextInterface->withContext
Returns a new instance with the given context
replacing the existing context.
Method: LoggerWithContextInterface->withAddedContext
Returns a new instance with the given context
added to the existing context.
Class: \Corpus\Loggers\Interfaces\MultiLoggerInterface
Method: MultiLoggerInterface->withAdditionalLoggers
withAdditionalLoggers returns a new instance with the given loggers
added to the list of loggers to delegate to.
Class: \Corpus\Loggers\Interfaces\WithAdditionalLoggersInterface
Method: WithAdditionalLoggersInterface->withAdditionalLoggers
withAdditionalLoggers returns a new instance with the given loggers
added to the list of loggers to delegate to.
Class: \Corpus\Loggers\Interfaces\WithContextInterface
Method: WithContextInterface->withContext
Returns a new instance with the given context
replacing the existing context.
Method: WithContextInterface->withAddedContext
Returns a new instance with the given context
added to the existing context.
Class: \Corpus\Loggers\LoggerVerbosityFilter
LoggerVerbosityFilter mutes log messages based on a given integer verbosity level.
By default,
- level 0 logs no messages.
- level 1 logs emergency, alert, critical, and error messages.
- level 2 logs emergency, alert, critical, error, warning, and notice messages.
- level 3 logs emergency, alert, critical, error, warning, notice, and info messages.
- level 4 or greater logs emergency, alert, critical, error, warning, notice, info, and debug messages.
The levels can be changed by passing a callback redefine the verbosity level for each log level.
The verbosity level can be changed by calling withVerbosity()
Method: LoggerVerbosityFilter->__construct
Parameters:
- callable | null
$verbosityFromLevelCallback
- A callback that takes a Psr\Log\LogLevel log level string and returns an integer verbosity level. If null, the default callback will be used.
Method: LoggerVerbosityFilter->withVerbosity
Returns a new instance with the specified verbosity level.
Method: LoggerVerbosityFilter->withVerbosityFromLevelCallback
Returns a new instance with the specified verbosity level callback.
Class: \Corpus\Loggers\LoggerWithContext
LoggerWithContext is a logger that adds a given context to all log messages before delegating to another logger.
This is useful for adding context to all log messages, such as the current request ID, IP address or the current user ID.
Method: LoggerWithContext->__construct
Create a new LoggerWithContext instance with the given logger and context.
The given context will be added to all log messages.
Parameters:
- \Psr\Log\LoggerInterface
$logger
- The logger to delegate to. - array
$context
- The context to add to all log messages.
Method: LoggerWithContext->withContext
Returns a new instance with the given context
replacing the existing context.
Method: LoggerWithContext->withAddedContext
Returns a new instance with the given context
added to the existing context.
Class: \Corpus\Loggers\LogLevelFilter
LogLevelFilter is a PSR Logger that filters logs based on the log level.
It can be used to filter out log messages that are not needed for a specific use case.
For example, you may want to log all messages at the DEBUG level to a file, but only log messages at the ERROR level or higher to the console.
This logger can be used to filter out the DEBUG messages from the console logger.
This logger accepts a list of log levels to filter, and a boolean indicating whether to exclude or include the given log levels.
Method: LogLevelFilter->__construct
Parameters:
- string[]
$levels
- The log levels to filter. - bool
$exclude
- Whether to exclude the given levels, or include them.
Class: \Corpus\Loggers\LogLevelLoggerMux
LogLevelLoggerMux is a PSR Logger that multiplexes logs to different loggers based on the log level.
Method: LogLevelLoggerMux->__construct
Parameters:
- \Psr\Log\LoggerInterface | null
$defaultLogger
- The default logger to use for levels where no other logger is specified. If null, a Psr\Log\NullLogger will be used.
Method: LogLevelLoggerMux->withEmergencyLogger
Returns a new instance with the specified logger handling the Emergency log level.
Method: LogLevelLoggerMux->withAlertLogger
Returns a new instance with the specified logger handling the Alert log level.
Method: LogLevelLoggerMux->withCriticalLogger
Returns a new instance with the specified logger handling the Critical log level.
Method: LogLevelLoggerMux->withErrorLogger
Returns a new instance with the specified logger handling the Error log level.
Method: LogLevelLoggerMux->withWarningLogger
Returns a new instance with the specified logger handling the Warning log level.
Method: LogLevelLoggerMux->withNoticeLogger
Returns a new instance with the specified logger handling the Notice log level.
Method: LogLevelLoggerMux->withInfoLogger
Returns a new instance with the specified logger handling the Info log level.
Method: LogLevelLoggerMux->withDebugLogger
Returns a new instance with the specified logger handling the Debug log level.
Class: \Corpus\Loggers\MemoryLogger
MemoryLogger is a PSR Logger that stores all logs in local memory.
This is primarily useful for testing purposes.
Method: MemoryLogger->getLogs
getLogs returns all logs that have been logged to this logger.
The returned array is a list of log records, each of which is an array keyed by
- MemoryLogger::KEY_LEVEL : The log level
- MemoryLogger::KEY_MESSAGE : The log message
- MemoryLogger::KEY_CONTEXT : The log context
Returns:
- array[]
Method: MemoryLogger->clearLogs
clearLogs clears all logs that have been logged to this logger.
Class: \Corpus\Loggers\MultiLogger
MultiLogger is a PSR Logger that delegates logs to multiple other loggers.
Method: MultiLogger->__construct
Create a new MultiLogger instance with the given loggers to delegate to.
Method: MultiLogger->withAdditionalLoggers
withAdditionalLoggers returns a new instance with the given loggers
added to the list of loggers to delegate to.
Class: \Corpus\Loggers\StreamResourceLogger
StreamResourceLogger is a PSR Logger that writes to a stream resource.
This is particularly useful for writing to STDERR or STDOUT, or to a file.
Method: StreamResourceLogger->__construct
Parameters:
- resource
$resource
- Writable stream resource
Throws: \Corpus\Loggers\Exceptions\LoggerArgumentException
- If the given resource is not a stream
Throws: \Corpus\Loggers\Exceptions\LoggerInitException
- If the given resource is not writable