0

I use the logging just plasing logging.mylog('message') in my different files. And I have this format:

logging.basicConfig(format = u'[%(asctime)s] # %(levelname)-4s\t%(filename)s[LINE:%(lineno)d]\t%(message)s', level = logging.MYLOG)

I took the function addLoggingLevel from https://stackoverflow.com/a/35804945/4647888

and found that filename always printed as main.py because I declare addLoggingLevel function in this file. Never mind in which file "logging.mylog('message')" placed.

So my question is: how to add a custom logging level with full support of standard levels behavior and with no surprises?

Kroll
  • 649
  • 2
  • 6
  • 17
  • What are you trying to achieve? What’s missing from the current logging implementation? You may want to take a closer look at the [`LogRecord`](https://docs.python.org/3/library/logging.html#logging.LogRecord)… ? – Jens Aug 09 '20 at 08:39
  • You should get the logger per module: `logger = logging.getLogger(__name__)` and use that instead of `logging`. – Klaus D. Aug 09 '20 at 08:43
  • I trying to achieve different filenames of mylog() call not main.py every time. Why cant I use ```logging``` like with standard loglevel methods? – Kroll Aug 09 '20 at 09:18

0 Answers0