0

I've defined a service to handle logging of records with specific text (e.g. "matched route" and such). I'm successfully writing those records out to a separate file.

However, what I want to avoid is writing them a second time to the primary log file. I've tried tagging my service with a channel and telling the main stream log to ignore that channel, but it occurs to me that it won't work since, in essence, the main stream logging handler matches everything.

Any advice on how to proceed?

EDIT: Here's what I have at the moment:

monolog:
    channels: ['noise']
    handlers:
        eliminate_noise_logger:
            type: service
            id: common.eliminate_noise_logger
            channels: ['noise']

        streamed:
            type:  stream
            level: info
            path:  "%kernel.logs_dir%/%kernel.environment%.log"
            formatter: monolog.formatter.session_request
            channels: ['!noise']

        console:
            type:  console
            verbosity_levels:
                VERBOSITY_NORMAL: INFO

And my services definition:

common.eliminate_noise_logger:
    class: path\to\class
    arguments: ["%kernel.logs_dir%/%kernel.environment%.noise.log", ["str1", "str2", "str3"]]
    tags:
        - { name: monolog.logger, channel: noise }

1 Answers1

0

This is how I do

#config.yml
monolog:
    use_microseconds: false
    channels: ['secondary']
    handlers:
        main:
            path: %kernel.logs_dir%/%kernel.language%/%kernel.environment%.log
            type          : fingers_crossed
            action_level  : error
            handler       : nested
            channels      : ['!secondary']
        secondary:
            type: rotating_file
            max_files: 10
            path: %kernel.logs_dir%/%kernel.language%/%kernel.environment%.secondary.log
            level: info
            channels: [secondary]
OlivierC
  • 682
  • 4
  • 11
  • I gave it a go, and it didn't work -- it's possible that I've got other things that are conflicting. I can't recall exactly what the result was, but I know that the main log file continued to get the stuff I wanted filtered out. – Carl Anderson Jan 13 '17 at 15:26
  • Did you try with second handler named secondary (and not secondary_channel) ? It is a typo i just seen reviewing my answer – OlivierC Jan 13 '17 at 15:32
  • Think so. I'm going to try again at some point in the next couple of days; work priorities shifted a bit. – Carl Anderson Jan 17 '17 at 19:49
  • Updated my question with the code I presently have. – Carl Anderson Jan 18 '17 at 16:46
  • If you want to use a service as handler you should have a look to http://stackoverflow.com/a/12937125/7169909. Otherwise you can have a look to [MonologBundle configuration](http://symfony.com/doc/current/reference/configuration/monolog.html) on Symfony doc and [Monolog configuration](https://github.com/symfony/monolog-bundle/blob/master/DependencyInjection/Configuration.php) on github. With the last link you will have minimum parameters to set for each handler type – OlivierC Jan 18 '17 at 17:15