Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZODB
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
ZODB
Commits
f80a5e0b
Commit
f80a5e0b
authored
Nov 22, 2002
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert zLOG changes that proved to be contentious.
parent
88ebcd9b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
94 deletions
+18
-94
src/zLOG/MinimalLogger.py
src/zLOG/MinimalLogger.py
+13
-40
src/zLOG/__init__.py
src/zLOG/__init__.py
+2
-26
src/zLOG/tests/testzLog.py
src/zLOG/tests/testzLog.py
+3
-28
No files found.
src/zLOG/MinimalLogger.py
View file @
f80a5e0b
...
...
@@ -11,10 +11,9 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
__version__
=
'$Revision: 1.2
0
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.2
1
$'
[
11
:
-
2
]
import
os
,
sys
,
time
import
zLOG
try
:
import
textwrap
...
...
@@ -54,39 +53,7 @@ class stupid_log_write:
self
.
initialize
()
def
initialize
(
self
):
path
,
severity
=
self
.
get_environment_info
()
self
.
initialize_log
(
path
,
severity
)
def
initialize_with_config
(
self
,
config
):
"""Initialize logging with information from ZConfig."""
path
,
severity
=
self
.
get_environment_info
()
if
config
is
not
None
:
loginfo
=
config
.
getSection
(
"log"
)
if
loginfo
is
not
None
:
if
path
is
None
:
path
=
loginfo
.
get
(
"path"
)
if
severity
is
None
:
severity
=
loginfo
.
get
(
"level"
)
self
.
initialize_log
(
path
,
severity
)
def
initialize_log
(
self
,
path
,
severity
):
global
_log_level
if
path
is
None
:
_set_log_dest
(
None
)
elif
path
:
_set_log_dest
(
open
(
path
,
'a'
))
else
:
_set_log_dest
(
sys
.
stderr
)
if
severity
:
_log_level
=
zLOG
.
severity
(
severity
)
else
:
_log_level
=
0
# INFO
def
get_environment_info
(
self
):
eget
=
os
.
environ
.
get
# EVENT_LOG_FILE is the preferred envvar, but we accept
...
...
@@ -94,14 +61,21 @@ class stupid_log_write:
path
=
eget
(
'EVENT_LOG_FILE'
)
if
path
is
None
:
path
=
eget
(
'STUPID_LOG_FILE'
)
if
path
is
None
:
_set_log_dest
(
None
)
else
:
if
path
:
_set_log_dest
(
open
(
path
,
'a'
))
else
:
_set_log_dest
(
sys
.
stderr
)
# EVENT_LOG_SEVERITY is the preferred envvar, but we accept
# STUPID_LOG_SEVERITY also
severity
=
eget
(
'EVENT_LOG_SEVERITY'
)
if
severity
is
None
:
severity
=
eget
(
'STUPID_LOG_SEVERITY'
)
return
path
,
severity
severity
=
eget
(
'EVENT_LOG_SEVERITY'
)
or
eget
(
'STUPID_LOG_SEVERITY'
)
if
severity
:
_log_level
=
int
(
severity
)
else
:
_log_level
=
0
# INFO
def
log
(
self
,
subsystem
,
severity
,
summary
,
detail
,
error
):
if
_log_dest
is
None
or
severity
<
_log_level
:
...
...
@@ -138,4 +112,3 @@ class stupid_log_write:
_log
=
stupid_log_write
()
log_write
=
_log
.
log
initialize
=
_log
.
initialize
initialize_with_config
=
_log
.
initialize_with_config
src/zLOG/__init__.py
View file @
f80a5e0b
...
...
@@ -86,10 +86,10 @@ There is a default event logging facility that:
can be overridden with the environment variable EVENT_LOG_SEVERITY
"""
__version__
=
'$Revision: 1.1
1
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.1
2
$'
[
11
:
-
2
]
from
MinimalLogger
import
log_write
,
log_time
,
severity_string
,
\
_set_log_dest
,
initialize
,
initialize_with_config
_set_log_dest
,
initialize
from
traceback
import
format_exception
# Standard severities
...
...
@@ -102,30 +102,6 @@ WARNING = 100
ERROR
=
200
PANIC
=
300
_severity_names
=
{
"trace"
:
-
300
,
"debug"
:
-
200
,
"blather"
:
-
100
,
"info"
:
0
,
"problem"
:
100
,
"warning"
:
100
,
"error"
:
200
,
"panic"
:
300
,
}
def
severity
(
value
):
"""Return the severity level associated with a value.
The value may be an integer, the repr of an integer, or the name
of a well-known severity value (case-insensitive).
"""
try
:
return
int
(
value
)
except
ValueError
:
try
:
return
_severity_names
[
value
.
lower
()]
except
KeyError
:
raise
ValueError
(
"unknown severity value: "
+
repr
(
value
))
def
LOG
(
subsystem
,
severity
,
summary
,
detail
=
''
,
error
=
None
,
reraise
=
None
):
"""Log some information
...
...
src/zLOG/tests/testzLog.py
View file @
f80a5e0b
...
...
@@ -16,10 +16,6 @@ import os
import
sys
import
tempfile
import
unittest
from
cStringIO
import
StringIO
import
ZConfig
import
zLOG
severity_string
=
{
...
...
@@ -64,7 +60,7 @@ class StupidLogTest(unittest.TestCase):
def
setLog
(
self
,
severity
=
0
):
os
.
environ
[
'%s_LOG_FILE'
%
self
.
prefix
]
=
self
.
path
if
severity
is
not
None
:
if
severity
:
os
.
environ
[
'%s_LOG_SEVERITY'
%
self
.
prefix
]
=
str
(
severity
)
self
.
_severity
=
severity
zLOG
.
MinimalLogger
.
_log
.
initialize
()
...
...
@@ -111,19 +107,13 @@ class StupidLogTest(unittest.TestCase):
def
getLogFile
(
self
):
return
open
(
self
.
path
,
'rb'
)
def
checkBasics
(
self
,
severity
=
None
):
self
.
setLog
(
severity
=
severity
)
def
checkBasics
(
self
):
self
.
setLog
()
zLOG
.
LOG
(
"basic"
,
zLOG
.
INFO
,
"summary"
)
f
=
self
.
getLogFile
()
self
.
verifyEntry
(
f
,
subsys
=
"basic"
,
summary
=
"summary"
)
def
checkBasicsNumericSeverity
(
self
):
self
.
checkBasics
(
severity
=
0
)
def
checkBasicsNamedSeverity
(
self
):
self
.
checkBasics
(
severity
=
'info'
)
def
checkDetail
(
self
):
self
.
setLog
()
zLOG
.
LOG
(
"basic"
,
zLOG
.
INFO
,
"xxx"
,
"this is a detail"
)
...
...
@@ -150,24 +140,9 @@ class EventLogTest(StupidLogTest):
""" Test alternate envvars EVENT_LOG_FILE and EVENT_LOG_SEVERITY """
prefix
=
'EVENT'
class
ConfigLogTest
(
StupidLogTest
):
""" Test using a ZConfig section to control logging. """
def
setLog
(
self
,
severity
=
None
):
self
.
_severity
=
severity
text
=
"<Log>
\
n
path %s
\
n
"
%
self
.
path
if
severity
is
not
None
:
text
+=
" level %s
\
n
"
%
severity
text
+=
"</Log>"
sio
=
StringIO
(
text
)
conf
=
ZConfig
.
loadfile
(
sio
)
zLOG
.
MinimalLogger
.
_log
.
initialize_with_config
(
conf
)
def
test_suite
():
suite
=
unittest
.
makeSuite
(
StupidLogTest
,
'check'
)
suite
.
addTest
(
unittest
.
makeSuite
(
EventLogTest
,
'check'
))
suite
.
addTest
(
unittest
.
makeSuite
(
ConfigLogTest
,
'check'
))
return
suite
if
__name__
==
"__main__"
:
...
...
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