-
-
Notifications
You must be signed in to change notification settings - Fork 240
Closed
Description
Hello,
My goal is to store logs with level "error" in a DB, just to facilitate their readings from inside my app. I've written a simple custom handler :
class MonologDoctrineHandler extends AbstractProcessingHandler
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
)
{
parent::__construct();
}
/**
* @inheritDoc
*/
protected function write(LogRecord $record): void
{
$logEntry = new ApplicationLog();
$logEntry
->setMessage($record['message'])
->setLevel($record['level'])
->setLevelName($record['level_name'])
->setExtra($record['extra'])
->setContexte($record['context'])
;
$this->entityManager->persist($logEntry);
$this->entityManager->flush();
}
}The service is declared in the "services.yaml" file, with the needed entitymanager as argument :
monolog.doctrine_handler:
class: App\Manager\Tools\MonologDoctrineHandler
arguments: ['@doctrine.orm.default_entity_manager']And I've added this handler in the configuration of the monolog bundle :
when@dev:
monolog:
handlers:
main:
type: rotating_file
path: "%kernel.logs_dir%/%kernel.environment%_main.log"
level: debug
channels: [ "!security", "!audit" ]
max_files: 30
db:
type: service
id: monolog.doctrine_handler
level : error
channels: ["!security", "!audit", "!doctrine"]Log entries are effectively written to the database, but the "level: error" in the monolog.yaml is not respected. All log levels are written (info, debug are written for example). I could filter this in my handler, but this would be more practical to be able to change this as needed in the yaml file. Is this a bug, or do I missed something in my configuration or in the documentation ?
Thank you.
Michaël
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels