[mostly code] musings of a software developer from nairobi | learning Swift
Configuring Multiple Loggers in Python
June 17, 2015
At times you may want to have multiple loggers in your application, e.g. one for a payments module and another for a messaging module. I’m going to explain how to set this up in your application, as well as show some examples for usage.
First, create a file, maybe call it logger.py
Import some required libraries
For example, if our app is called wasted_meerkats, and we have 2 modules, payments and messaging, we could set up different loggers as follows:
To test this out, you could create another file, called wasted_meerkats.py and put the following code in it:
Create the log directories above
In a separate tab, tail the logs
Then test it out!
The log output should look something like this:
Having all the loggers in one file can help organize your project better.