Entries tagged with “logging”.


Python’s logging module has lots of options. In this article, we will looks at the logging module’s ability to create Rotating Logs. Python supports two types of rotating logs:

  • Rotate logs based on size (RotatingFileHandler)
  • Rotate the logs based on some time interval (TimedRotatingFileHandler)

Let’s spend some time learning how each of these two types of loggers are implemented and used. (more…)

Today I decided to figure out how to make Python log to a file and the console simultaneously. Most of the time, I just want to log to a file, but occasionally I want to be able to see stuff on the console too to help with debugging. I found this ancient example in the Python documentation and ended up using it to mock up the following script: (more…)

Python provides a very powerful logging library in its standard library. A lot of programmers use print statements for debugging (myself included), but you can also use logging to do this. It’s actually cleaner to use logging as you won’t have to go through all your code to remove the print statements. In this tutorial we’ll cover the following topics:

  • Creating a simple logger
  • How to log from multiple modules
  • Log formatting
  • Log configuration

By the end of this tutorial, you should be able to confidently create your own logs for your applications. Let’s get started! (more…)