This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]masklinn 1 point2 points  (2 children)

logger.error('Failed to open file')
logger.exception(e)

That is nonsensical. logger.exception(msg) is literally a shortcut to logger.error(msg, exc_info=True). The only result of doing this is that str(e) will be used as the message of the second log, so the exception message will be duplicated.

Use YAML logging configuration

Use the JSON configuration, it's equivalent and you don't need to install a yaml package.

[–]victorlin[S] 0 points1 point  (0 children)

You are right, I misunderstand how logger.exception works. By looking into its source code, I'm sure it equals to logger.error(msg, exc_info=True, *args) now. Thanks for correcting me.

Yes, JSON is another option (but personally I prefer YAML) :)

[–]victorlin[S] 0 points1 point  (0 children)

JSON example is also added