473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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' : "%(levelname)-8s|%(asctime)s|%(pathname)s,
%(name)s, line %(lineno)s|%(message)s",
'datefmt ': '%d %b %Y, %H:%M:%S',
'filename': 'logtest.log',
'filemode': 'a'
}
logging.basicConfig(**logBaseConf)

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 1936

Hi, i've check documentation, and found that logging.basicConfig 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.FileHandler(fileName)
iHandler.setFormatter(
logging.Formatter("%(levelname)-8s|%(asctime)s|%(pathname)s,%(name)s,
line %(lineno)s|%(message)s") )

iLog = logging.getLogger(logName)
iLog.addHandler(iHandler)
iLog.setLevel(logging.DEBUG)

iLog.info('hello logging')

it gives me:

INFO |2006-12-13 19:57:33,575|test.py,LOG, line 12|hello logging
On 13 Dec., 19:02, "Tekkaman" <simone....@gmail.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' : "%(levelname)-8s|%(asctime)s|%(pathname)s,
%(name)s, line %(lineno)s|%(message)s",
'datefmt ': '%d %b %Y, %H:%M:%S',
'filename': 'logtest.log',
'filemode': 'a'
}
logging.basicConfig(**logBaseConf)

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' : "%(levelname)-8s|%(asctime)s|%(pathname)s,
%(name)s, line %(lineno)s|%(message)s",
'datefmt ': '%d %b %Y, %H:%M:%S',
'filename': 'logtest.log',
'filemode': 'a'
}
logging.basicConfig(**logBaseConf)

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.basicConfig(format="%(pathname)s")
logging.getLogger().critical("yadda")
/usr/local/lib/python2.4/logging/__init__.py
>>>
$ rm logging
$ python
[snip]
>>import logging
logging.basicConfig(format="%(pathname)s")
logging.getLogger().critical("yadda")
<stdin>

Peter

Dec 13 '06 #3

sim.sim wrote:
Hi, i've check documentation, and found that logging.basicConfig 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.getLogger("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.FileHandler(fileName)
iHandler.setFormatter(
logging.Formatter("%(levelname)-8s|%(asctime)s|%(pathname)s,%(name)s,
line %(lineno)s|%(message)s") )

iLog = logging.getLogger(logName)
iLog.addHandler(iHandler)
iLog.setLevel(logging.DEBUG)

iLog.info('hello logging')

it gives me:

INFO |2006-12-13 19:57:33,575|test.py,LOG, line 12|hello logging
On 13 Dec., 19:02, "Tekkaman" <simone....@gmail.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' : "%(levelname)-8s|%(asctime)s|%(pathname)s,
%(name)s, line %(lineno)s|%(message)s",
'datefmt ': '%d %b %Y, %H:%M:%S',
'filename': 'logtest.log',
'filemode': 'a'
}
logging.basicConfig(**logBaseConf)

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.basicConfig(format="%(pathname)s")
logging.getLogger().critical("yadda")
/usr/local/lib/python2.4/logging/__init__.py
>>
$ rm logging
$ python
[snip]
>import logging
logging.basicConfig(format="%(pathname)s")
logging.getLogger().critical("yadda")
<stdin>

Peter
Dec 14 '06 #5
Tekkaman wrote:
Thanks for the hint, but it's not a symlink
What does logging._srcfile contain? Should be
>>import logging
logging._srcfile
'/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._srcfile contain? Should be
>import logging
logging._srcfile
'/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._srcfile contain? Should be
>>import logging
logging._srcfile
'/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._srcfile contain? Should be

import logging
logging._srcfile
'/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._srcfile contain? Should be

import logging
logging._srcfile
'/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
Tekkaman wrote:
lib is a symlink to lib64
So my initial diagnosis was correct. Unfortunately I can no longer recommend
that you remove the symlink...

Putting /usr/lib64/python2.4 as the first entry into your

PYTHONPATH

environment variable might fix the problem (the idea is
that /usr/lib64/python2.4 precedes /usr/lib/python2.4 in sys.path and is
therefore used for the import of the logging package).

Peter
Dec 14 '06 #11


On Dec 14, 6:41 pm, Peter Otten <__pete...@web.dewrote:
Tekkaman wrote:
>lib is a symlink to lib64
So my initial diagnosis was correct. Unfortunately I can no longer recommend
that you remove the symlink...
Yes. What I really meant in my first reply was "it's not a symlink in
the script's own directory": I didn't suspect that a symlink at any
level in the path between the script and the logging module would break
findCaller().
Putting /usr/lib64/python2.4 as the first entry into your

PYTHONPATH

environment variable might fix the problem (the idea is
that /usr/lib64/python2.4 precedes /usr/lib/python2.4 in sys.path and is
therefore used for the import of the logging package).
Thanks, I'll check it out. Anyway, since this is a hack, you think this
behaviour should be reported as a bug?
Peter
T.

Dec 15 '06 #12
Tekkaman wrote:
>Putting /usr/lib64/python2.4 as the first entry into your

PYTHONPATH

environment variable might fix the problem (the idea is
that /usr/lib64/python2.4 precedes /usr/lib/python2.4 in sys.path and is
therefore used for the import of the logging package).
Thanks, I'll check it out. Anyway, since this is a hack, you think this
behaviour should be reported as a bug?
Yes, that's a good idea.

Peter

Dec 15 '06 #13

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

Similar topics

0
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...
3
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...
7
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...
15
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
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...
10
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
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...
3
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...
6
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.