I created a new Magento 2 module and followed the injection-based logger object creation.

protected $logger;
public function __construct(\Psr\Log\LoggerInterface $logger)

Now, when I log using this logger, I get it logged as module main. e.g.

[2019-08-22 10:42:02] main.INFO: message ...

I presume, the main is the root logger. How can I create my logger, so that instead of main, it will print my module name every time?

This is pretty standard practice in java to create a logger for the given class or package so that you can control the logging levels per package. I don't even want to control the level, at least this will help me grep for my messages in my log. How can I achieve this?

1 Answer 1


You can check my repo: CustomLog

Still facing any problem add comment.I will try to help you.

  • This repo seems nice if I had to change the target file. I dont want to do that. I would prefer it goes to the system.log as is, but only want to change the prefix in every log. I am not sure how that portion is initialized. Any comment on that?
    – melchi
    Aug 26, 2019 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.