mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-04-22 07:04:44 +00:00
added tracing
git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@2535 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
parent
6679f95e16
commit
c95c4b11d7
1 changed files with 32 additions and 2 deletions
|
|
@ -19,20 +19,50 @@ Logging and debug functions.
|
|||
"""
|
||||
|
||||
# public api
|
||||
__all__ = ["debug", "info", "warn", "error", "critical", "exception", ]
|
||||
__all__ = ["debug", "info", "warn", "error", "critical", "exception",
|
||||
"trace", "is_debug"]
|
||||
|
||||
import logging
|
||||
import traceback
|
||||
import inspect
|
||||
import cStringIO as StringIO
|
||||
import linecache
|
||||
import sys
|
||||
|
||||
# memory leak debugging
|
||||
#import gc
|
||||
#gc.enable()
|
||||
#gc.set_debug(gc.DEBUG_LEAK)
|
||||
|
||||
PRINT_LOCALVARS = False
|
||||
# call tracing
|
||||
|
||||
tracelog = ""
|
||||
|
||||
def trace (log):
|
||||
"""
|
||||
Start tracing of the current thread (and the current thread only).
|
||||
"""
|
||||
global tracelog
|
||||
tracelog = log
|
||||
sys.settrace(_traceit)
|
||||
|
||||
|
||||
def _traceit (frame, event, arg):
|
||||
"""
|
||||
Print current executed line.
|
||||
"""
|
||||
if event == "line":
|
||||
lineno = frame.f_lineno
|
||||
filename = frame.f_globals["__file__"]
|
||||
if filename.endswith(".pyc") or filename.endswith(".pyo"):
|
||||
filename = filename[:-1]
|
||||
name = frame.f_globals["__name__"]
|
||||
line = linecache.getline(filename, lineno)
|
||||
debug(tracelog, "%s:%s: %s", name, lineno, line.rstrip())
|
||||
return _traceit
|
||||
|
||||
|
||||
PRINT_LOCALVARS = False
|
||||
def _stack_format (stack):
|
||||
"""
|
||||
Format a stack trace to a message.
|
||||
|
|
|
|||
Loading…
Reference in a new issue