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
ff3863cf
Commit
ff3863cf
authored
Apr 22, 2004
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanly separate the debug logging handler from the startup logging handler;
these must be controllable separately
parent
a5da2d31
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
25 deletions
+54
-25
lib/python/Zope/Startup/__init__.py
lib/python/Zope/Startup/__init__.py
+36
-17
lib/python/Zope/Startup/tests/testStarter.py
lib/python/Zope/Startup/tests/testStarter.py
+18
-8
No files found.
lib/python/Zope/Startup/__init__.py
View file @
ff3863cf
...
@@ -82,6 +82,7 @@ class ZopeStarter:
...
@@ -82,6 +82,7 @@ class ZopeStarter:
def
__init__
(
self
,
cfg
):
def
__init__
(
self
,
cfg
):
self
.
cfg
=
cfg
self
.
cfg
=
cfg
self
.
event_logger
=
logging
.
getLogger
()
self
.
event_logger
=
logging
.
getLogger
()
self
.
debug_handler
=
None
# XXX does anyone actually use these three?
# XXX does anyone actually use these three?
...
@@ -159,6 +160,16 @@ class ZopeStarter:
...
@@ -159,6 +160,16 @@ class ZopeStarter:
def
dropPrivileges
(
self
):
def
dropPrivileges
(
self
):
return
dropPrivileges
(
self
.
cfg
)
return
dropPrivileges
(
self
.
cfg
)
def
getLoggingLevel
(
self
):
if
self
.
cfg
.
eventlog
is
None
:
level
=
logging
.
INFO
else
:
# get the lowest handler level. This is the effective level
# level at which which we will spew messages to the console
# during startup.
level
=
self
.
cfg
.
eventlog
.
getLowestHandlerLevel
()
return
level
def
setupConfiguredLoggers
(
self
):
def
setupConfiguredLoggers
(
self
):
if
self
.
cfg
.
zserver_read_only_mode
:
if
self
.
cfg
.
zserver_read_only_mode
:
# no log files written in read only mode
# no log files written in read only mode
...
@@ -171,6 +182,20 @@ class ZopeStarter:
...
@@ -171,6 +182,20 @@ class ZopeStarter:
if
self
.
cfg
.
trace
is
not
None
:
if
self
.
cfg
.
trace
is
not
None
:
self
.
cfg
.
trace
()
self
.
cfg
.
trace
()
def
setupDebugLogging
(
self
):
from
ZConfig.components.logger
import
loghandler
if
self
.
cfg
.
debug_mode
:
formatter
=
logging
.
Formatter
(
"%(asctime)s %(levelname)s %(name)s %(message)s"
,
"%Y-%m-%d %H:%M:%S"
)
self
.
debug_handler
=
loghandler
.
StreamHandler
()
self
.
debug_handler
.
setFormatter
(
formatter
)
self
.
debug_handler
.
setLevel
(
self
.
getLoggingLevel
())
root
=
self
.
event_logger
root
.
addHandler
(
self
.
debug_handler
)
root
.
error
(
"the lowest handler level is: %r"
,
self
.
debug_handler
.
level
)
def
startZope
(
self
):
def
startZope
(
self
):
# Import Zope
# Import Zope
import
Zope
import
Zope
...
@@ -235,6 +260,7 @@ class WindowsZopeStarter(ZopeStarter):
...
@@ -235,6 +260,7 @@ class WindowsZopeStarter(ZopeStarter):
pass
pass
def
setupInitialLogging
(
self
):
def
setupInitialLogging
(
self
):
self
.
setupDebugLogging
()
self
.
setupConfiguredLoggers
()
self
.
setupConfiguredLoggers
()
def
setupFinalLogging
(
self
):
def
setupFinalLogging
(
self
):
...
@@ -250,43 +276,36 @@ class UnixZopeStarter(ZopeStarter):
...
@@ -250,43 +276,36 @@ class UnixZopeStarter(ZopeStarter):
self
.
cfg
.
trace
])
self
.
cfg
.
trace
])
def
setupInitialLogging
(
self
):
def
setupInitialLogging
(
self
):
self
.
setupDebugLogging
()
# set up our initial logging environment (log everything to stderr
# set up our initial logging environment (log everything to stderr
# if we're not in debug mode).
# if we're not in debug mode).
from
ZConfig.components.logger.loghandler
import
StartupHandler
from
ZConfig.components.logger.loghandler
import
StartupHandler
if
self
.
cfg
.
eventlog
is
not
None
:
level
=
self
.
getLoggingLevel
()
# get the lowest handler level. This is the effective level
# level at which which we will spew messages to the console
# during startup.
level
=
self
.
cfg
.
eventlog
.
getLowestHandlerLevel
()
else
:
level
=
logging
.
INFO
self
.
startup_handler
=
StartupHandler
(
sys
.
stderr
)
self
.
startup_handler
.
setLevel
(
level
)
formatter
=
logging
.
Formatter
(
formatter
=
logging
.
Formatter
(
fmt
=
'------
\
n
%(asctime)s %(levelname)s %(name)s %(message)s'
,
fmt
=
'------
\
n
%(asctime)s %(levelname)s %(name)s %(message)s'
,
datefmt
=
'%Y-%m-%dT%H:%M:%S'
)
datefmt
=
'%Y-%m-%dT%H:%M:%S'
)
if
not
self
.
cfg
.
debug_mode
:
self
.
startup_handler
=
StartupHandler
()
# prevent startup messages from going to stderr if we're not
self
.
startup_handler
.
setLevel
(
level
)
# in debug mode
self
.
startup_handler
=
StartupHandler
(
open
(
'/dev/null'
,
'w'
))
self
.
startup_handler
.
setFormatter
(
formatter
)
self
.
startup_handler
.
setFormatter
(
formatter
)
# set up our event logger temporarily with a startup handler only
# set up our event logger temporarily with a startup handler only
self
.
event_logger
.
handlers
=
[]
self
.
event_logger
.
addHandler
(
self
.
startup_handler
)
self
.
event_logger
.
addHandler
(
self
.
startup_handler
)
# set the initial logging level (this will be changed by the
# set the initial logging level (this will be changed by the
# zconfig settings later)
# zconfig settings later)
self
.
event_logger
.
level
=
level
self
.
event_logger
.
setLevel
(
level
)
def
setupFinalLogging
(
self
):
def
setupFinalLogging
(
self
):
if
self
.
startup_handler
in
self
.
event_logger
.
handlers
:
if
self
.
startup_handler
in
self
.
event_logger
.
handlers
:
self
.
event_logger
.
removeHandler
(
self
.
startup_handler
)
self
.
event_logger
.
removeHandler
(
self
.
startup_handler
)
self
.
setupConfiguredLoggers
()
self
.
setupConfiguredLoggers
()
# flush buffered startup messages to event logger
# flush buffered startup messages to event logger
logger
=
logging
.
getLogger
(
'event'
)
if
self
.
debug_handler
is
not
None
:
self
.
startup_handler
.
flushBufferTo
(
logger
)
self
.
event_logger
.
removeHandler
(
self
.
debug_handler
)
self
.
startup_handler
.
flushBufferTo
(
self
.
event_logger
)
if
self
.
debug_handler
is
not
None
:
self
.
event_logger
.
addHandler
(
self
.
debug_handler
)
def
check_python_version
():
def
check_python_version
():
...
...
lib/python/Zope/Startup/tests/testStarter.py
View file @
ff3863cf
...
@@ -21,6 +21,8 @@ import tempfile
...
@@ -21,6 +21,8 @@ import tempfile
import
unittest
import
unittest
import
ZConfig
import
ZConfig
from
ZConfig.components.logger.tests
import
test_logger
import
Zope.Startup
import
Zope.Startup
from
Zope.Startup
import
handlers
from
Zope.Startup
import
handlers
from
Zope.Startup
import
ZopeStarter
,
UnixZopeStarter
from
Zope.Startup
import
ZopeStarter
,
UnixZopeStarter
...
@@ -39,18 +41,18 @@ def getSchema():
...
@@ -39,18 +41,18 @@ def getSchema():
# that come later
# that come later
logger_states
=
{}
logger_states
=
{}
for
name
in
(
'event'
,
'trace'
,
'access'
):
for
name
in
(
None
,
'trace'
,
'access'
):
logger
=
logging
.
getLogger
(
name
)
logger
=
logging
.
getLogger
(
name
)
logger_states
[
name
]
=
{
'level'
:
logger
.
level
,
logger_states
[
name
]
=
{
'level'
:
logger
.
level
,
'propagate'
:
logger
.
propagate
,
'propagate'
:
logger
.
propagate
,
'handlers'
:
logger
.
handlers
,
'handlers'
:
logger
.
handlers
,
'filters'
:
logger
.
filters
}
'filters'
:
logger
.
filters
}
class
ZopeStarterTestCase
(
unittest
.
TestC
ase
):
class
ZopeStarterTestCase
(
test_logger
.
LoggingTestB
ase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
schema
=
getSchema
()
self
.
schema
=
getSchema
()
self
.
original_event_logger
=
logging
.
getLogger
test_logger
.
LoggingTestBase
.
setUp
(
self
)
def
tearDown
(
self
):
def
tearDown
(
self
):
try
:
try
:
...
@@ -58,8 +60,9 @@ class ZopeStarterTestCase(unittest.TestCase):
...
@@ -58,8 +60,9 @@ class ZopeStarterTestCase(unittest.TestCase):
os
.
rmdir
(
TEMPNAME
)
os
.
rmdir
(
TEMPNAME
)
except
:
except
:
pass
pass
test_logger
.
LoggingTestBase
.
tearDown
(
self
)
# reset logger states
# reset logger states
for
name
in
(
'event'
,
'access'
,
'trace'
):
for
name
in
(
None
,
'access'
,
'trace'
):
logger
=
logging
.
getLogger
(
name
)
logger
=
logging
.
getLogger
(
name
)
logger
.
__dict__
.
update
(
logger_states
[
name
])
logger
.
__dict__
.
update
(
logger_states
[
name
])
...
@@ -126,10 +129,14 @@ class ZopeStarterTestCase(unittest.TestCase):
...
@@ -126,10 +129,14 @@ class ZopeStarterTestCase(unittest.TestCase):
# with the lowest level
# with the lowest level
logger
=
logging
.
getLogger
()
logger
=
logging
.
getLogger
()
self
.
assertEqual
(
starter
.
startup_handler
.
level
,
15
)
# 15 is BLATHER
self
.
assertEqual
(
starter
.
startup_handler
.
level
,
15
)
# 15 is BLATHER
self
.
assert
Equal
(
starter
.
startup_handler
,
logger
.
handlers
[
0
]
)
self
.
assert
_
(
starter
.
startup_handler
in
logger
.
handlers
)
self
.
assertEqual
(
logger
.
level
,
15
)
self
.
assertEqual
(
logger
.
level
,
15
)
self
.
assertEqual
(
len
(
logger
.
handlers
),
1
)
# We expect a debug handler and the startup handler:
self
.
failUnlessEqual
(
starter
.
startup_handler
.
stream
,
sys
.
stderr
)
self
.
assertEqual
(
len
(
logger
.
handlers
),
2
)
# XXX need to check that log messages get written to
# sys.stderr, not that the stream identity for the startup
# handler matches
#self.failUnlessEqual(starter.startup_handler.stream, sys.stderr)
conf
=
self
.
load_config_text
(
"""
conf
=
self
.
load_config_text
(
"""
instancehome <<INSTANCE_HOME>>
instancehome <<INSTANCE_HOME>>
debug-mode off
debug-mode off
...
@@ -142,7 +149,10 @@ class ZopeStarterTestCase(unittest.TestCase):
...
@@ -142,7 +149,10 @@ class ZopeStarterTestCase(unittest.TestCase):
</eventlog>"""
)
</eventlog>"""
)
starter
=
UnixZopeStarter
(
conf
)
starter
=
UnixZopeStarter
(
conf
)
starter
.
setupInitialLogging
()
starter
.
setupInitialLogging
()
self
.
failIfEqual
(
starter
.
startup_handler
.
stream
,
sys
.
stderr
)
# XXX need to check that log messages get written to
# sys.stderr, not that the stream identity for the startup
# handler matches
#self.failIfEqual(starter.startup_handler.stream, sys.stderr)
def
testSetupZServerThreads
(
self
):
def
testSetupZServerThreads
(
self
):
conf
=
self
.
load_config_text
(
"""
conf
=
self
.
load_config_text
(
"""
...
...
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