Linked Questions
31 questions linked to/from Using logging in multiple modules
18 votes
1 answer
91k views
Logging in classes - Python [duplicate]
I'm trying to use Python's logging module, and have questions on the best way to use it. I define several classes, want to write logs and be able to set the level of all of them at the same time. I ...
294 votes
11 answers
403k views
Python logging not outputting anything
In a python script I am writing, I am trying to log events using the logging module. I have the following code to configure my logger: ERROR_FORMAT = "%(levelname)s at %(asctime)s in %(funcName)s in %...
138 votes
6 answers
87k views
Get __name__ of calling function's module in Python
Suppose myapp/foo.py contains: def info(msg): caller_name = ???? print '[%s] %s' % (caller_name, msg) And myapp/bar.py contains: import foo foo.info('Hello') # => [myapp.bar] Hello I want ...
74 votes
9 answers
41k views
Good or bad practice in Python: import in the middle of a file [duplicate]
Suppose I have a relatively long module, but need an external module or method only once. Is it considered OK to import that method or module in the middle of the module? Or should imports only be ...
126 votes
3 answers
236k views
How to use logging.getLogger(__name__) in multiple modules
From the logging howto for Python 2.7 (my emphasis): A good convention to use when naming loggers is to use a module-level logger, in each module which uses logging, named as follows: logger =...
39 votes
1 answer
24k views
How should logging be used in a Python package?
I am currently developing a package which can be used without writing any new code and the modules can be used to develop new code (see documentation). Many of my modules use logging in a very simple ...
16 votes
2 answers
13k views
Python logging multiple modules logger not working outside main program
My goal is to log from multiple modules, while only configuring the logger in one place - in the main program. As shown in this answer, one should include logging.config.fileConfig('/path/to/logging....
13 votes
2 answers
7k views
How to log from separate module in Flask
I have a simple Flask app like this: from flask import Flask import util APP = Flask("app") APP.debug = True @APP.route('/', methods=['GET']) def index(): APP.logger.info("info message from ...
2 votes
4 answers
7k views
Python logging module imported in different scripts
In the python logging tutorial, there is an example with two python scripts : myapp.py, and mylib.py The code is : # myapp.py import logging import mylib def main(): logging.basicConfig(...
5 votes
1 answer
12k views
Python logging from multiple modules to same log file
I am working on a Python library with multiple packages and a main routine outside these packages. I have set up a logger to log to the standard output and a log file using a configuration file as ...
2 votes
1 answer
5k views
Can i set logging level of all loaded modules at once?
main module module A module B The main module uses the functions of modules. The functions of modules include logger.info or logger.warning.. so on to show what i made wrong about the code. Objective ...
9 votes
1 answer
5k views
Share Python logger across multiple files
I have a python application with a file structure similar to the following: /Project file1.py file2.py file3.py ... The application is using Python 2.6 as it is running on a CentOS 6 ...
4 votes
1 answer
2k views
logging with the same logging levels across modules
I'm somewhat new to Python, especially in writing modules and functions in several files and not just raw scripts. I'm writing a command line app and I would like to have a single function (I call it ...
5 votes
1 answer
2k views
Using python 'logging' when logging.root has been redefined (Kivy)
I've already seen Using Python logging in multiple modules and similar which recommend using:- import logging logger = logging.getLogger(__name__) in every module. However I'm also using Kivy as a ...
1 vote
2 answers
2k views
How to define logging in one place in Python?
I am new Python and I want to define the following logging code in python in one place so that it can be used in other python files(class or non-class). In case of Java, we use log4j or slf4j as part ...