Linked Questions

18 votes
1 answer
91k views

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 ...
MeanStreet's user avatar
  • 1,287
294 votes
11 answers
403k views

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 %...
murgatroid99's user avatar
  • 20.4k
138 votes
6 answers
87k views

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

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 ...
flybywire's user avatar
  • 276k
126 votes
3 answers
236k views

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 =...
djvg's user avatar
  • 14.8k
39 votes
1 answer
24k views

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 ...
Martin Thoma's user avatar
16 votes
2 answers
13k views

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....
Filip Kilibarda's user avatar
13 votes
2 answers
7k views

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 ...
Philip's user avatar
  • 2,001
2 votes
4 answers
7k views

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(...
MG1992's user avatar
  • 567
5 votes
1 answer
12k views

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 ...
sfat's user avatar
  • 164
2 votes
1 answer
5k views

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 ...
Crispy13's user avatar
  • 379
9 votes
1 answer
5k views

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 ...
Andrew's user avatar
  • 1,032
4 votes
1 answer
2k views

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 ...
Doron Behar's user avatar
  • 2,916
5 votes
1 answer
2k views

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 ...
Ng Oon-Ee's user avatar
  • 1,265
1 vote
2 answers
2k views

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 ...
PythonLearner's user avatar

15 30 50 per page