Debug-Log Flashcards
logging.basicConfig(level=logging.DEBUG)
All messges with level >= DEBUG will get logged
What does this do?
logging.basicConfig(
filename=’app.log’, # write logs to this file
filemode=’a’, # open in append mode
format=’%(name)s - %(levelname)s - %(message)s’
)
logs will be appended to the file with name app.log in the specified format
How can you include the process id in the log message?
You can always pass it as a string to the log message but the most easy way is to use LogRecord elements like that:
logging.basicConfig(format=’ID:%(process)d - %(levelname)s - %(message)s’)
What is the LogRecord of logging module?
It’s a class whose instances are created by the Logger. An instance LogRecord has all the information about the record that is being logged like message, levelname, name of logger, function etc
What is a handler?
Its the parent class of other classes like StreamHandler, FileHandler, SMPTHandler etc which are used to send the LogRecord to the right destination, file,console, email etc.
What is a handler?
Its the parent class of other classes like StreamHandler, FileHandler, SMPTHandler etc which are used to send the LogRecord to the right destination, file,console, email etc.W
What is Formatter?
Here you sepcify the format of the output
calls to logging.getLogger(“logger-name”) will return reference to the same logger if the logger-name is the same?
Yes
Should we use module-level loggers with __name__ as the name of the logger?
Yes its a good technique