EDIT The blank spaces were added by an obscure statement in the code, somewhere deep in a sub-function. Once this was removed, the logging output is nice… Therefore I close the subject.
The redirection of console logging to stderrpermitted to highlight this easily, so thanks to commenters!
I’m using Python logging module to handle logging from my project, both to log file and standard output. This works quite nice, based on a config file, with different logging levels.
Problem: to standard output, lines are starting with blank spaces. This seems to be linked to the time elapsed between two writings (something like one space per second).
For sure, I made an error in logging config file, as I’m really not at ease with it, but I cannot identify where. Changing logging level for all to be set at the same will not change anything. Could someone bring some help?
Report file content:
2011-10-11 17:25:43,911 : INFO : P-Tool : P-Tool launched from command-line
2011-10-11 17:25:43,927 : INFO : P-Tool : Starting instantiation of tools
2011-10-11 17:25:43,959 : INFO : P-Tool : Initialization completed
2011-10-11 17:25:43,959 : INFO : P-Tool : Execution started
2011-10-11 17:25:44,973 : WARNING : P-Tool : Process Project File CRC check FAILED, [...]
2011-10-11 17:25:44,973 : INFO : P-Tool : XSD version check passed: Process [...]
2011-10-11 17:25:44,973 : ERROR : P-Tool : XSD validation FAILED for Process[...]
2011-10-11 17:25:44,973 : INFO : P-Tool : Process Call found, ID: 1, short name: [...]
2011-10-11 17:25:44,973 : INFO : lib.tools.I-Tool : importing AC_ICD: [...]
2011-10-11 17:25:52,983 : INFO : lib.tools.I-Tool : importing AC_ICD: [...]
2011-10-11 17:26:00,009 : INFO : lib.tools.V-Tool : verifying project [...]
Standard output:
INFO : P-Tool : P-Tool launched from command-line
INFO : P-Tool : Starting instantiation of tools
INFO : P-Tool : Initialization completed
INFO : P-Tool : Execution started
WARNING : P-Tool : Process Project File CRC check FAILED, [...]
INFO : P-Tool : XSD version check passed: Process Project [...]
ERROR : P-Tool : XSD validation FAILED for Process Project [...]
INFO : P-Tool : Process Call found, ID: 1, short [...]
INFO : lib.tools.I-Tool : importing AC_ICD: [...]
INFO : lib.tools.I-Tool : importing AC_ICD: [...]
INFO : lib.tools.V-Tool : verifying project [...]
ERROR : P-Tool : no CRC found in "Project\Rep[...]
INFO : lib.tools.G-Tool : generating binary for [...]
ERROR : P-Tool : no CRC found in "Project\Reports[...]
INFO : lib.tools.LAF Writer : LAF writing started, [...]
(note how the lines are starting with blank space)
Here is how I configure the logging module:
# in the module p_tool.py
# defining the logging
LOG_CONFIG = 'logging.conf'
logging.config.fileConfig(os.path.join(os.path.split(__file__)[0],
'resources',
LOG_CONFIG))
logger = logging.getLogger('P-Tool')
[...]
# adding some message
logger.info('message to logger')
and the logging configuration file:
# logging.conf
[loggers]
keys=root,P-Tool
[handlers]
keys=consoleHandler,logFileHandler
[formatters]
keys=consoleFormatter,fileFormatter
[logger_root]
level=DEBUG
handlers=consoleHandler,logFileHandler
[logger_P-Tool]
level=DEBUG
handlers=consoleHandler,logFileHandler
qualname=P-Tool
propagate=0
[handler_consoleHandler]
class=StreamHandler
level=INFO
formatter=consoleFormatter
args=(sys.stdout,)
[handler_logFileHandler]
class=FileHandler
level=DEBUG
formatter=fileFormatter
args=('p_tool_log.txt','w')
[formatter_fileFormatter]
format=%(asctime)s : %(levelname)s : %(name)s : %(message)s
datefmt=
[formatter_consoleFormatter]
format=%(levelname)s : %(name)s : %(message)s
datefmt=
As written above, I made two mistakes in my code. Therefore, there’s nothing wrong with the
loggingmodule or the configuration I made of it.The blank spaces were added by an obscure statement in the code, somewhere deep in a sub-function. Once this was removed, the logging output is nice… Therefore I close the subject.
The redirection of console logging to
stderrpermitted to highlight this easily, so thanks to commenters!