Download the PHP package bizkit/loggable-command-bundle without Composer
On this page you can find all versions of the php package bizkit/loggable-command-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package loggable-command-bundle
BizkitLoggableCommandBundle
Symfony bundle which creates a dedicated Monolog log file for each command or message handler.
Features
- Dynamically creates a dedicated Monolog file handler for each command or message handler
- Uses Monolog's console handler to display the output inside a terminal
- Supports using Monolog's stream or rotating file handlers & creating custom handler factories
- Automatically excludes the configured Monolog channel from all other handlers with exclusive channels
- Allows per command configuration through the use of PHP 8 attributes or Doctrine annotations
- Supports configuring which output stream should be used by certain log levels (
stdout
orstderr
)
Requirements
- PHP 7.2 or greater
- Symfony 4.4 or Symfony 5.2 or greater
Installation
-
Require the bundle with Composer:
-
Create the bundle configuration file under
config/packages/bizkit_loggable_command.yaml
. Here is a reference configuration file: - Enable the bundle in
config/bundles.php
by adding it to the array:
Usage
The bundle provides a way to log the output of a Symfony Command
or Symfony Messenger's message handler into
a dedicated file by dynamically creating a Monolog file handler & logger for each
service. Supported file handlers are the stream
& rotating_file
handlers. To use other file handlers,
a custom handler factory must be implemented & registered.
The output logger also uses a console handler to display the output inside a terminal. The stderr_threshold
option can
be used to set the log level at which the output is start being sent to the stderr
stream instead of the stdout
.
Other Monolog handlers can be added to the output logger as well as described in the dedicated section.
Command
The simplest way to enable output logging in a Symfony Command is by extending the LoggableCommand
class. The output
logger can be accessed through the $outputLogger
property. By default, the name of the log file will be the snake
cased version of the command name, e.g. app_my_loggable
.
Instead of extending the LoggableCommand
class, you can also use the LoggableOutputTrait
with
the LoggableOutputInterface
. This is useful when you have a custom base command class.
Message handler
Output logging can also be used with Symfony Messenger's message handlers by implementing the LoggableOutputInterface
.
The name of the log file will be the snake cased version of the classname, e.g. my_message_handler
. A custom name can
be provided by implementing the NamedLoggableOutputInterface
instead.
PHP 8 attribute
The default configuration can be overridden for each individual command or message handler by using the LoggableOutput
PHP attribute. Among other things, it allows you to
change which Monolog file handler is used by the output logger.
The PHP attribute can also be used as an alternative way to provide a custom name for the log file, in which case
implementing the NamedLoggableOutputInterface
is not necessary.
Attribute options are inherited from all parent classes that have the PHP attribute declared. In case both a parent & a child class have the same option defined, the one from the child class has precedence.
Doctrine annotations
If you're using a version of PHP prior to 8, Doctrine annotations can be used instead of PHP attributes as a way to override the default configuration.
-
Require the Doctrine annotations library with Composer:
- Enable annotations support in the configuration:
The LoggableOutput
PHP attribute also serves as the Doctrine annotation class.
Annotation options are also inherited from all parent classes.
Adding other Monolog handlers to the output logger
To add other Monolog handlers to the output logger, in case of an inclusive channel list, add the Monolog channel
defined with the channel_name
option to their channels
list.
In case of an exclusive channel list, disable the auto-exclusion feature for that handler.
NOTE: In case of multiple output loggers, each output logger will use the same handler instance.
Monolog channel auto-exclusion
The Monolog channel used by the bundle is automatically excluded from all other Monolog handlers with an exclusive channel list. There's no need to manually add the channel to the list.
Disabling auto-exclusion
If you don't want the channel to be automatically excluded from a certain handler, add it to the channels
list
prefixed with !!
.
Handler factories
Handler factories are used to instantiate & configure the file handler used by the output logger.
Custom handler factories
To implement a custom handler factory all you need to do is create a service which implements
the HandlerFactoryInterface
interface.
Use the FQCN of the service in the configuration:
If you are not using
Symfony's autoconfigure feature or wish
to use an alias in the configuration, tag the service with the bizkit_loggable_command.handler_factory
tag.
To simplify the configuring of a handler factory the bundle comes with an AbstractHandlerFactory
class which can be
used to configure some common handler features such as the PSR 3 log message
processor or a log formatter.
Versioning
This project adheres to Semantic Versioning 2.0.0.
Reporting issues
Use the issue tracker to report any issues you might have.
License
See the LICENSE file for license rights and limitations (MIT).
All versions of loggable-command-bundle with dependencies
monolog/monolog Version ^1.25.1 || ^2 || ^3
symfony/config Version ^4.4 || ^5.2 || ^6.0 || ^7.0
symfony/console Version ^4.4 || ^5.2 || ^6.0 || ^7.0
symfony/dependency-injection Version ^4.4 || ^5.2 || ^6.0 || ^7.0
symfony/http-kernel Version ^4.4 || ^5.2 || ^6.0 || ^7.0
symfony/monolog-bridge Version ^4.4 || ^5.2 || ^6.0 || ^7.0
symfony/monolog-bundle Version ^3.4