Commit 1182373c authored by Michel Pelletier's avatar Michel Pelletier

moving ZLogger to the Zope package

parent b62e86e2
2.13 master x/poll y/cleanup-__del__ y/profile-fix 4.0a2 4.0a1 2.13.25 2.13.24 2.13.23 2.13.22 2.13.21 2.13.20 2.13.19 2.13.18 2.13.17 2.13.16 2.13.15 2.13.14 2.13.13 2.13.12 2.13.11 2.13.10 2.13.9 2.13.8 2.13.7 2.13.6 2.13.5 2.13.4 2.13.3 2.13.2 2.13.1 2.13.0 2.13.0c1 2.13.0b1 2.13.0a4 2.13.0a3 2.13.0a2 2.13.0a1 2.12.28 2.12.27 2.12.26 2.12.25 2.12.24 2.12.23 2.12.22 2.12.21 2.12.20 2.12.19 2.12.18 2.12.17 2.12.16 2.12.15 2.12.14 2.12.13 2.12.12 2.12.11 2.12.10 2.12.9 2.12.8 2.12.7 2.12.6 2.12.5 2.12.4 2.12.3 2.12.2 2.12.1 2.12.0 2.12.0c1 2.12.0b4 2.12.0b3 2.12.0b2 2.12.0b1 2.12.0a4 2.12.0a3 2.12.0a2 2.12.0a1 2.12-last-fulltree-revision 2.11.8 2.11.7 2.11.6 2.11.5 2.11.4 2.11.3 2.11.2 2.11.1 2.11.0 2.11.0c1 2.11.0b1 2.11.0a1 2.10.13 2.10.12 2.10.11 2.10.10 2.10.9 2.10.8 2.10.7 2.10.6 2.10.5 2.10.4 2.10.3 2.10.2 2.10.2b1 2.10.1 2.10.0 2.10.0c1 2.10.0b2 2.10.0b1 2.9.12 2.9.10 2.9.9 2.9.8 2.9.7 2.9.6 2.9.5 2.9.4 2.9.3 2.9.2 2.9.1 2.9.0 2.9.0b2 2.9.0b1 2.8.12 2.8.11 2.8.10 2.8.9.1 2.8.9 2-8-8 2-8-7 2-8-6 philikon-aq-checkpoint cvs-to-svn-conversion before-merging-console-scripts-branch backups/2.10@68399 backups/2.10-with-ZODB3.8@83153 backups/zope33-port@68354 backups/zodb-blobs-branch@39746 backups/z4-zmi@124419 backups/witsch-zope2.11-with-standard-docutils@83154 backups/witsch-2.10-with-standard-docutils@76342 backups/tyam-unicodeSplitterPatch@104722 backups/tseaver-zope.app_delenda_est@110398 backups/tseaver-retire_zpkg@69009 backups/tseaver-retire_zpkg-2.10@69010 backups/tseaver-no_globals_imports@94459 backups/tseaver-instlib_as_site_dir@110397 backups/tseaver-five-integration-security@110396 backups/tseaver-five-integration-security@29697 backups/tseaver-collector_1774@40462 backups/tseaver-collector_1460@110395 backups/tseaver-clarify_install_docs@110394 backups/tseaver-catalog_getObject_raises@110393 backups/tseaver-2.11-no-z2-interfaces@110391 backups/tseaver-2.8-external_test@110392 backups/tseaver-2.8-external_test@29729 backups/tim-merge-zodb34@29764 backups/tim-2.9-windows-installer@41463 backups/slinkp_1726_zopeundo@40069 backups/slinkp-collector_1895@38740 backups/slinkp-collector_596@40067 backups/slinkp-1447-httpcache-fix-branch@67981 backups/shh-2.11-zopelitelayer@80865 backups/rochael-TM_sortKey@113726 backups/regebro-zopectl_shellfix@67835 backups/regebro-wsgi_refactor@67833 backups/regebro-unittest_docs@67835 backups/regebro-strftime_1127@67835 backups/regebro-issue_1888@67834 backups/philikon-zope32-integration@39849 backups/philikon-local-components@67666 backups/philikon-fix-lookup-priorities@66204 backups/philikon-deprecate-interfaces@68354 backups/jim-move-Zope@29064 backups/hannosch-dtml-vs-accesscontrol@113161 backups/gotcha-processlifetime@113938 backups/gotcha-LP143531@113945 backups/efge-five-events-work@40031 backups/easter-sprint_twistedserver@67155 backups/dc-large_file-branch@28340 backups/dc-bobo_traverse-branch@28330 backups/davisagli-copy-export@123222 backups/chrism-mountpoint@39745 backups/andig-catalog-report@115049 backups/ajung-zpt-strict-unicode@68335 backups/ajung-zpt-integration@68335 backups/ajung-zpt-end-game@68335 backups/ajung-zpt-encoding-fixes@71736 backups/ajung-zcatalog-progress@26609 backups/ajung-translatationservice@30288 backups/ajung-final-zpt-integration@68335 backups/ajung-epi-integration@29916 backups/ajung-2-11-prep-branch@82440 backups/acripps-resourceViewletDirective@75991 backups/Zope-2.9@40221 backups/Zope-2_9-branch@40220 ajung-final-zpt-integration-before-merge-savepoint Zope-2.8.5 Zope-2-8-6 Zope-2-8-4 Zope-2-8-3 Zope-2-8-2 Zope-2-8-1 Zope-2-8-1-b1 Zope-2-8-0 Zope-2-8-0-b2 Zope-2-8-0-b1 Zope-2-8-0-a2 Zope-2-8-0-a1
No related merge requests found
class FileLogger:
""" a File Logger
This is just a stub, FileLogger should be smarter than
stupidFileLogger, but for the moment it's completely brain dead.
"""
def __init__(self):
pass
def __call__(self, sub, sev, sum, det, err):
print 'syslogger %s, %s, %s, %s, %s, %s' % (self, sub, sev, sum, det, err)
import stupidFileLogger
import syslogLogger
from zLOG import *
loggers = (stupidFileLogger.stupidFileLogger(), syslogLogger.syslogLogger(),)
def log_write(subsystem, severity, summary, detail, error):
""" Hook into the logging system
The actual logic to determine what log messages go where will go
here. For now, everything goes to all loggers.
"""
if severity < 0: return
for logger in loggers:
logger(subsystem, severity, summary, detail, error)
##############################################################################
#
# Zope Public License (ZPL) Version 1.0
# -------------------------------------
#
# Copyright (c) Digital Creations. All rights reserved.
#
# This license has been certified as Open Source(tm).
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions in source code must retain the above copyright
# notice, this list of conditions, and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# 3. Digital Creations requests that attribution be given to Zope
# in any manner possible. Zope includes a "Powered by Zope"
# button that is installed by default. While it is not a license
# violation to remove this button, it is requested that the
# attribution remain. A significant investment has been put
# into Zope, and this effort will continue if the Zope community
# continues to grow. This is one way to assure that growth.
#
# 4. All advertising materials and documentation mentioning
# features derived from or use of this software must display
# the following acknowledgement:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# In the event that the product being advertised includes an
# intact Zope distribution (with copyright and license included)
# then this clause is waived.
#
# 5. Names associated with Zope or Digital Creations must not be used to
# endorse or promote products derived from this software without
# prior written permission from Digital Creations.
#
# 6. Modified redistributions of any form whatsoever must retain
# the following acknowledgment:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# Intact (re-)distributions of any official Zope release do not
# require an external acknowledgement.
#
# 7. Modifications are encouraged but must be packaged separately as
# patches to official Zope releases. Distributions that do not
# clearly separate the patches from the original work must be clearly
# labeled as unofficial distributions. Modifications which do not
# carry the name Zope may be packaged in any form, as long as they
# conform to all of the clauses above.
#
#
# Disclaimer
#
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# This software consists of contributions made by Digital Creations and
# many individuals on behalf of Digital Creations. Specific
# attributions are listed in the accompanying credits file.
#
##############################################################################
import ZLogger
import time, sys, string
_stupid_dest=None
_no_stupid_log=[]
format_exception_only=None
# 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)
class stupidFileLogger:
""" a stupid File Logger """
def __init__(self):
pass
def __call__(self, sub, sev, sum, det, err):
stupid_log_write(sub, sev, sum, det, err)
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')
else:
import sys
_stupid_dest=sys.stderr
else:
_stupid_dest=_no_stupid_log
if _stupid_dest is _no_stupid_log: return
_stupid_dest.write(
"------\n"
"%s %s %s %s\n%s"
%
(log_time(),
severity_string(severity),
subsystem,
summary,
detail,
)
)
_stupid_dest.flush()
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])
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)
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])
# -*- Mode: Python; tab-width: 4 -*-
# From: "Samual M. Rushing" <rushing@nightmare.com>
# Date: Mon, 21 Apr 1997 16:10:42 -0500
# ======================================================================
# Copyright 1997 by Sam Rushing
#
# All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose and without fee is hereby
# granted, provided that the above copyright notice appear in all
# copies and that both that copyright notice and this permission
# notice appear in supporting documentation, and that the name of Sam
# Rushing not be used in advertising or publicity pertaining to
# distribution of the software without specific, written prior
# permission.
#
# SAM RUSHING DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
# NO EVENT SHALL SAM RUSHING BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# ======================================================================
"""socket interface to unix syslog.
On Unix, there are usually two ways of getting to syslog: via a
local unix-domain socket, or via the TCP service.
Usually "/dev/log" is the unix domain socket. This may be different
for other systems.
>>> my_client = syslog_client ('/dev/log')
Otherwise, just use the UDP version, port 514.
>>> my_client = syslog_client (('my_log_host', 514))
On win32, you will have to use the UDP version. Note that
you can use this to log to other hosts (and indeed, multiple
hosts).
This module is not a drop-in replacement for the python
<syslog> extension module - the interface is different.
Usage:
>>> c = syslog_client()
>>> c = syslog_client ('/strange/non_standard_log_location')
>>> c = syslog_client (('other_host.com', 514))
>>> c.log ('testing', facility='local0', priority='debug')
"""
# TODO: support named-pipe syslog.
# [see ftp://sunsite.unc.edu/pub/Linux/system/Daemons/syslog-fifo.tar.z]
# from <linux/sys/syslog.h>:
# ===========================================================================
# priorities/facilities are encoded into a single 32-bit quantity, where the
# bottom 3 bits are the priority (0-7) and the top 28 bits are the facility
# (0-big number). Both the priorities and the facilities map roughly
# one-to-one to strings in the syslogd(8) source code. This mapping is
# included in this file.
#
# priorities (these are ordered)
LOG_EMERG = 0 # system is unusable
LOG_ALERT = 1 # action must be taken immediately
LOG_CRIT = 2 # critical conditions
LOG_ERR = 3 # error conditions
LOG_WARNING = 4 # warning conditions
LOG_NOTICE = 5 # normal but significant condition
LOG_INFO = 6 # informational
LOG_DEBUG = 7 # debug-level messages
# facility codes
LOG_KERN = 0 # kernel messages
LOG_USER = 1 # random user-level messages
LOG_MAIL = 2 # mail system
LOG_DAEMON = 3 # system daemons
LOG_AUTH = 4 # security/authorization messages
LOG_SYSLOG = 5 # messages generated internally by syslogd
LOG_LPR = 6 # line printer subsystem
LOG_NEWS = 7 # network news subsystem
LOG_UUCP = 8 # UUCP subsystem
LOG_CRON = 9 # clock daemon
LOG_AUTHPRIV = 10 # security/authorization messages (private)
# other codes through 15 reserved for system use
LOG_LOCAL0 = 16 # reserved for local use
LOG_LOCAL1 = 17 # reserved for local use
LOG_LOCAL2 = 18 # reserved for local use
LOG_LOCAL3 = 19 # reserved for local use
LOG_LOCAL4 = 20 # reserved for local use
LOG_LOCAL5 = 21 # reserved for local use
LOG_LOCAL6 = 22 # reserved for local use
LOG_LOCAL7 = 23 # reserved for local use
priority_names = {
"alert": LOG_ALERT,
"crit": LOG_CRIT,
"debug": LOG_DEBUG,
"emerg": LOG_EMERG,
"err": LOG_ERR,
"error": LOG_ERR, # DEPRECATED
"info": LOG_INFO,
"notice": LOG_NOTICE,
"panic": LOG_EMERG, # DEPRECATED
"warn": LOG_WARNING, # DEPRECATED
"warning": LOG_WARNING,
}
facility_names = {
"auth": LOG_AUTH,
"authpriv": LOG_AUTHPRIV,
"cron": LOG_CRON,
"daemon": LOG_DAEMON,
"kern": LOG_KERN,
"lpr": LOG_LPR,
"mail": LOG_MAIL,
"news": LOG_NEWS,
"security": LOG_AUTH, # DEPRECATED
"syslog": LOG_SYSLOG,
"user": LOG_USER,
"uucp": LOG_UUCP,
"local0": LOG_LOCAL0,
"local1": LOG_LOCAL1,
"local2": LOG_LOCAL2,
"local3": LOG_LOCAL3,
"local4": LOG_LOCAL4,
"local5": LOG_LOCAL5,
"local6": LOG_LOCAL6,
"local7": LOG_LOCAL7,
}
import socket
class syslog_client:
def __init__ (self, address='/dev/log'):
self.address = address
if type (address) == type(''):
self.socket = socket.socket (socket.AF_UNIX, socket.SOCK_STREAM)
self.socket.connect (address)
self.unix = 1
else:
self.socket = socket.socket (socket.AF_INET, socket.SOCK_DGRAM)
self.unix = 0
# curious: when talking to the unix-domain '/dev/log' socket, a
# zero-terminator seems to be required. this string is placed
# into a class variable so that it can be overridden if
# necessary.
log_format_string = '<%d>%s\000'
def log (self, message, facility=LOG_USER, priority=LOG_INFO):
message = self.log_format_string % (
self.encode_priority (facility, priority),
message
)
if self.unix:
self.socket.send (message)
else:
self.socket.sendto (message, self.address)
def encode_priority (self, facility, priority):
if type(facility) == type(''):
facility = facility_names[facility]
if type(priority) == type(''):
priority = priority_names[priority]
return (facility<<3) | priority
def close (self):
if self.unix:
self.socket.close()
from syslog import syslog_client
import os, string
class syslogLogger:
""" a syslog Logger """
def __init__(self):
if os.environ.has_key('ZSYSLOG_SERVER'):
(addr, port) = string.split(os.environ['ZSYSLOG_SERVER'], ':')
self.client = syslog_client((addr, int(port)))
else:
self.client = syslog_client()
def __call__(self, sub, sev, sum, det, err):
self.client.log(sum)
class FileLogger:
""" a File Logger
This is just a stub, FileLogger should be smarter than
stupidFileLogger, but for the moment it's completely brain dead.
"""
def __init__(self):
pass
def __call__(self, sub, sev, sum, det, err):
print 'syslogger %s, %s, %s, %s, %s, %s' % (self, sub, sev, sum, det, err)
import stupidFileLogger
import syslogLogger
from zLOG import *
loggers = (stupidFileLogger.stupidFileLogger(), syslogLogger.syslogLogger(),)
def log_write(subsystem, severity, summary, detail, error):
""" Hook into the logging system
The actual logic to determine what log messages go where will go
here. For now, everything goes to all loggers.
"""
if severity < 0: return
for logger in loggers:
logger(subsystem, severity, summary, detail, error)
##############################################################################
#
# Zope Public License (ZPL) Version 1.0
# -------------------------------------
#
# Copyright (c) Digital Creations. All rights reserved.
#
# This license has been certified as Open Source(tm).
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions in source code must retain the above copyright
# notice, this list of conditions, and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# 3. Digital Creations requests that attribution be given to Zope
# in any manner possible. Zope includes a "Powered by Zope"
# button that is installed by default. While it is not a license
# violation to remove this button, it is requested that the
# attribution remain. A significant investment has been put
# into Zope, and this effort will continue if the Zope community
# continues to grow. This is one way to assure that growth.
#
# 4. All advertising materials and documentation mentioning
# features derived from or use of this software must display
# the following acknowledgement:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# In the event that the product being advertised includes an
# intact Zope distribution (with copyright and license included)
# then this clause is waived.
#
# 5. Names associated with Zope or Digital Creations must not be used to
# endorse or promote products derived from this software without
# prior written permission from Digital Creations.
#
# 6. Modified redistributions of any form whatsoever must retain
# the following acknowledgment:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# Intact (re-)distributions of any official Zope release do not
# require an external acknowledgement.
#
# 7. Modifications are encouraged but must be packaged separately as
# patches to official Zope releases. Distributions that do not
# clearly separate the patches from the original work must be clearly
# labeled as unofficial distributions. Modifications which do not
# carry the name Zope may be packaged in any form, as long as they
# conform to all of the clauses above.
#
#
# Disclaimer
#
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# This software consists of contributions made by Digital Creations and
# many individuals on behalf of Digital Creations. Specific
# attributions are listed in the accompanying credits file.
#
##############################################################################
import ZLogger
import time, sys, string
_stupid_dest=None
_no_stupid_log=[]
format_exception_only=None
# 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)
class stupidFileLogger:
""" a stupid File Logger """
def __init__(self):
pass
def __call__(self, sub, sev, sum, det, err):
stupid_log_write(sub, sev, sum, det, err)
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')
else:
import sys
_stupid_dest=sys.stderr
else:
_stupid_dest=_no_stupid_log
if _stupid_dest is _no_stupid_log: return
_stupid_dest.write(
"------\n"
"%s %s %s %s\n%s"
%
(log_time(),
severity_string(severity),
subsystem,
summary,
detail,
)
)
_stupid_dest.flush()
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])
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)
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])
# -*- Mode: Python; tab-width: 4 -*-
# From: "Samual M. Rushing" <rushing@nightmare.com>
# Date: Mon, 21 Apr 1997 16:10:42 -0500
# ======================================================================
# Copyright 1997 by Sam Rushing
#
# All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose and without fee is hereby
# granted, provided that the above copyright notice appear in all
# copies and that both that copyright notice and this permission
# notice appear in supporting documentation, and that the name of Sam
# Rushing not be used in advertising or publicity pertaining to
# distribution of the software without specific, written prior
# permission.
#
# SAM RUSHING DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
# NO EVENT SHALL SAM RUSHING BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# ======================================================================
"""socket interface to unix syslog.
On Unix, there are usually two ways of getting to syslog: via a
local unix-domain socket, or via the TCP service.
Usually "/dev/log" is the unix domain socket. This may be different
for other systems.
>>> my_client = syslog_client ('/dev/log')
Otherwise, just use the UDP version, port 514.
>>> my_client = syslog_client (('my_log_host', 514))
On win32, you will have to use the UDP version. Note that
you can use this to log to other hosts (and indeed, multiple
hosts).
This module is not a drop-in replacement for the python
<syslog> extension module - the interface is different.
Usage:
>>> c = syslog_client()
>>> c = syslog_client ('/strange/non_standard_log_location')
>>> c = syslog_client (('other_host.com', 514))
>>> c.log ('testing', facility='local0', priority='debug')
"""
# TODO: support named-pipe syslog.
# [see ftp://sunsite.unc.edu/pub/Linux/system/Daemons/syslog-fifo.tar.z]
# from <linux/sys/syslog.h>:
# ===========================================================================
# priorities/facilities are encoded into a single 32-bit quantity, where the
# bottom 3 bits are the priority (0-7) and the top 28 bits are the facility
# (0-big number). Both the priorities and the facilities map roughly
# one-to-one to strings in the syslogd(8) source code. This mapping is
# included in this file.
#
# priorities (these are ordered)
LOG_EMERG = 0 # system is unusable
LOG_ALERT = 1 # action must be taken immediately
LOG_CRIT = 2 # critical conditions
LOG_ERR = 3 # error conditions
LOG_WARNING = 4 # warning conditions
LOG_NOTICE = 5 # normal but significant condition
LOG_INFO = 6 # informational
LOG_DEBUG = 7 # debug-level messages
# facility codes
LOG_KERN = 0 # kernel messages
LOG_USER = 1 # random user-level messages
LOG_MAIL = 2 # mail system
LOG_DAEMON = 3 # system daemons
LOG_AUTH = 4 # security/authorization messages
LOG_SYSLOG = 5 # messages generated internally by syslogd
LOG_LPR = 6 # line printer subsystem
LOG_NEWS = 7 # network news subsystem
LOG_UUCP = 8 # UUCP subsystem
LOG_CRON = 9 # clock daemon
LOG_AUTHPRIV = 10 # security/authorization messages (private)
# other codes through 15 reserved for system use
LOG_LOCAL0 = 16 # reserved for local use
LOG_LOCAL1 = 17 # reserved for local use
LOG_LOCAL2 = 18 # reserved for local use
LOG_LOCAL3 = 19 # reserved for local use
LOG_LOCAL4 = 20 # reserved for local use
LOG_LOCAL5 = 21 # reserved for local use
LOG_LOCAL6 = 22 # reserved for local use
LOG_LOCAL7 = 23 # reserved for local use
priority_names = {
"alert": LOG_ALERT,
"crit": LOG_CRIT,
"debug": LOG_DEBUG,
"emerg": LOG_EMERG,
"err": LOG_ERR,
"error": LOG_ERR, # DEPRECATED
"info": LOG_INFO,
"notice": LOG_NOTICE,
"panic": LOG_EMERG, # DEPRECATED
"warn": LOG_WARNING, # DEPRECATED
"warning": LOG_WARNING,
}
facility_names = {
"auth": LOG_AUTH,
"authpriv": LOG_AUTHPRIV,
"cron": LOG_CRON,
"daemon": LOG_DAEMON,
"kern": LOG_KERN,
"lpr": LOG_LPR,
"mail": LOG_MAIL,
"news": LOG_NEWS,
"security": LOG_AUTH, # DEPRECATED
"syslog": LOG_SYSLOG,
"user": LOG_USER,
"uucp": LOG_UUCP,
"local0": LOG_LOCAL0,
"local1": LOG_LOCAL1,
"local2": LOG_LOCAL2,
"local3": LOG_LOCAL3,
"local4": LOG_LOCAL4,
"local5": LOG_LOCAL5,
"local6": LOG_LOCAL6,
"local7": LOG_LOCAL7,
}
import socket
class syslog_client:
def __init__ (self, address='/dev/log'):
self.address = address
if type (address) == type(''):
self.socket = socket.socket (socket.AF_UNIX, socket.SOCK_STREAM)
self.socket.connect (address)
self.unix = 1
else:
self.socket = socket.socket (socket.AF_INET, socket.SOCK_DGRAM)
self.unix = 0
# curious: when talking to the unix-domain '/dev/log' socket, a
# zero-terminator seems to be required. this string is placed
# into a class variable so that it can be overridden if
# necessary.
log_format_string = '<%d>%s\000'
def log (self, message, facility=LOG_USER, priority=LOG_INFO):
message = self.log_format_string % (
self.encode_priority (facility, priority),
message
)
if self.unix:
self.socket.send (message)
else:
self.socket.sendto (message, self.address)
def encode_priority (self, facility, priority):
if type(facility) == type(''):
facility = facility_names[facility]
if type(priority) == type(''):
priority = priority_names[priority]
return (facility<<3) | priority
def close (self):
if self.unix:
self.socket.close()
from syslog import syslog_client
import os, string
class syslogLogger:
""" a syslog Logger """
def __init__(self):
if os.environ.has_key('ZSYSLOG_SERVER'):
(addr, port) = string.split(os.environ['ZSYSLOG_SERVER'], ':')
self.client = syslog_client((addr, int(port)))
else:
self.client = syslog_client()
def __call__(self, sub, sev, sum, det, err):
self.client.log(sum)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment