Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
829dc51a
Commit
829dc51a
authored
Feb 18, 2005
by
Vinay Sajip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved frame handling for 1.5.2, and now return func from findCaller (not actually used yet)
parent
84df97fd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
9 deletions
+20
-9
Lib/logging/__init__.py
Lib/logging/__init__.py
+20
-9
No files found.
Lib/logging/__init__.py
View file @
829dc51a
...
...
@@ -37,14 +37,14 @@ except ImportError:
__author__
=
"Vinay Sajip <vinay_sajip@red-dove.com>"
__status__
=
"beta"
__version__
=
"0.4.9.6"
__date__
=
"
20 October 2004
"
__date__
=
"
03 February 2005
"
#---------------------------------------------------------------------------
# Miscellaneous module data
#---------------------------------------------------------------------------
#
#_srcfile is used when walking the stack to check when we've got the first
#
_srcfile is used when walking the stack to check when we've got the first
# caller stack frame.
#
if
string
.
lower
(
__file__
[
-
4
:])
in
[
'.pyc'
,
'.pyo'
]:
...
...
@@ -53,12 +53,23 @@ else:
_srcfile
=
__file__
_srcfile
=
os
.
path
.
normcase
(
_srcfile
)
# next bit filched from 1.5.2's inspect.py
def
currentframe
():
"""Return the frame object for the caller's stack frame."""
try
:
raise
'catch me'
except
:
return
sys
.
exc_traceback
.
tb_frame
.
f_back
if
hasattr
(
sys
,
'_getframe'
):
currentframe
=
sys
.
_getframe
# done filching
# _srcfile is only used in conjunction with sys._getframe().
# To provide compatibility with older versions of Python, set _srcfile
# to None if _getframe() is not available; this value will prevent
# findCaller() from being called.
if
not
hasattr
(
sys
,
"_getframe"
):
_srcfile
=
None
#
if not hasattr(sys, "_getframe"):
#
_srcfile = None
#
#_startTime is used as the base when calculating the relative time of events
...
...
@@ -1005,16 +1016,16 @@ class Logger(Filterer):
def
findCaller
(
self
):
"""
Find the stack frame of the caller so that we can note the source
file name
and line number
.
file name
, line number and function name
.
"""
f
=
sys
.
_getframe
(
1
)
f
=
currentframe
().
f_back
while
1
:
co
=
f
.
f_code
filename
=
os
.
path
.
normcase
(
co
.
co_filename
)
if
filename
==
_srcfile
:
f
=
f
.
f_back
continue
return
filename
,
f
.
f_lineno
return
filename
,
f
.
f_lineno
,
co
.
co_name
def
makeRecord
(
self
,
name
,
level
,
fn
,
lno
,
msg
,
args
,
exc_info
):
"""
...
...
@@ -1029,9 +1040,9 @@ class Logger(Filterer):
all the handlers of this logger to handle the record.
"""
if
_srcfile
:
fn
,
lno
=
self
.
findCaller
()
fn
,
lno
,
func
=
self
.
findCaller
()
else
:
fn
,
lno
=
"<unknown file>"
,
0
fn
,
lno
,
func
=
"(unknown file)"
,
0
,
"(unknown function)"
if
exc_info
:
if
type
(
exc_info
)
!=
types
.
TupleType
:
exc_info
=
sys
.
exc_info
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment