eonx-com / easy-logging
Create and configure Monolog Loggers easily
Installs: 723 074
Dependents: 4
Suggesters: 6
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.2
- eonx-com/easy-utils: ^6.4.2
- monolog/monolog: ^3.7
- symfony/config: ^7.1
- symfony/contracts: ^3.5
- symfony/dependency-injection: ^7.1
- symfony/http-kernel: ^7.1
Requires (Dev)
- bugsnag/bugsnag: ^3.29
- eonx-com/easy-test: ^6.4.2
- laravel/lumen-framework: ^11.0
- phpunit/phpunit: ^10.2
Suggests
- bugsnag/bugsnag: For Bugsnag integration
- 6.x-dev
- dev-master / 6.5.x-dev
- 6.4.2
- 6.4.1
- 6.4.0
- 6.3.2
- 6.3.1
- 6.3.0
- 6.2.0
- 6.1.0
- 6.0.3
- 6.0.2
- 6.0.1
- 6.0.0
- 6.0.0-rc.1
- 6.0.0-alpha.5
- 6.0.0-alpha.4
- 6.0.0-alpha.3
- 6.0.0-alpha.2
- 6.0.0-alpha
- 5.13.2
- 5.13.1
- 5.13.0
- 5.12.1
- 5.12.0
- 5.11.3
- 5.11.2
- 5.11.1
- 5.11.0
- 5.10.5
- 5.10.4
- 5.10.3
- 5.10.2
- 5.10.1
- 5.10.0
- 5.9.3
- 5.9.2
- 5.9.1
- 5.9.0
- 5.8.0
- 5.7.5
- 5.7.4
- 5.7.3
- 5.7.2
- 5.7.1
- 5.7.0
- 5.6.16
- 5.6.15
- 5.6.14
- 5.6.13
- 5.6.12
- 5.6.11
- 5.6.10
- 5.6.9
- 5.6.8
- 5.6.7
- 5.6.6
- 5.6.5
- 5.6.4
- 5.6.3
- 5.6.2
- 5.6.1
- 5.6.0
- 5.5.0
- 5.4.0
- 5.3.2
- 5.3.1
- 5.3.0
- 5.2.2
- 5.2.1
- 5.2.0
- 5.1.7
- 5.1.6
- 5.1.5
- 5.1.4
- 5.1.3
- 5.1.2
- 5.1.1
- 5.1.0
- 5.0.3
- 5.0.2
- 5.0.1
- 5.0.0
- 4.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 3.0.5-alpha4
- 3.0.5-alpha3
- 3.0.5-alpha2
- 3.0.5-alpha1
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 3.0.0-alpha2
- 3.0.0-alpha1
- 2.5.33
- 2.5.32
- 2.5.31
- 2.5.30
- 2.5.29
- 2.5.28
- 2.5.27
- v2.5.26
- v2.5.25
- v2.5.24
- v2.5.23
- v2.5.22
- v2.5.21
- v2.5.20
- v2.5.19
- v2.5.18
- v2.5.17
- v2.5.16
- v2.5.15
- v2.5.14
- v2.5.13
- v2.5.12
- v2.5.11
- v2.5.10
- v2.5.9
- v2.5.8
- v2.5.7
- v2.5.6
- v2.5.5
- v2.5.4
- v2.5.3
- v2.5.2
- v2.5.1
- v2.5.0
- v2.4.49
- v2.4.48
- v2.4.47
- v2.4.46
- v2.4.45
- v2.4.44
- v2.4.43
- v2.4.42
- v2.4.41
- v2.4.40
- v2.4.39
- v2.4.38
- v2.4.37
- v2.4.36
- v2.4.35
- v2.4.34
- v2.4.33
- v2.4.32
- v2.4.31
- v2.4.30
- v2.4.29
- v2.4.28
- v2.4.27
- v2.4.26
- v2.4.25
- v2.4.24
- v2.4.23
- v2.4.22
- v2.4.21
- v2.4.20
- v2.4.19
- v2.4.18
- v2.4.17
- v2.4.16
- v2.4.15
- v2.4.14
- v2.4.13
- v2.4.12
- v2.4.11
- v2.4.10
- v2.4.9
- v2.4.8
- v2.4.7
- v2.4.6
- v2.4.5
- v2.4.4
- v2.4.3
- v2.4.2
- v2.4.1
- v2.4.0
- v2.3.17
- v2.3.16
- v2.3.15
- v2.3.14
- v2.3.13
- v2.3.12
- v2.3.11
- v2.3.10
- v2.3.9
- v2.3.8
- v2.3.7
- v2.3.6
- v2.3.5
- v2.3.4
- v2.3.3
- v2.3.2
- v2.3.1
- v2.3.0
- v2.2.1
- v2.2.0
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.10
- v2.0.9
- v2.0.8
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.0.1
- v1.0.0
- v0.11.2
- v0.11.1
- v0.11.0
- v0.10.11
- v0.10.10
- v0.10.9
- v0.10.8
- dev-feature/swoole-error-response
- dev-hotfix/swoole-pdo-client-pool-own-implementation
- dev-np/investigate-swoole-errors-in-aws
- dev-feature/git-subtree-for-split-1
- dev-feature/git-subtree-for-split
- dev-feature/easy-async-refactor
- dev-3.x-split-test
- dev-feature/exception-to-status-code
- dev-feature/easy-request-id
- dev-feature/error-handler-framework-agnostic
- dev-feature/easy-bugsnag
- dev-feature/aws-credentials-finder
- dev-feature/aws-sso-access-token
- dev-feature/easy-webhook-profiler
- dev-feature/easy-webhooks
- dev-feature/refactor-easy-security
- dev-feature/refactory-easy-api-token
- dev-feature/search-in-easy-core
- dev-integration/easy-api-token-and-easy-security
- dev-feature/improve-data-persister-structure
- dev-feature/improve-easy-ssm-console-export
- dev-feature/make-commands
- dev-feature/persister-route-paremeters-aware
- dev-hotfix/data-persister-decoration-priority
- dev-feature/auto-configure-doctrine-listeners
- dev-feature/enhance-api-platform
- dev-whitesource/configure
- dev-feature/migrate-core-bundle
- dev-HEAD
- dev-feature/new-branch-for-split-test
- dev-feature/new-branch-for-split-test-1
- dev-feature/easy-async-package
- dev-feature/easier-permissions
- dev-feature/easy-test-package
This package is auto-updated.
Last update: 2024-11-28 13:37:02 UTC
README
---eonx_docs--- title: Introduction weight: 0 ---eonx_docs---
This package allows you to create and configure Monolog Loggers in centralised and reusable way:
- Configure channels using PHP
- Control Handlers and Processors order
- Integration with popular frameworks (e.g. Laravel, Symfony)
- Discover Handlers and Processors automatically in your application
Require package (Composer)
The recommended way to install this package is to use Composer:
$ composer require eonx-com/easy-logging
Usage
Here is a simple example on how to use the LoggerFactoryInterface
to create loggers:
// Instantiate the logger factory manually or use DI ... $default = $loggerFactory->create(); // Calling create without arguments will create logger for default channel $console = $loggerFactory->create('console'); // Create logger for console channel specifically
Usage in Framework
The different integrations provided by this package will by default register the logger for your default channel in the service container under the following service ids:
Psr\Log\LoggerInterface
logger
You can then use dependency injection anywhere you like!
Thanks to Autowiring via setters in Symfony, you can use \EonX\EasyLogging\Logger\LoggerAwareTrait
to simplify the injection of Psr\Log\LoggerInterface
.
Logger Configuration
The LoggerFactoryInterface
allows you to set different collections of "config providers", each config can define:
- channels: if defined the config will be applied only to given channels, if
null
the config will be applied to all channels - priority: define the order each config must be set on the logger instance, higher the priority later the config will be added to the logger instance
HandlerConfig
The HandlerConfigInterface
allows you to configure \Monolog\Handler\HandlerInterface
to be set loggers created by
the factory. Like other configs, it allows you to specify a list of channels this handler is for and, also a priority
to control when the handler must be executed.
To tell the logger factory about your HandlerConfigInterface
, you must use a HandlerConfigProviderInterface
. The
logger factory accepts a collection of providers via the setHandlerConfigProviders()
method:
use EonX\EasyLogging\Factory\LoggerFactory; $handlerConfigProviders = []; // Add your own handler config providers to $handlerConfigProviders ... $loggerFactory = new LoggerFactory(); // Set your handler config providers on the logger factory $loggerFactory->setHandlerConfigProviders($handlerConfigProviders);
Here is a simple example of a HandlerConfigProviderInterface
to register a StreamHandler
:
namespace App\Logger; use EonX\EasyLogging\Config\HandlerConfig; use EonX\EasyLogging\Provider\HandlerConfigProviderInterface; use Monolog\Handler\StreamHandler; final class StreamHandlerConfigProvider implements HandlerConfigProviderInterface { /** * @return iterable<\EonX\EasyLogging\Config\HandlerConfigInterface> */ public function handlers(): iterable { /** * This method returns an iterable to make it easier to handle complex handler configs definition * But you can simply return an array if you want. */ yield new HandlerConfig(new StreamHandler('php://stdout')); } }
ProcessorConfig
The ProcessorConfigInterface
allows you to configure \Monolog\Processor\ProcessorInterface
to be set loggers created
by the factory. Like other configs, it allows you to specify a list of channels this handler is for and, also a priority
to control when the handler must be executed.
To tell the logger factory about your ProcessorConfigInterface
, you must use a ProcessorConfigProviderInterface
. The
logger factory accepts a collection of providers via the setProcessorConfigProviders()
method:
use EonX\EasyLogging\Factory\LoggerFactory; $processorConfigProviders = []; // Add your own processor config providers to $handlerConfigProviders ... $loggerFactory = new LoggerFactory(); // Set your processor config providers on the logger factory $loggerFactory->setProcessorConfigProviders($processorConfigProviders);
Here is a simple example of a ProcessorConfigProviderInterface
to register a TagProcessor
:
namespace App\Logger; use EonX\EasyLogging\Config\ProcessorConfig; use EonX\EasyLogging\Provider\ProcessorConfigProviderInterface; use Monolog\Processor\TagProcessor; final class TagProcessorConfigProvider implements ProcessorConfigProviderInterface { /** * @return iterable<\EonX\EasyLogging\Config\ProcessorConfigInterface> */ public function processors(): iterable { /** * This method returns an iterable to make it easier to handle complex processor configs definition * But you can simply return an array if you want. */ yield new ProcessorConfig(new TagProcessor(['tag-1', 'tag-2'])); } }
LoggerConfigurator
The \Monolog\Logger
class has methods allowing you to configure it even more (e.g. using microseconds). To deal with
that, the logger factory accepts a collection of LoggerConfiguratorInterface
.
To tell the logger factory about your LoggerConfiguratorInterface
, you must call the setLoggerConfigurators()
method:
use EonX\EasyLogging\Factory\LoggerFactory; $loggerConfigurators = []; // Add your own logger configurators to $loggerConfigurators ... $loggerFactory = new LoggerFactory(); // Set your logger configurators on the logger factory $loggerFactory->setLoggerConfigurators($loggerConfigurators);
Here is a simple example of a LoggerConfiguratorInterface
to use microseconds:
namespace App\Logger; use EonX\EasyLogging\Config\AbstractLoggingConfig; use EonX\EasyLogging\Configurator\LoggerConfiguratorInterface; use Monolog\Logger; final class UseMicrosecondsLoggerConfigurator extends AbstractLoggingConfig implements LoggerConfiguratorInterface { public function configure(Logger $logger) : void { $logger->useMicrosecondTimestamps(true); } }