开发者

Python module logging with eclipse

开发者 https://www.devze.com 2023-02-10 02:43 出处:网络
I am trying to get logging going across a couple of different modules usinglogging.config.fileConfig() My directory looks something like this:

I am trying to get logging going across a couple of different modules using logging.config.fileConfig() My directory looks something like this:

> Package
   > Source
       __init__.py
       SomeSource.py
   > Test
       __init__.py
       SomeTests.py
   __init__.py

Inside in Package.__init__.py I have the following:

directory = 'C:/User/Me/workspace/Package/'
logFile = 'logger.conf'
logging.config.fileConfig(directory+logFile)
log = logging.getLogger('Package')
log.info('Logging initialized.')

import Test

Inside in Package.Test.__init__.py I have

log = logging.getLogger('Package.Test')
log.info('Test module started')

So the expected output for this is something like:

Logging initialized.
Test Module started.

I can get this to run and log correctly while using eclipse using Ctrl+F11. However, calling it from the interpreter results in nothing at all:

>>> import Package

The log file remains开发者_如何学C empty. Any ideas?


By default the verbosity of logging in an interactive interpreter session will be WARNING, so your INFO messages won't show (Eclipse or a plugin may set the verbosity differently).

Change your .info calls to .warning calls - you should see some output (depending on how your configuration is set up in the conf file).

Alternatively, in your interactive session, do

logging.getLogger().setLevel(logging.DEBUG)

before

import Package
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号