stderr from error and above
See original GitHub issueHi,
First of all I would like to congratulate for this awesome library, made my logging experience with Python really simple.
I am not sure if I am using the correct way to setup a logger, what I would like to do is to log to stderr from error level above (error, critical, etc).
My current implementation logs error messages to stdout:
def setup_logger():
logger.remove()
logger.add('/tmp/ssh.log', format="{time:YYYY-MM-DD HH:mm:ss} | {level} | {message}", level='DEBUG',
enqueue=True, retention="14 days")
logger.add(sys.stdout, colorize=True, format="{time:YYYY-MM-DD HH:mm:ss} | {level} | {message}", level='INFO',
enqueue=True)
Is there a way do to this?
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How to redirect standard (stderr) error in bash - nixCraft
Explains how to redirect standard error in bash shell on Linux, macOS, BSD & Unix . You can also redirect both stdout &...
Read more >Write Error and above to stderr and Verbose and above to stdout
How to set the configuration in NLog to log errors and above to stderr and log verbose and above to stdout ? //...
Read more >Functions of Stderr in C with Different Examples - eduCBA
Stderr is the standard error message that is used to print the output on the screen or windows terminal. Stderr is used to...
Read more >Standard error - Wikipedia
The standard error (SE) of a statistic is the standard deviation of its sampling distribution or an estimate of that standard deviation.
Read more >Writing Error Messages to Standard Error Instead ... - Learn Rust
macro. In most terminals, there are two kinds of output: standard output ( stdout ) for general information and standard error ( stderr...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @PyAntony.
Defining the level of an handler as the “minimum threshold” for messages to be emitted is a very popular principle among logging libraries. You can look at it this way: by default we don’t want to display debug messages to the user, thus we set the minimal level to “INFO”. However, when something goes wrong, debug messages exist to give more detailed information next to the error messages. If both message are separated in two files, context is lost which makes investigating bugs more challenging. It makes little sense to have the fine grained details without a global view of what is happening.
That’s why in my opinion new arguments like
upper_level
orlevels_allowed
should not be added to theadd()
method. I don’t think this is a good practice when using Loguru.If you need multiple logs to appear in multiple files (for example), it’s advised to use
bind()
with a customfilter
sink function.Indeed. So you want
"ERROR"
and below tostdout
, but"ERROR"
and above tostderr
?In this case you may use a function to
filter
logs emitted tostdout
: