Is there any way that i can define my custom levels in monolog in symfony2.
I i do this
$logger->err('An error occurred');
Then in the database i have this added.
The channel is app
and level is 500
Is there any way to do this
$logger->log("message",(channel),(level)
$logger->log("Object with is 212 deleted",'DELETE',NORMAL);
So that i can have separate things in database for reporting and viewing
Monolog log levels Monolog has the following log levels: DEBUG - detailed debug information. INFO - interesting events. NOTICE - normal but significant events.
Generally you might need to classify your log files for different services or modules. For this purpose, Monolog allows you to create different channels, where each can log separately to different file and allow you to configure your log per channel.
Monolog is the existing standard logging library for PHP. It is most popular in PHP frameworks such as Laravel and Symfony, where it implements a common interface for logging libraries. This article talks about the step-by-step process of using PHP Monolog in your application.
By default, Symfony logs are stored in var/log/dev. log and var/log/prod. log within the project directory, depending on the environment, but these defaults can be changed in the Monolog package configuration file found at config/packages/monolog.
With version 2.4 and up (beware, the release cycle of the MonologBundle is not syncronized with symfony anymore) of the MonologBundle, you can now define new channels very simple via configuration, without defining services.
monolog:
channels: ["my_channel"]
Now simply get the automatically created logger for the new channel in your controller:
$logger = $this->get('monolog.logger.my_channel');
$logger->info('somelogcontent');
The message level is defined trough the use of the appropriate method. Take a look into the LoggerInterface
to see all logging methods (which are indeed implemented by monolog). Here some levels to be mentioned:
$logger->info('Info message for interesting things');
$logger->warning('Some application warnings, but the application works');
$logger->error('Error which can influence the application flow/output');
I know old question, but this new feature from the MonologBundle
~2.4
should be mentioned.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With