[issue7869] traceback from logging is unusable.

2010-02-07 Thread R. David Murray

Changes by R. David Murray rdmur...@bitdance.com:


--
nosy: +vinay.sajip
priority:  - normal
stage:  - patch review
type: behavior - feature request
versions:  -Python 2.5

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7869
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7869] traceback from logging is unusable.

2010-02-07 Thread Vinay Sajip

Vinay Sajip vinay_sa...@yahoo.co.uk added the comment:

Fix (slightly modified version of patch) checked into trunk (r78081), thanks 
Inada Naoki!

--
resolution:  - fixed
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7869
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7869] traceback from logging is unusable.

2010-02-06 Thread INADA Naoki

New submission from INADA Naoki songofaca...@gmail.com:

When exception raised in logging, traceback is shown but it doesn't tell
me which logging code cause the error.

$ cat unusable_traceback.py 
import logging
logging.warn('%s %s', 1) # not enough arguments.

$ python unusable_traceback.py 
Traceback (most recent call last):
  File /usr/lib/python2.6/logging/__init__.py, line 768, in emit
msg = self.format(record)
  File /usr/lib/python2.6/logging/__init__.py, line 648, in format
return fmt.format(record)
  File /usr/lib/python2.6/logging/__init__.py, line 436, in format
record.message = record.getMessage()
  File /usr/lib/python2.6/logging/__init__.py, line 306, in getMessage
msg = msg % self.args
TypeError: not enough arguments for format string

--
components: Library (Lib)
messages: 98981
nosy: naoki
severity: normal
status: open
title: traceback from logging is unusable.
type: behavior
versions: Python 2.5, Python 2.6, Python 2.7, Python 3.1, Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7869
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7869] traceback from logging is unusable.

2010-02-06 Thread INADA Naoki

INADA Naoki songofaca...@gmail.com added the comment:

This patch shows filename and lineno.
I can specify my wrong logging code with this patch.

--
keywords: +patch
Added file: http://bugs.python.org/file16164/logging_show_file_and_line.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7869
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Traceback in Logging

2009-01-08 Thread Kottiyath
The issue is that I am on Python 2.4 which doesnt support func name.
I am using filename and lineno now. That does serve the purpose.
Thank you, I had not checked all the parameters.

Regards
K

