fyre / log
A logging library.
Installs: 240
Dependents: 4
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
pkg:composer/fyre/log
Requires
- fyre/config: ^5.0
- fyre/container: ^2.0
- fyre/filesystem: ^3.0
- fyre/macro: ^2.0
- fyre/path: ^3.0
- psr/log: ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.59
- fyre/php-cs-fixer-config: ^1.0
- phpunit/phpunit: ^12
- dev-main
- v7.0.1
- v7.0
- v6.1.7
- v6.1.6
- v6.1.5
- v6.1.4
- v6.1.3
- v6.1.2
- v6.1.1
- v6.1.0
- v6.0
- v5.2.0
- v5.1.2
- v5.1.1
- v5.1.0
- v5.0.4
- v5.0.3
- v5.0.2
- v5.0.1
- v5.0
- v4.0
- v3.0.14
- v3.0.13
- v3.0.12
- v3.0.11
- v3.0.10
- v3.0.9
- v3.0.8
- v3.0.7
- v3.0.6
- v3.0.5
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0
- v2.0.1
- v2.0
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0
This package is auto-updated.
Last update: 2025-11-02 10:43:13 UTC
README
FyreLog is a free, open-source logging library for PHP.
Table Of Contents
Installation
Using Composer
composer require fyre/log
In PHP:
use Fyre\Log\LogManager;
Basic Usage
$logManager = new LogManager($container);
Default configuration options will be resolved from the "Log" key in the Config.
Autoloading
It is recommended to bind the LogManager to the Container as a singleton.
$container->singleton(LogManager::class);
Any dependencies will be injected automatically when loading from the Container.
$logManager = $container->use(LogManager::class);
Methods
Build
Build a Logger.
$configis an array containing configuration options.
$logger = $logManager->build($config);
Logger dependencies will be resolved automatically from the Container.
Clear
Clear instances and configs.
$logManager->clear();
Get Config
Get a Logger config.
$keyis a string representing the Logger key.
$config = $logManager->getConfig($key);
Alternatively, if the $key argument is omitted an array containing all configurations will be returned.
$config = $logManager->getConfig();
Handle
$levelis a string representing the log level .$messageis a string representing the log message.$datais an array containing data to insert into the message string.$scopeis a string or array representing the log scope, and will default to null.
$logManager->handle($level, $message, $data, $scope);
The supported log levels include: "emergency", "alert", "critical", "error", "warning", "notice", "info" and "debug".
Has Config
Determine whether a Logger config exists.
$keyis a string representing the Logger key, and will default toLogManager::DEFAULT.
$hasConfig = $logManager->hasConfig($key);
Is Loaded
Determine whether a Logger instance is loaded.
$keyis a string representing the Logger key, and will default toLogManager::DEFAULT.
$isLoaded = $logManager->isLoaded($key);
Set Config
Set the Logger config.
$keyis a string representing the Logger key.$optionsis an array containing configuration options.
$logManager->setConfig($key, $options);
Unload
Unload a Logger.
$keyis a string representing the Logger key, and will default toLogManager::DEFAULT.
$logManager->unload($key);
Use
Load a shared Logger instance.
$keyis a string representing the Logger key, and will default toLogManager::DEFAULT.
$logger = $logManager->use($key);
Logger dependencies will be resolved automatically from the Container.
Loggers
You can load a specific logger by specifying the className option of the $config variable above.
Custom loggers can be created by extending \Fyre\Log\Logger, ensuring all below methods are implemented.
Can Handle
Determine whether a log level can be handled.
$levelis a string representing the log level.$scopeis a string or array representing the log scope, and will default to null.
$canHandle = $logger->canHandle($level, $scope);
This method will return true if the $level is contained in the levels of the Logger config (or levels is set to null), and the $scope is contained in scopes (or $scope is null and scopes is an empty array, or scopes is set to null).
Log
Log a message.
$levelis a string representing the log level.$messageis a string representing the log message.$datais an array containing data to insert into the message string.
$logger->log($level, $message, $data);
Array
The Array logger can be loaded using custom configuration.
$optionsis an array containing configuration options.classNamemust be set to\Fyre\Log\Handlers\ArrayLogger.levelsis an array containing the levels that should be handled, and will default to null.scopesis an array containing the scopes that should be handled, and will default to [].
$container->use(Config::class)->set('Log.array', $options);
Clear
Clear the log content.
$logger->clear();
Read
Read the log content.
$content = $logger->read();
File
The File logger can be loaded using custom configuration.
$optionsis an array containing configuration options.classNamemust be set to\Fyre\Log\Handlers\FileLogger.dateFormatis a string representing the date format, and will default to "Y-m-d H:i:s".levelsis an array containing the levels that should be handled, and will default to null.scopesis an array containing the scopes that should be handled, and will default to [].pathis a string representing the directory path, and will default to "/var/log".fileis a string representing the file name, and will default null (the type of log will be used instead).suffixis a string representing the filename suffix, and will default to null (or "-cli" if running from the CLI).extensionis a string representing the file extension, and will default to "log".maxSizeis a number representing the maximum file size before log rotation, and will default to 1048576.
$container->use(Config::class)->set('Log.file', $options);
Logging
Generally, logging is done by calling the handle method of a LogManager instance.
This will call the canHandle method of all defined logger configs, and if that returns true then the handle method will also be called.
The default log levels are shown below (in order of severity).
$messageis a string representing the log message.$datais an array containing data to insert into the message string.$scopeis a string or array representing the log scope, and will default to null.
$logManager->handle('emergency', $message, $data, $scope); $logManager->handle('alert', $message, $data, $scope); $logManager->handle('critical', $message, $data, $scope); $logManager->handle('error', $message, $data, $scope); $logManager->handle('warning', $message, $data, $scope); $logManager->handle('notice', $message, $data, $scope); $logManager->handle('info', $message, $data, $scope); $logManager->handle('debug', $message, $data, $scope);
There are default placeholders that can also be used in log messages:
- {post_vars} will be replaced with the
$_POSTdata. - {get_vars} will be replaced with the
$_GETdata. - {server_vars} will be replaced with the
$_SERVERdata. - {session_vars} will be replaced with the
$_SESSIONdata. - {backtrace} will be replaced with the backtrace.
See the MessageFormatter::formatMessage method for details about message formatting.