Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

single logger in python project?

Tags:

python

logging

I'd like to create a logger for a python project. I want to make sure that i'm using the same logger for every module in the project. What is the best way to do this? It seems I need a global logging object? Or perhaps a logging module that is imported by every other module? I want to make sure that I'm always writing to the same log file.

I'm using python's logger and handler already. The problem is that I have to define which file the logger will write to in every module. I'd like to define the log file path once and have it be used for every module.

like image 732
Ramy Avatar asked Jan 21 '23 02:01

Ramy


1 Answers

As you say, look at Python's logging module

It provides objects like Logger and Handler, I think it can work for you.

like image 190
utdemir Avatar answered Jan 29 '23 11:01

utdemir