Vinay Sajip wrote:
 On Jan 6, 4:17 pm, Kottiyath n.kottiy...@gmail.com wrote:
  I dont want the whole traceback. I just wanted to know where the log
  was generated from i.e. which procedure and which line. I have 3/4
  points in many procedures where I encounter a small error (not an
  exception) and want to log it. So having individual names for each
  looks to be somewhat verbose - esp since the application is 10K LOC.
 

 Don't the funcName and lineno arguments in the format string work for
 you?

 (See http://docs.python.org/library/logging.html#id1)

 Regards,

 Vinay Sajip
--
http://mail.python.org/mailman/listinfo/python-list


Re: Traceback in Logging

2009-01-07 Thread Vinay Sajip
On Jan 6, 10:19 pm, Thorsten Kampe thors...@thorstenkampe.de wrote:
 I don't think he's interested in the line number where the logging call
 was issued but where the exception occurred.

Well, he does say all logging and every logging. And, as I
mentioned earlier, there is already support for tracebacks by using
the Logger.exception method in an exception handler.

Regards,

Vinay Sajip

--
http://mail.python.org/mailman/listinfo/python-list


Traceback in Logging

2009-01-06 Thread Kottiyath
Hi all,
   Is it possible to print traceback for all logging?
   I have created something like this:

def trace():
import traceback
return ''.join(traceback.format_stack(limit=4)[1:])

And during every logging, append it -
self.logger.info('Data: %s, kwargs: %s Traceback: %s' %(data,
kwargs, trace()))

--Result--

2009-01-06 18:52:21,483 - test- INFO
--- Data:, kwargs: {}
Traceback:   File C:\test.py, line 48, in success
super(testObj, self).success(reply, **kwargs)
  File C:\test.py, line 87, in success
self.logger.info('Data: %s, kwargs: %s Traceback: %s' %(data,
kwargs, trace()))
  File C:\test.py, line 151, in trace
return ''.join(traceback.format_stack(limit=4)[1:])

This seems somewhat kludgy. Is it possible in logging mechanism itself
to provide traceback as default?

I use Python2.4, so LoggingAdapter is not there too.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Traceback in Logging

2009-01-06 Thread Vinay Sajip
On Jan 6, 1:33 pm, Kottiyath n.kottiy...@gmail.com wrote:
 This seems somewhat kludgy. Is it possible in logging mechanism itself
 to provide traceback as default?


No, because it's not a common use case to print tracebacks for every
logging call. There's support for adding traceback information in
exception handling, via use of the Logger.exception method in the
exception handling code.


 I use Python2.4, so LoggingAdapter is not there too.

If you need LoggingAdapter, you can always copy and paste the relevant
code from Python's SVN repository into your own application.

Regards,

Vinay Sajip
--
http://mail.python.org/mailman/listinfo/python-list


Re: Traceback in Logging

2009-01-06 Thread Kottiyath
I dont want the whole traceback. I just wanted to know where the log
was generated from i.e. which procedure and which line. I have 3/4
points in many procedures where I encounter a small error (not an
exception) and want to log it. So having individual names for each
looks to be somewhat verbose - esp since the application is 10K LOC.

This might be a good item to have in the logging system - along with
time and level, just proc name and the line number.

Thank you for the help.

Regards
K

Vinay Sajip wrote:
 On Jan 6, 1:33 pm, Kottiyath n.kottiy...@gmail.com wrote:
  This seems somewhat kludgy. Is it possible in logging mechanism itself
  to provide traceback as default?
 

 No, because it's not a common use case to print tracebacks for every
 logging call. There's support for adding traceback information in
 exception handling, via use of the Logger.exception method in the
 exception handling code.


  I use Python2.4, so LoggingAdapter is not there too.

 If you need LoggingAdapter, you can always copy and paste the relevant
 code from Python's SVN repository into your own application.

 Regards,

 Vinay Sajip
--
http://mail.python.org/mailman/listinfo/python-list


Re: Traceback in Logging

2009-01-06 Thread skip

Kottiyath I dont want the whole traceback. I just wanted to know where
Kottiyath the log was generated from i.e. which procedure and which
Kottiyath line.

The asyncore standard module has an undocumented compact_traceback()
function:

#!/usr/bin/env python

import asyncore

def f():
1/0

def g():
f()

def h():
g()

try:
h()
except ZeroDivisionError:
print asyncore.compact_traceback()[3]

Output looks like this:

% python f.py
[f.py|module|15] [f.py|h|12] [f.py|g|9] [f.py|f|6]

Might be of interest.

-- 
Skip Montanaro - s...@pobox.com - http://smontanaro.dyndns.org/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Traceback in Logging

2009-01-06 Thread Vinay Sajip
On Jan 6, 4:17 pm, Kottiyath n.kottiy...@gmail.com wrote:
 I dont want the whole traceback. I just wanted to know where the log
 was generated from i.e. which procedure and which line. I have 3/4
 points in many procedures where I encounter a small error (not an
 exception) and want to log it. So having individual names for each
 looks to be somewhat verbose - esp since the application is 10K LOC.


Don't the funcName and lineno arguments in the format string work for
you?

(See http://docs.python.org/library/logging.html#id1)

Regards,

Vinay Sajip
--
http://mail.python.org/mailman/listinfo/python-list


Re: Traceback in Logging

2009-01-06 Thread Thorsten Kampe
* Vinay Sajip (Tue, 6 Jan 2009 11:24:54 -0800 (PST))
 On Jan 6, 4:17 pm, Kottiyath n.kottiy...@gmail.com wrote:
  I dont want the whole traceback. I just wanted to know where the log
  was generated from i.e. which procedure and which line. I have 3/4
  points in many procedures where I encounter a small error (not an
  exception) and want to log it. So having individual names for each
  looks to be somewhat verbose - esp since the application is 10K LOC.
 
 
 Don't the funcName and lineno arguments in the format string work for
 you?
 
 (See http://docs.python.org/library/logging.html#id1)

I don't think he's interested in the line number where the logging call 
was issued but where the exception occurred.

Thorsten
--
http://mail.python.org/mailman/listinfo/python-list