473,769 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Logging module: problem with some mapping keys

I'm getting a strange behaviour from the "pathname" and "lineno"
formatter mapping keys. Instead of my file and my line number I get:

/usr/lib/python2.4/logging/__init__.py

as the file, and 1072 as the line number. I set up my config as
follows:

logBaseConf = {
'level' : logging.DEBUG,
'format' : "%(levelnam e)-8s|%(asctime)s| %(pathname)s,
%(name)s, line %(lineno)s|%(me ssage)s",
'datefmt ': '%d %b %Y, %H:%M:%S',
'filename': 'logtest.log',
'filemode': 'a'
}
logging.basicCo nfig(**logBaseC onf)

I'm not using any executable-generating tools such as cx_Freeze or
Psyco. In fact, I'm getting this error on a very basic script with the
specific purpose of testing the logging module capabilities.

Thanks in advance for any contribution.

T.

Dec 13 '06 #1
12 1975

Hi, i've check documentation, and found that logging.basicCo nfig takes
no arguments (probably we have different versions of logging package),
and i've never used it.

just try this:
fileName = 'testlog.log'
logName = 'LOG'
iHandler = logging.FileHan dler(fileName)
iHandler.setFor matter(
logging.Formatt er("%(levelname )-8s|%(asctime)s| %(pathname)s,%( name)s,
line %(lineno)s|%(me ssage)s") )

iLog = logging.getLogg er(logName)
iLog.addHandler (iHandler)
iLog.setLevel(l ogging.DEBUG)

iLog.info('hell o logging')

it gives me:

INFO |2006-12-13 19:57:33,575|te st.py,LOG, line 12|hello logging
On 13 Dec., 19:02, "Tekkaman" <simone....@gma il.comwrote:
I'm getting a strange behaviour from the "pathname" and "lineno"
formatter mapping keys. Instead of my file and my line number I get:

/usr/lib/python2.4/logging/__init__.py

as the file, and 1072 as the line number. I set up my config as
follows:

logBaseConf = {
'level' : logging.DEBUG,
'format' : "%(levelnam e)-8s|%(asctime)s| %(pathname)s,
%(name)s, line %(lineno)s|%(me ssage)s",
'datefmt ': '%d %b %Y, %H:%M:%S',
'filename': 'logtest.log',
'filemode': 'a'
}
logging.basicCo nfig(**logBaseC onf)

I'm not using any executable-generating tools such as cx_Freeze or
Psyco. In fact, I'm getting this error on a very basic script with the
specific purpose of testing the logging module capabilities.

Thanks in advance for any contribution.

T.
--
Maksim Kasimov

Dec 13 '06 #2
Tekkaman wrote:
I'm getting a strange behaviour from the "pathname" and "lineno"
formatter mapping keys. Instead of my file and my line number I get:

/usr/lib/python2.4/logging/__init__.py

as the file, and 1072 as the line number. I set up my config as
follows:

logBaseConf = {
'level' : logging.DEBUG,
'format' : "%(levelnam e)-8s|%(asctime)s| %(pathname)s,
%(name)s, line %(lineno)s|%(me ssage)s",
'datefmt ': '%d %b %Y, %H:%M:%S',
'filename': 'logtest.log',
'filemode': 'a'
}
logging.basicCo nfig(**logBaseC onf)

I'm not using any executable-generating tools such as cx_Freeze or
Psyco. In fact, I'm getting this error on a very basic script with the
specific purpose of testing the logging module capabilities.

Thanks in advance for any contribution.
An evil symlink, maybe?

$ ln -s /usr/local/lib/python2.4/logging
$ python
[snip]
>>import logging
logging.basic Config(format=" %(pathname)s")
logging.getLo gger().critical ("yadda")
/usr/local/lib/python2.4/logging/__init__.py
>>>
$ rm logging
$ python
[snip]
>>import logging
logging.basic Config(format=" %(pathname)s")
logging.getLo gger().critical ("yadda")
<stdin>

Peter

Dec 13 '06 #3

sim.sim wrote:
Hi, i've check documentation, and found that logging.basicCo nfig takes
no arguments (probably we have different versions of logging package),
Your Python version is < 2.4. Now basicConfig takes optional keyword
args:

basicConfig([**kwargs])
Does basic configuration for the logging system by creating a
StreamHandler with a default Formatter and adding it to the root
logger. The functions debug(), info(), warning(), error() and
critical() will call basicConfig() automatically if no handlers are
defined for the root logger.

In my real application (not the small test script!) This behaviour is
very useful since I can call basicConfig only once in the main file and
then all I have to do in the other files is:

import logging
self.logger = logging.getLogg er("myClass")

Everything works smoothly except for not being able to get file and
line number info.
and i've never used it.

just try this:
fileName = 'testlog.log'
logName = 'LOG'
iHandler = logging.FileHan dler(fileName)
iHandler.setFor matter(
logging.Formatt er("%(levelname )-8s|%(asctime)s| %(pathname)s,%( name)s,
line %(lineno)s|%(me ssage)s") )

iLog = logging.getLogg er(logName)
iLog.addHandler (iHandler)
iLog.setLevel(l ogging.DEBUG)

iLog.info('hell o logging')

it gives me:

INFO |2006-12-13 19:57:33,575|te st.py,LOG, line 12|hello logging
On 13 Dec., 19:02, "Tekkaman" <simone....@gma il.comwrote:
I'm getting a strange behaviour from the "pathname" and "lineno"
formatter mapping keys. Instead of my file and my line number I get:

/usr/lib/python2.4/logging/__init__.py

as the file, and 1072 as the line number. I set up my config as
follows:

logBaseConf = {
'level' : logging.DEBUG,
'format' : "%(levelnam e)-8s|%(asctime)s| %(pathname)s,
%(name)s, line %(lineno)s|%(me ssage)s",
'datefmt ': '%d %b %Y, %H:%M:%S',
'filename': 'logtest.log',
'filemode': 'a'
}
logging.basicCo nfig(**logBaseC onf)

I'm not using any executable-generating tools such as cx_Freeze or
Psyco. In fact, I'm getting this error on a very basic script with the
specific purpose of testing the logging module capabilities.

Thanks in advance for any contribution.

T.

--
Maksim Kasimov
Dec 14 '06 #4

Peter Otten wrote:
>
An evil symlink, maybe?
Thanks for the hint, but it's not a symlink
>
$ ln -s /usr/local/lib/python2.4/logging
$ python
[snip]
>import logging
logging.basicC onfig(format="% (pathname)s")
logging.getLog ger().critical( "yadda")
/usr/local/lib/python2.4/logging/__init__.py
>>
$ rm logging
$ python
[snip]
>import logging
logging.basicC onfig(format="% (pathname)s")
logging.getLog ger().critical( "yadda")
<stdin>

Peter
Dec 14 '06 #5
Tekkaman wrote:
Thanks for the hint, but it's not a symlink
What does logging._srcfil e contain? Should be
>>import logging
logging._srcf ile
'/usr/lib/python2.4/logging/__init__.py'

on your machine, but probably isn't.

Peter

Dec 14 '06 #6
'/usr/lib64/python2.4/logging/__init__.py'

Peter Otten wrote:
Tekkaman wrote:
Thanks for the hint, but it's not a symlink

What does logging._srcfil e contain? Should be
>import logging
logging._srcfi le
'/usr/lib/python2.4/logging/__init__.py'

on your machine, but probably isn't.

Peter
Dec 14 '06 #7
Tekkaman wrote:
Peter Otten wrote:
>Tekkaman wrote:
Thanks for the hint, but it's not a symlink

What does logging._srcfil e contain? Should be
>>import logging
logging._srcf ile
'/usr/lib/python2.4/logging/__init__.py'

on your machine, but probably isn't.
'/usr/lib64/python2.4/logging/__init__.py'
And neither /usr/lib nor /usr/lib/python2.4 are symlinks?

Peter

PS: Please don't top-post
Dec 14 '06 #8
lib is a symlink to lib64

Peter Otten wrote:
Tekkaman wrote:
Peter Otten wrote:
Tekkaman wrote:

Thanks for the hint, but it's not a symlink

What does logging._srcfil e contain? Should be

import logging
logging._srcfi le
'/usr/lib/python2.4/logging/__init__.py'

on your machine, but probably isn't.
'/usr/lib64/python2.4/logging/__init__.py'

And neither /usr/lib nor /usr/lib/python2.4 are symlinks?

Peter

PS: Please don't top-post
Dec 14 '06 #9

Peter Otten wrote:
Tekkaman wrote:
Peter Otten wrote:
Tekkaman wrote:

Thanks for the hint, but it's not a symlink

What does logging._srcfil e contain? Should be

import logging
logging._srcfi le
'/usr/lib/python2.4/logging/__init__.py'

on your machine, but probably isn't.
'/usr/lib64/python2.4/logging/__init__.py'

And neither /usr/lib nor /usr/lib/python2.4 are symlinks?

Peter

PS: Please don't top-post
Sry for the top-post, I noticed the PS a moment too late!

Dec 14 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1660
by: Robert.Schmitt | last post by:
I found that the configuration system of the new logging package of Python 2.3 has some unintuitive idiosyncracies that are worth mentioning because they can cost you quite some development time and are not documented elsewhere. I used the logging configuration file shown below. My aim was to log only the INFO messages, but log DEBUG messages for one particular module (called webTestLogin.py).
3
2263
by: Irmen de Jong | last post by:
Hello I'm using the logging module in Python 2.3.3, with a format string containing %(asctime). But it now dumps a full date +timestamp in the log, which is nice but sometimes I only want the timestamp (no date). Is there an easy way to change this? How can I make %(asctime) dump only the time? I'm using a configuration file to set up the logging. Which brings me to another thing.
7
1957
by: marduk | last post by:
I have a weird request. I want to be able to say def myvalues(): while True: # stuff that determines a new somevalue yield somevalue x = "Hello, %s, this is a %s with %s and %s on top of %s" % myvalues()
15
2987
by: Stefan Behnel | last post by:
Hi! I'm trying to do this in Py2.4b1: ------------------------------- import logging values = {'test':'bla'} logging.log(logging.FATAL, 'Test is %(test)s', values) -------------------------------
18
3051
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of a single collections type, I should be proposing a new "namespaces" module instead. Some of my reasons: (1) Namespace is feeling less and less like a collection to me. Even though it's still intended as a data-only structure, the use cases...
10
2674
by: Baurzhan Ismagulov | last post by:
Hello all, I want that each module has its own logger. I've defined the following config file: keys=f01 keys=console
7
8587
by: flupke | last post by:
Hi, i'm getting errors with the log module concerning RotatingFileHandler. I'm using Python 2.4.3 on Windows XP SP2. This used to work in previous python versions but since i upgraded to 2.4.3 i get these errors: Traceback (most recent call last): File "C:\Python24\lib\logging\handlers.py", line 71, in emit if self.shouldRollover(record):
3
6423
by: Lowell Alleman | last post by:
Here is the situation: I wrote my own log handler class (derived from logging.Handler) and I want to be able to use it from a logging config file, that is, a config file loaded with the logging.config.fileConfig() function. Let say my logging class is called "MyLogHandler" and it's in a module called "mylogmodule", I want to be able to make an entry something like this in my logging config file:
6
7586
by: Larry Bates | last post by:
Every time I look at the logging module (up until now) I've given up and continue to use my home-grown logger that I've been using for years. I'm not giving up this time ;-) I find that I REALLY need to be able to monitor LOTS of running programs/processes and thought it would be nice to have them use SocketHandler logging and then I would write TCPServer to accept the log messages for real-time monitoring. I Googled (is that now a...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10210
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10039
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9860
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8869
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6668
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3560
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.