V
V
Vladislav2017-01-05 20:25:12
symfony
Vladislav, 2017-01-05 20:25:12

Trouble with logger in symfony, what's wrong?

I connect the logger as follows, but it still does not write to the file, but only to the console:

#app/config/config_dev.yml
monolog:
    handlers:
        search:
            type: stream
            level: error
            path: "%kernel.logs_dir%/search_log.log"
            channels: [search]
        main:
            type: stream
            path: "%kernel.logs_dir%/%kernel.environment%.log"
            level: debug
            channels: [!event, !search]
        console:
            type:   console
            channels: [!event, !doctrine, !search]

#MyBundle/Resources/config/services.yml
services:
    app.logger_search:
            class: Symfony\Bridge\Monolog\Logger
            arguments: ["@logger"]
            tags:
                - {name: monolog.logger, channel: search}

Now I'm trying to test it.
#MyController.php

/**
     * @Route("/test")
     */
    public function test()
    {
        $this->get("app.logger_search")->error("Test");
        return $this->json("test");
    }

But instead of writing to the specified file, it only writes to the console in which I started the
php server bin/console server:run
What's wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Skobkin, 2017-01-06
@skobkin

Look at the Monolog settings in config_dev.yml.
You have handler specified console.

D
dizzy7, 2017-01-12
@dizzy7

You don't need to create a separate service. In the logger configuration:

monolog:
   channels: ["main", "search"]
   handlers: ...

And for logging, you request the service @monolog.logger.search

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question