Debug-Log Flashcards

1
Q

logging.basicConfig(level=logging.DEBUG)

A

All messges with level >= DEBUG will get logged

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A

logs will be appended to the file with name app.log in the specified format

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can you include the process id in the log message?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the LogRecord of logging module?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a handler?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a handler?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is Formatter?

A

Here you sepcify the format of the output

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

calls to logging.getLogger(“logger-name”) will return reference to the same logger if the logger-name is the same?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Should we use module-level loggers with __name__ as the name of the logger?

A

Yes its a good technique

How well did you know this?
1
Not at all
2
3
4
5
Perfectly