Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
63467981
Commit
63467981
authored
Jun 29, 1999
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Began renaming to zLOG.
parent
0e0f0daf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
209 deletions
+2
-209
lib/python/LOG.py
lib/python/LOG.py
+2
-209
No files found.
lib/python/LOG.py
View file @
63467981
...
...
@@ -83,212 +83,5 @@
#
##############################################################################
"""General logging facility
This module attempts to provide a simple programming API for logging
with a pluggable API for defining where log messages should go.
Programmers call the LOG function to log information.
The LOG function, in turn, calls the write_log method to actually write
logging information somewhere. This module provides a very simple
write_log implementation. It is intended that applications main
programs will replace this method with a method more suited to their needs.
The module provides a register_subsystem method that does nothing, but
provides a hook that logging management systems could use to collect information about subsystems being used.
The module defines several standard severities:
BLATHER=-100 -- Somebody shut this app up.
INFO=0 -- For things like startup and shutdown.
PROBLEM=100 -- This isn't causing any immediate problems, but deserves
attention.
WARNING=100 -- A wishy-washy alias for PROBLEM.
ERROR=200 -- This is going to have adverse effects.
PANIC=300 -- We're dead!
Also, looging facilities will normally ignore negative severities.
To plug in a log handler, simply replace the log_write function
with a callable object that takes 5 arguments:
subsystem -- The subsystem generating the message (e.g. ZODB)
severity -- The "severity" of the event. This may be an integer or
a floating point number. Logging back ends may
consider the int() of this valua to be significant.
For example, a backend may consider any severity
whos integer value is WARNING to be a warning.
summary -- A short summary of the event
detail -- A detailed description
error -- A three-element tuple consisting of an error type, value, and
traceback. If provided, then a summary of the error
is added to the detail.
There is a default stupid logging facility that:
- swallows logging information by default,
- outputs to sys.stderr if the environment variable
STUPID_LOG_FILE is set to an empty string, and
- outputs to file if the environment variable
STUPID_LOG_FILE is set to a file name.
"""
import
time
,
sys
,
string
# Standard severities
BLATHER
=-
100
INFO
=
0
PROBLEM
=
WARNING
=
100
ERROR
=
200
PANIC
=
300
def
severity_string
(
severity
,
mapping
=
{
-
100
:
'BLATHER'
,
0
:
'INFO'
,
100
:
'PROBLEM'
,
200
:
'ERROR'
,
300
:
'PANIC'
,
}):
"""Convert a severity code to a string
"""
s
=
int
(
severity
)
if
mapping
.
has_key
(
s
):
s
=
mapping
[
s
]
else
:
s
=
''
return
"%s(%s)"
%
(
s
,
severity
)
def
LOG
(
subsystem
,
severity
,
summary
,
detail
=
''
,
error
=
None
,
reraise
=
None
):
"""Log some information
The required arguments are:
subsystem -- The subsystem generating the message (e.g. ZODB)
severity -- The "severity" of the event. This may be an integer or
a floating point number. Logging back ends may
consider the int() of this valua to be significant.
For example, a backend may consider any severity
whos integer value is WARNING to be a warning.
summary -- A short summary of the event
detail -- A detailed description
error -- A three-element tuple consisting of an error type, value, and
traceback. If provided, then a summary of the error
is added to the detail.
reraise -- If provided with a true value, then the error given by
error is reraised.
"""
log_write
(
subsystem
,
severity
,
summary
,
detail
,
error
)
if
reraise
and
error
:
raise
error
[
0
],
error
[
1
],
error
[
2
]
def
register_subsystem
(
subsystem
):
"""Register a subsystem name
A logging facility might replace this function to collect information about
subsystems used in an application.
"""
def
log_time
():
"""Return a simple time string without spaces suitable for logging
"""
return
(
"%4.4d-%2.2d-%2.2dT%2.2d:%2.2d:%2.2d"
%
time
.
gmtime
(
time
.
time
())[:
6
])
_stupid_dest
=
None
_no_stupid_log
=
[]
def
stupid_log_write
(
subsystem
,
severity
,
summary
,
detail
,
error
):
if
severity
<
0
:
return
global
_stupid_dest
if
_stupid_dest
is
None
:
import
os
if
os
.
environ
.
has_key
(
'STUPID_LOG_FILE'
):
f
=
os
.
environ
[
'STUPID_LOG_FILE'
]
if
f
:
_stupid_dest
=
open
(
f
,
'a'
).
write
else
:
import
sys
_stupid_dest
=
sys
.
stderr
.
write
else
:
_stupid_dest
=
_no_stupid_log
if
_stupid_dest
is
_no_stupid_log
:
return
_stupid_dest
(
"------
\
n
"
"%s %s %s %s
\
n
%s
\
n
"
%
(
log_time
(),
severity_string
(
severity
),
subsystem
,
summary
,
detail
,
)
)
if
error
:
try
:
_stupid_dest
(
format_exception
(
error
[
0
],
error
[
1
],
error
[
2
],
trailer
=
'
\
n
'
,
limit
=
100
))
except
:
_stupid_dest
(
"%s: %s
\
n
"
%
error
[:
2
])
log_write
=
stupid_log_write
format_exception_only
=
None
def
format_exception
(
etype
,
value
,
tb
,
limit
=
None
,
delimiter
=
'
\
n
'
,
header
=
''
,
trailer
=
''
):
global
format_exception_only
if
format_exception_only
is
None
:
import
traceback
format_exception_only
=
traceback
.
format_exception_only
result
=
[
'Traceback (innermost last):'
]
if
header
:
result
.
insert
(
0
,
header
)
if
limit
is
None
:
if
hasattr
(
sys
,
'tracebacklimit'
):
limit
=
sys
.
tracebacklimit
n
=
0
while
tb
is
not
None
and
(
limit
is
None
or
n
<
limit
):
f
=
tb
.
tb_frame
lineno
=
tb
.
tb_lineno
co
=
f
.
f_code
filename
=
co
.
co_filename
name
=
co
.
co_name
locals
=
f
.
f_locals
result
.
append
(
' File %s, line %d, in %s'
%
(
filename
,
lineno
,
name
))
try
:
result
.
append
(
' (Object: %s)'
%
locals
[
co
.
co_varnames
[
0
]].
__name__
)
except
:
pass
try
:
result
.
append
(
' (Info: %s)'
%
str
(
locals
[
'__traceback_info__'
]))
except
:
pass
tb
=
tb
.
tb_next
n
=
n
+
1
result
.
append
(
string
.
join
(
format_exception_only
(
etype
,
value
),
' '
))
if
trailer
:
result
.
append
(
trailer
)
return
string
.
join
(
result
,
delimiter
)
# We've renamed this module to zLOG. This one will dissappear soon.
from
zLOG
import
*
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