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
6877d123
Commit
6877d123
authored
Jun 08, 2006
by
Andreas Jung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed deprecated zLOG module
parent
b00b4b96
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
2 additions
and
832 deletions
+2
-832
doc/CHANGES.txt
doc/CHANGES.txt
+2
-350
lib/python/zLOG/EventLogger.py
lib/python/zLOG/EventLogger.py
+0
-115
lib/python/zLOG/__init__.py
lib/python/zLOG/__init__.py
+0
-156
lib/python/zLOG/tests/__init__.py
lib/python/zLOG/tests/__init__.py
+0
-1
lib/python/zLOG/tests/test_logging.py
lib/python/zLOG/tests/test_logging.py
+0
-62
lib/python/zLOG/tests/testzLog.py
lib/python/zLOG/tests/testzLog.py
+0
-148
No files found.
doc/CHANGES.txt
View file @
6877d123
...
...
@@ -14,361 +14,13 @@ Zope Changes
to the rules for such a type laid out in the Python docs:
http://docs.python.org/api/supporting-cycle-detection.html
Zope 2.10.0 beta 2 (unreleased)
Bugs Fixed
- Acquisition wrappers now correctly proxy __contains__.
- Collector #2116: sequence.sort() did not work properly
locale related comparison methods
Zope 2.10.0 beta 1 (2006/05/30)
Trunk (unreleased)
Restructuring
- Zope 2.10+ now includes site.zcml as part of its instance
creation skel directory. As a consequence Five now requires
this file to exist in every instance. If upgrading a site
from Zope 2.9 to 2.10, you will need to copy site.zcml and
package-includes/ from your installed Zope installation
location (skel/etc/) into the etc/ directory of your upgraded
instance.
The rationale for requiring this new file is to bring Zope 2
instances closer in consistency to Zope 3 instances. It also
eases use of Zope 3 coding techniques in Zope 2 and removes
some confusion when trying to run pure Zope 3 applications on
Zope 2.
- Products.PageTemplates now uses the Zope 3 ZPT implementation
in zope.pagetemplate.
- The TAL package has been deprecated in favour of the TAL
engine from zope.tal.
- Products.PageTemplates.TALES has been deprecated in favour of
the TALES engine from zope.tales.
- ZTUtils.Iterator has been deprecated in favour of the TALES
iterator implementation in zope.tales.tales.
- ZCatalog: removed manage_deleteIndex(), manage_delColumns()
which were deprecated since Zope 2.4
- deprecated the zLOG module. Use Pythons 'logging' module instead.
- replaced all zLOG occurences (expect the zLOG module itself) with
the 'logging' module
- PluginIndexes/TextIndex is deprecated. Use ZCTextIndex instead
- the 'StructuredText' module is deprecated. Use zope.structuredtext
instead
- removed ZopeTutorial (Elvis is now really dead)
- ZClasses are deprecated and should no longer be used. In addition
any code related to the ZClasses (re)distribution mechanism is
removed.
- ZGadyFlyDA/Gadfly is deprecated
- deprecated OFS.content_types (to be removed in Zope 2.11) and
replaced all occurences with zope.app.content_types
- OFS.content_types: moved code to zope.app.content_types and added
method aliases
- Using FastCGI is offically deprecated.
- removed zLOG module which was deprecated since Zope 2.9
Features added
- Included Zope 3.3 and corresponding Five 1.5 release.
- There is now a default favicon.ico.
- Experimental WSGI and Twisted support for http.
Zope now has a WSGI interface for integration with other
web-servers than ZServer. Most notably Twisted is supported.
The WSGI application is ZPublisher.WSGIPublisher.publish_module
You can make ZServer use the twisted interface with the
"use-wsgi on" keyword in the http-server section in zope.conf.
You can run Twisted by installing Twisted (2.1 recommended) and
replacing the http-server section with a server section in
zope.conf. It is not possible to run a Twisted server together with
a ZServer at the same time.
<server>
address 8080
type Zope2-HTTP
</server>
WSGI: http://www.python.org/dev/peps/pep-0333/
Twisted: http://twistedmatrix.com/
- The traversal has been refactored to take heed of Zope3s
IPublishTraverse adapter interfaces. The ZCML directives
five:traversable and five:defaultViewable are therefore no
longer needed, as everything now is five:traversable and
five:defaultViewable.
There was a bug in earlier versions of Five that allowed you
to do custom publishing traversal with ITraversable adapters.
This bug has been corrected. Anybody using ITraversable
adapters need to convert them to IPublishTraversal adapters.
- Testing.makerequest: Added an 'environ' argument so
clients can use mappings other than os.environ.
- Updated to Docutils 0.4.0
- reStructuredText: The default value for the 'stylesheet'
property has been changed from 'default.css' to None because
there is no 'default.css' file by default.
- ZReST: rewritten render() method to integrate it smoothly
with Docutils 0.4.0. The default value for the 'stylesheet'
property has been changed from 'default.css' to None because
there is no 'default.css' file by default.
- Added a "clock server" servertype which allows users to
configure methods that should be called periodically as if
they were being called by a remote user agent on one of Zope's
HTTP ports. This is meant to replace wget+cron for some class
of periodic callables.
To use, create a "clock-server" directive section anywhere
in your zope.conf file, like so:
<clock-server>
method /do_stuff
period 60
user admin
password 123
host localhost
</clock-server>
Any number of clock-server sections may be defined within a
single zope.conf. Note that you must specify a
username/password combination with the appropriate level of
access to call the method you've defined. You can omit the
username and password if the method is anonymously callable.
Obviously the password is stored in the clear in the config
file, so you need to protect the config file with filesystem
security if the Zope account is privileged and those who have
filesystem access should not see the password.
Descriptions of the values within the clock-server section
follow::
method -- the traversal path (from the Zope root) to an
executable Zope method (Python Script, external method,
product method, etc). The method must take no arguments or
must obtain its arguments from a query string.
period -- the number of seconds between each clock "tick" (and
thus each call to the above "method"). The lowest number
providable here is typically 30 (this is the asyncore mainloop
"timeout" value).
user -- a zope username.
password -- the password for the zope username provided above.
host -- the hostname passed in via the "Host:" header in the
faux request. Could be useful if you have virtual host rules
set up inside Zope itself.
To make sure the clock is working, examine your Z2.log file. It
should show requests incoming via a "Zope Clock Server"
useragent.
- Added a 'conflict-error-log-level' directive to zope.conf, to set
the level at which conflict errors (which are normally retried
automatically) are logged. The default is 'info'.
- The SiteErrorLog now copies exceptions to the event log by default.
- ObjectManager now has an hasObject method to test presence. This
brings it in line with BTreeFolder.
- Improved logging of ConflictErrors. All conflict errors are
logged at INFO, with counts of how many occurred and how many
were resolved. Tracebacks for all conflicts are logged a DEBUG
level, although these won't help anyone much. If a conflict
error is unresolved, it will now bubble up to error_log and
standard_error_message.
- Use new-style security declarations everywhere possible. This
means remove the use of __ac_permissions__, foo__roles__ and
default__class_init__. A few corner cases can't be converted
because of circular imports.
- Fixed unclear security declarations. Warn when an attempt is
made to have a security declaration on a nonexistent method.
- updated to ZPL 2.1
- interfaces: Added 'Interfaces' tab to basic core objects.
This is a Five feature and only available if the classes are made
five:traversable. It allows to inspect interfaces and to assign
marker interfaces through the ZMI.
- webdav: Added support for the z3 WriteLock interface.
It is no longer necessary to have the WriteLockInterface in the
__implements__ list of lockable objects. All classes inheriting from
LockableItem inherit also the IWriteLock interface. Note that this
enables webdav locking for all subclasses by default even if they
don't specify the WriteLockInterface explicitly.
- App ProductContext: Made registerClass aware of z3 interfaces.
Z2 and z3 interfaces are registered side by side in the same tuple in
Products.meta_types. IFAwareObjectManagers like the ZCatalog work now
with z3 interfaces as well.
- Zope now sends Zope 3 events when objects are added or removed
from standard containers. manage_afterAdd, manage_beforeDelete
and manage_afterClone are now deprecated. See
lib/python/Products/Five/tests/event.txt for details.
- Zope now utilizes ZODB 3.6. It had previously used
ZODB 3.4. As a result, the DBTab package was removed, as
ZODB 3.6 has multidatabase support that makes DBTab
unnecessary.
- Added a 'product-config' section type to zope.conf, allowing
arbitrary key-value mappings. Products can look for such
confgiurations to set product-specific options. Products mwy
also register their own section types, extending the
'zope.product.base' type. (see the example '<product-config>'
section in skel/etc/zope.conf.in for sample usage).
- Collector #1490: Added a new zope.conf option to control the
character set used to encode unicode data that reaches
ZPublisher without any specified encoding.
- AccessControl, Acquisition, App, OFS, webdav, PluginIndexes,
ZCatalog and ZCTextIndex: Added some Zope 3 style interfaces.
This makes the bridged interfaces shipped with Five obsolete.
- ZConfig extension, address now also accepts symbolic port names
from etc/services (unix) or etc\services (win32)
- ZPublisher.HTTPRequest.FileUpload now supports full file
object interface. This means Iterator support was added. (for
line in fileobject: ..., as well as fileobject.next() and
fileobject.xreadlines() ) Collector #1837
- Switched the bundled Zope 3 to release 3.2 and upgraded the
Five product to version 1.3 (see Products/Five/CHANGES.txt).
- The PageTemplate implementation now uses Zope 3 message
catalogs by default for translation. Old-style translation
services such as Localizer or PlacelessTranslationService are
still supported as fall-backs. See Products/Five/doc/i18n.txt
for more information.
- Switched to the new improved test runner from Zope 3. Run
test.py with -h to find out more.
- lib/python/docutils is now a reference to docutils package
from the Zope 3 source tree (to get rid of redundant packages)
Bugs Fixed
- Collector #1447: When editing content on a virtual-hosted zope,
AcceleratedHTTPCacheManager now purges the correct URL.
- When you add roles in manage_access, roles are now stripped of
any leading or trailing spaces.
- Collector #2062: Fix manage_historyCopy, which was broken, and write
tests for it.
- Collector #2061: Fix problems where windows line endings are passed
to restricted code compilers.
- Collector #2051: Applied patch by Yoshinori Okuji to fix some
XML export/import problems, including tests for that feature.
- Collector #2037: fixed broken ACTUAL_URL for '/'
- Missing import of NotFound in webdav.Resource
- Collector #1819: fixed method signature of
MountedObject.SimpleTrailblazer._construct()
- Collector #2019: removed validateValue() from cAccessControl (already
removed in former Zope versions from the AccessControl Python
implementation)
- Collector #1991: ZPublisher did not deal properly with a trailing
%20 in the URL
- zope.app.introspector was not included with the source archive
- Collector #2013: improved XHTML conformance of error messages,
some of which did not close '<p>' tags.
- Collector #2002: fixed broken 'ls -R' functionality (didn't
recurse properly subclasses of OFS.Folder)
- Collector #1992: unified the visible hostnames of the FTP and
HTTP servers
- Collector #1999: fixed broken FTP rename functionality
(RNFR now returns 350 as status code instead 250)
- HTTPResponse: for XML content the encoding specified within
the XML preamble is adjusted to the real encoding of the content
as specified through the 'charset' within the content-type
property.
- Collector #1939: When running as a service, Zope could
potentially collect too much log output filling the NT Event
Log. When that happened, a 'print' during exception handling
would cause an IOError in the restart code causing the service
not to restart automatically.
Problem is that a service/pythonw.exe process *always* has an
invalid sys.stdout. But due to the magic of buffering, small
"print" statements would not fail - but once the file actually
got written to, the error happened. Never a problem when
debugging, as the process has a console, and hence a valid
stdout.
- For content-type HTTP headers starting with 'text/' or 'application/'
the 'charset' field is automatically if not specified by the
application. The 'charset' is determined by the content-type header
specified by the application (if available) or from the
zpublisher_default_encoding value as configured in etc/zope.conf
- Collector #1976: FTP STOR command would load the file being
uploaded in memory. Changed to use a TemporaryFile.
- OFS ObjectManager: Fixed list_imports() to tolerate missing
import directories.
- Collector #1621, 1894: Removed support for use of long-deprecated
'whrandom' module.
- OFS PropertySheets / webdav: Fixed dav__resourcetype.
__dav_collection__ with a false value was overridden by
isAnObjectManager.
- added missing Zope 3 imports: zope.app.intid, zope.app.keyreference,
zope.app.session, zope.contentprovider, zope.viewlet
Other
- AccessControl.User: Use a better __repr__.
- ZSQLMethod.manage_main: Moved the error message that warns of a
non-existing or closed database connection next to the Connection ID
dropdown and present it using red to increase its visibility.
- The ImageFile module has finally been deprecated for good and
will be removed in Zope 2.11. Use App.ImageFile instead.
lib/python/zLOG/EventLogger.py
deleted
100644 → 0
View file @
b00b4b96
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""
A logging module which handles event messages.
This uses Vinay Sajip's PEP 282 logging module.
"""
__version__
=
'$Revision$'
[
11
:
-
2
]
import
logging
import
time
# XXX Defining custom levels needs to move to
# ZConfig.components.logger, I think. It only needs to be done when
# logging configuration is activated (the logger factory is called).
#
# Custom logging levels
CUSTOM_BLATHER
=
15
# Mapping for zLOG.BLATHER
CUSTOM_TRACE
=
5
# Mapping for zLOG.TRACE
logging
.
addLevelName
(
"BLATHER"
,
CUSTOM_BLATHER
)
logging
.
addLevelName
(
"TRACE"
,
CUSTOM_TRACE
)
def
log_write
(
subsystem
,
severity
,
summary
,
detail
,
error
):
level
=
(
zlog_to_pep282_severity_cache_get
(
severity
)
or
zlog_to_pep282_severity
(
severity
))
msg
=
summary
if
detail
:
msg
=
"%s
\
n
%s"
%
(
msg
,
detail
)
logger
=
logging
.
getLogger
(
subsystem
)
# Since the logging module of Python does not allow to pass a
# traceback triple, we need to fake the exception. (See also
# Collector #1234).
if
isinstance
(
error
,
tuple
):
try
:
raise
error
[
0
],
error
[
1
],
error
[
2
]
except
:
pass
logger
.
log
(
level
,
msg
,
exc_info
=
(
error
is
not
None
))
def
severity_string
(
severity
,
mapping
=
{
-
300
:
'TRACE'
,
-
200
:
'DEBUG'
,
-
100
:
'BLATHER'
,
0
:
'INFO'
,
100
:
'PROBLEM'
,
200
:
'ERROR'
,
300
:
'PANIC'
,
}):
"""Convert a severity code to a string."""
s
=
mapping
.
get
(
int
(
severity
),
''
)
return
"%s(%s)"
%
(
s
,
severity
)
def
zlog_to_pep282_severity
(
zlog_severity
):
"""
We map zLOG severities to PEP282 severities here.
This is how they are mapped:
zLOG severity PEP282 severity
------------- ---------------
PANIC (300) FATAL, CRITICAL (50)
ERROR (200) ERROR (40)
WARNING, PROBLEM (100) WARN (30)
INFO (0) INFO (20)
BLATHER (-100) BLATHER (15) [*]
DEBUG (-200) DEBUG (10)
TRACE (-300) TRACE (5) [*]
[*] BLATHER and TRACE are custom logging levels.
"""
sev
=
zlog_severity
if
sev
>=
300
:
return
logging
.
FATAL
if
sev
>=
200
:
return
logging
.
ERROR
if
sev
>=
100
:
return
logging
.
WARN
if
sev
>=
0
:
return
logging
.
INFO
if
sev
>=
-
100
:
return
CUSTOM_BLATHER
if
sev
>=
-
200
:
return
logging
.
DEBUG
return
CUSTOM_TRACE
zlog_to_pep282_severity_cache
=
{}
for
_sev
in
range
(
-
300
,
301
,
100
):
zlog_to_pep282_severity_cache
[
_sev
]
=
zlog_to_pep282_severity
(
_sev
)
zlog_to_pep282_severity_cache_get
=
zlog_to_pep282_severity_cache
.
get
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
.
localtime
()[:
6
])
lib/python/zLOG/__init__.py
deleted
100644 → 0
View file @
b00b4b96
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""General logging facility
Note:
This module exists only for backward compatibility. Any new code
for Zope 2.8 and newer should use the logging module from Python's
standard library directly. zLOG is only an API shim to map existing
use of zLOG onto the standard logging API.
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 log_write method to actually write
logging information somewhere. This module provides a very simple
log_write 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:
TRACE=-300 -- Trace messages
DEBUG=-200 -- Debugging messages
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!
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.
The default logging facility uses Python's logging module as a
back-end; configuration of the logging module must be handled
somewhere else.
"""
import
warnings
from
EventLogger
import
log_write
,
log_time
,
severity_string
from
traceback
import
format_exception
# Standard severities
TRACE
=
-
300
DEBUG
=
-
200
BLATHER
=
-
100
INFO
=
0
PROBLEM
=
100
WARNING
=
100
ERROR
=
200
PANIC
=
300
def
initialize
():
pass
def
set_initializer
(
func
):
"""Set the function used to re-initialize the logs.
This should be called when initialize_from_environment() is not
appropiate.
This does not ensure that the new function gets called; the caller
should do that separately.
"""
pass
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 value 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.
"""
warnings
.
warn
(
'The zLOG package is deprecated and will be removed in '
'Zope 2.11. Use the Python logging module instead.'
,
DeprecationWarning
,
stacklevel
=
2
)
log_write
(
subsystem
,
severity
,
summary
,
detail
,
error
)
if
reraise
and
error
:
raise
error
[
0
],
error
[
1
],
error
[
2
]
_subsystems
=
[]
def
register_subsystem
(
subsystem
):
"""Register a subsystem name
A logging facility might replace this function to collect information about
subsystems used in an application.
"""
_subsystems
.
append
(
subsystem
)
# Most apps interested in logging only want the names below.
__all__
=
[
'LOG'
,
'TRACE'
,
'DEBUG'
,
'BLATHER'
,
'INFO'
,
'PROBLEM'
,
'WARNING'
,
'ERROR'
,
'PANIC'
,
'log_time'
]
lib/python/zLOG/tests/__init__.py
deleted
100644 → 0
View file @
b00b4b96
# nothing to see here
lib/python/zLOG/tests/test_logging.py
deleted
100644 → 0
View file @
b00b4b96
##############################################################################
#
# Copyright (c) 2004 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Tests of the integration with the standard logging package."""
import
logging
import
unittest
from
ZConfig.components.logger.tests.test_logger
import
LoggingTestBase
import
zLOG
from
zLOG.EventLogger
import
log_write
class
CollectingHandler
(
logging
.
Handler
):
def
__init__
(
self
):
logging
.
Handler
.
__init__
(
self
)
self
.
records
=
[]
def
emit
(
self
,
record
):
self
.
records
.
append
(
record
)
class
LoggingIntegrationTestCase
(
LoggingTestBase
):
def
setUp
(
self
):
LoggingTestBase
.
setUp
(
self
)
self
.
handler
=
CollectingHandler
()
self
.
records
=
self
.
handler
.
records
self
.
logger
=
logging
.
getLogger
()
self
.
logger
.
addHandler
(
self
.
handler
)
def
test_log_record
(
self
):
#log_write(subsystem, severity, summary, detail, error)
log_write
(
"sample.subsystem"
,
zLOG
.
WARNING
,
"summary"
,
"detail"
,
None
)
self
.
assertEqual
(
len
(
self
.
records
),
1
)
record
=
self
.
records
[
0
]
self
.
assertEqual
(
record
.
levelno
,
logging
.
WARN
)
self
.
assertEqual
(
record
.
name
,
"sample.subsystem"
)
# Make sure both the message and the detail information appear
# in the text that gets logged:
record
.
msg
.
index
(
"summary"
)
record
.
msg
.
index
(
"detail"
)
def
test_suite
():
return
unittest
.
makeSuite
(
LoggingIntegrationTestCase
)
if
__name__
==
"__main__"
:
unittest
.
main
(
defaultTest
=
"test_suite"
)
lib/python/zLOG/tests/testzLog.py
deleted
100644 → 0
View file @
b00b4b96
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import
os
import
sys
import
tempfile
import
unittest
import
zLOG
import
logging
severity_string
=
{
-
300
:
'TRACE'
,
-
200
:
'DEBUG'
,
-
100
:
'BLATHER'
,
0
:
'INFO'
,
100
:
'PROBLEM'
,
200
:
'ERROR'
,
300
:
'PANIC'
,
}
class
EventLogTest
(
unittest
.
TestCase
):
"""Test zLOG with the default implementation."""
def
setUp
(
self
):
self
.
path
=
tempfile
.
mktemp
()
self
.
_severity
=
0
# Windows cannot remove a file that's open. The logging code
# keeps the log file open, and I can't find an advertised API
# to tell the logger to close a log file. So here we cheat:
# tearDown() will close and remove all the handlers that pop
# into existence after setUp() runs. This breaks into internals,
# but I couldn't find a sane way to do it.
self
.
handlers
=
logging
.
_handlers
.
keys
()
# capture current handlers
def
tearDown
(
self
):
# Close and remove all the handlers that came into existence
# since setUp ran.
for
h
in
logging
.
_handlers
.
keys
():
if
h
not
in
self
.
handlers
:
h
.
close
()
del
logging
.
_handlers
[
h
]
os
.
remove
(
self
.
path
)
zLOG
.
initialize
()
def
setLog
(
self
,
severity
=
0
):
# XXX Need to write new logging initialization code here!
self
.
_severity
=
severity
zLOG
.
initialize
()
def
verifyEntry
(
self
,
f
,
time
=
None
,
subsys
=
None
,
severity
=
None
,
summary
=
None
,
detail
=
None
,
error
=
None
):
# skip to the beginning of next entry
line
=
f
.
readline
().
strip
()
while
line
!=
"------"
:
if
not
line
:
self
.
fail
(
"can't find entry in log file"
)
line
=
f
.
readline
()
line
=
f
.
readline
().
strip
()
_time
,
rest
=
line
.
split
(
" "
,
1
)
if
time
is
not
None
:
self
.
assertEqual
(
_time
,
time
)
if
subsys
is
not
None
:
self
.
assert_
(
rest
.
find
(
subsys
)
!=
-
1
,
"subsystem mismatch"
)
if
severity
is
not
None
and
severity
>=
self
.
_severity
:
s
=
severity_string
[
severity
]
self
.
assert_
(
rest
.
find
(
s
)
!=
-
1
,
"severity mismatch"
)
if
summary
is
not
None
:
self
.
assert_
(
rest
.
find
(
summary
)
!=
-
1
,
"summary mismatch"
)
if
detail
is
not
None
:
line
=
f
.
readline
()
self
.
assert_
(
line
.
find
(
detail
)
!=
-
1
,
"missing detail"
)
if
error
is
not
None
:
line
=
f
.
readline
().
strip
()
self
.
assert_
(
line
.
startswith
(
'Traceback'
),
"missing traceback"
)
last
=
"%s: %s"
%
(
error
[
0
],
error
[
1
])
if
last
.
startswith
(
"exceptions."
):
last
=
last
[
len
(
"exceptions."
):]
while
1
:
line
=
f
.
readline
().
strip
()
if
not
line
:
self
.
fail
(
"couldn't find end of traceback"
)
if
line
==
"------"
:
self
.
fail
(
"couldn't find end of traceback"
)
if
line
==
last
:
break
def
getLogFile
(
self
):
return
open
(
self
.
path
,
'rb'
)
def
checkBasics
(
self
):
self
.
setLog
()
zLOG
.
LOG
(
"basic"
,
zLOG
.
INFO
,
"summary"
)
f
=
self
.
getLogFile
()
try
:
self
.
verifyEntry
(
f
,
subsys
=
"basic"
,
summary
=
"summary"
)
finally
:
f
.
close
()
def
checkDetail
(
self
):
self
.
setLog
()
zLOG
.
LOG
(
"basic"
,
zLOG
.
INFO
,
"xxx"
,
"this is a detail"
)
f
=
self
.
getLogFile
()
try
:
self
.
verifyEntry
(
f
,
subsys
=
"basic"
,
detail
=
"detail"
)
finally
:
f
.
close
()
def
checkError
(
self
):
self
.
setLog
()
try
:
1
/
0
except
ZeroDivisionError
,
err
:
err
=
sys
.
exc_info
()
zLOG
.
LOG
(
"basic"
,
zLOG
.
INFO
,
"summary"
)
zLOG
.
LOG
(
"basic"
,
zLOG
.
ERROR
,
"raised exception"
,
error
=
err
)
f
=
self
.
getLogFile
()
try
:
self
.
verifyEntry
(
f
,
subsys
=
"basic"
,
summary
=
"summary"
)
self
.
verifyEntry
(
f
,
subsys
=
"basic"
,
severity
=
zLOG
.
ERROR
,
error
=
err
)
finally
:
f
.
close
()
def
test_suite
():
return
unittest
.
TestSuite
()
return
unittest
.
makeSuite
(
EventLogTest
,
'check'
)
if
__name__
==
"__main__"
:
loader
=
unittest
.
TestLoader
()
loader
.
testMethodPrefix
=
"check"
unittest
.
main
(
testLoader
=
loader
)
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