473,695 Members | 2,626 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 1967

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
1657
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
2257
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
1954
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
2981
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
3041
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
2665
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
8573
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
6421
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
7582
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
8640
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8582
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
9001
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...
0
7670
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
6496
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
4587
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3018
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2280
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1980
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.