Use pm2 with loguru
See original GitHub issueHello!
I have been very appreciated to use loguru where a friend of mine has showed me and its been what I have been looking for in ages!
I have some issues with it and I wouldn’t say its a bug or so, maybe a new feature or something I might have missed?
What I have done is super simple script such as:
from loguru import logger
logger.info("hello world")
and I tried to run it with something called PM2 which looks like this:
The only issue is that it marks it as a “error” with the red line which shouldn’t. How is when I change it to a normal print:
print("hello world")
So my question is simple as, is it possible to do something similar where logger.info would mark it as a “green” success color in the pm2 while exception/debug could be red?
As I mentioned, its probably maybe not an issue but maybe a cool feature for those who uses pm2 and if there is anything I can help you out, please let me know! 😃
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Thanks for the write-up!
Usually I would configure the
logger
inside anif __name__ == "__main__"
block in case the app is used as a library. However, as you call.remove()
before.add()
, even if the module happens to be re-imported for some reason, it should not be noticeable.Glad you found a solution. I wish a good day to both of you too. 👍
Was giving advise to @BarryThrill in a side channel, this is what we came up with:
shunt the pm2 sink & logger configuration to a module, that executes the necessary loguru configuration calls on import. this has two major effects:
Specifically we shunted it to the package’s top-level
__init__.py
, so it executes on startup as a natural result of executing anything under the package via-m
.This does have the unfortunate side effect of working too well, im not sure we can do an entry-point check on
__init__.py
to prevent the logger reconfiguration if the project is imported by something else; though in this application thats not important (as its not a library).