スキップしてメイン コンテンツに移動

投稿

ラベル(logger)が付いた投稿を表示しています

Static Access to Symfony2 Logger

If you would like to use logging functionality in Symfony2, you should access logger service via container. For example in controller, you can easily access container and access logger service. $logger = $this->get('logger'); $logger->info('I just got the logger'); $logger->error('An error occurred'); Well, that's it. However, this is big however for me, what should I do when accessing logger not from controller class? Of course you can pass container or logger service itself to the class in service.yml service_use_logger: class: LoggingExample\Service\ServiceUsingLogger arguments: - @logger A bit pain everytime we should passing logger to the service class if you would like to use logger. For Java or .Net, I have never seen general logging functionality is provided from dependency injection container. For Almost all logging library, logger can be accessible as static - for example log4j. I tried to make logging functio