Quantcast
Channel: Custom Logger class and correct line number/function name in log - Stack Overflow
Browsing all 7 articles
Browse latest View live

Answer by Arthur for Custom Logger class and correct line number/function...

Try stacklevel, which counts the number of calls from the original logging call to the logger's debug(), info(), etc., call. It's new in logging 3.8:The third optional keyword argument is stacklevel,...

View Article



Answer by denizb for Custom Logger class and correct line number/function...

The best place to change lineno and filename (if you really want to do that) is in a filter that is attached to the logger. Here is a proof-of-concept. The last line will log a customized message with...

View Article

Answer by Sergei for Custom Logger class and correct line number/function...

Based on @Will Ware's answer. Another option is to overwrite findCaller method and use custom class as default logger: class MyLogger(logging.Logger):""" Needs to produce correct line numbers""" def...

View Article

Answer by Will Ware for Custom Logger class and correct line number/function...

Here's yet another stab at rewriting findCaller. This lets you customize the extra stack frame depth on a per-function basis.import osimport loggingfrom contextlib import...

View Article

Answer by NeilenMarais for Custom Logger class and correct line...

It is possible to generate a log wrapper if you are willing to re-implent a little bit of the standard logging module. The trick is to write your own findCaller() method that knows how to ignore your...

View Article


Answer by Armin Rigo for Custom Logger class and correct line number/function...

Yes: sys._getframe(NUM) where NUM says how how many functions outside the current one you are looking for. The returned frame object has attributes like f_lineno and...

View Article

Custom Logger class and correct line number/function name in log

I'd like to wrap Python logger in a custom class to embed some application-specific functionality and hide setup details from developers (setting file output, logging level, etc). To do this, I created...

View Article
Browsing all 7 articles
Browse latest View live


Latest Images