Normally you just get logger
service, and logs go to:
%kernel.root_dir%/%kernel.environment%.log
I would like to log messages form SOAP services ONLY to:
%kernel.root_dir%/%kernel.environment%.soap.log
not to main logfile.
I've read the cookbook, but I don't understand how to configure monolog.
Any help, clues?
I had a similar problem and I chose to use the Monolog library directly instead of the Monolog service.
Monolog uses
Monolog\Handler\StreamHandler
to write to files. The github page has a simple example:It may be possible to still use the service and simply push a new handler (and pop it once you're done - otherwise you might inadvertently write more than you wanted to to your custom log) but I haven't tested this. Honestly it seemed easier just to use the library directly.
I solved the same issue by creating custom channels in config.yml as explained in this link How to Log Messages to different Files.
After this, I can access my looger with a dynamically created service named monolog.logger.my_logger
The MonologBundle logs everything using the same handlers for the whole framework. That means if one of your services needs to log to different handlers, you should create your own Logger/Handler and inject that in your service.
This could be an example config (in yaml):
I hope this clarifies it.
Update: as of symfony 2.1, you can also configure which channels receive which handlers, so you could alternatively do something like this:
Which creates a new soap channel (i.e. logger instance receiving all handlers), then to configure different handlers for this channel:
This means the main handler will receive everything but the soap channel, and the soap handler will receive only the soap channel. You could also remove the
channels
key on the main handler if you want your main log file to have everything, but also have a copy of only the soap logs separately. This brings a lot of flexibility, and as you see the channels is an array so you can list channels you want, or use the blacklist!name
notation to exclude some and include everything else.