question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use pm2 with loguru

See original GitHub issue

Hello!

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:

image

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")

image

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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Delgancommented, Oct 28, 2020

Thanks for the write-up!

Usually I would configure the logger inside an if __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. 👍

2reactions
theunkn0wn1commented, Oct 28, 2020

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:

  • this code only ever executes once unless dynamic module reloading hackery is employed
  • this code can be re-used by multiple executables under the same project, without special effort.

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).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python logging package always logs to pm2 error · Issue #4817
When managing a python3 script with pm2, if you use the logging package it always outputs as an error log to pm2 even...
Read more >
Logs - PM2
Advanced process manager for production Node.js applications. Load balancer, logs facility, startup script, micro service management, ...
Read more >
A Complete Guide to Winston Logging in Node.js - Better Stack
In this tutorial, we will explain how to install, set up, and use the Winston logger in a Node.js application. We'll go through...
Read more >
Log Storage | Guides | PM2 Enterprise Documentation - PM2.IO
Overview. This feature allow to store all of your application logs directly in PM2 Enterprise so you can retrieve them later to inspect...
Read more >
How to use PM2 for monitoring production Node JS applications
This tutorial will help you have a working Node JS express app with logging and monitoring.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found