mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 18:50:05 +01:00
bitkeeper revision 1.1108.1.8 (40ffc44fV2fs0W-8bRw5B0XcBdmAsw)
Add python 2.3 logging to the tree. Only install if not present. Convert xend to use logging.
This commit is contained in:
1 parent
6d88c800d3
commit
5b14d2aca3
63 files changed
+10896
-63
No files matched your search
@@ -0,0 +1,5 @@
|
||||
import logging
|
||||
|
||||
logging.warning("Hello")
|
||||
logging.error("Still here...")
|
||||
logging.warning("Goodbye")
|
||||
@@ -0,0 +1,60 @@
|
||||
[loggers]
|
||||
keys=root,log02,log03,log04,log05
|
||||
|
||||
[handlers]
|
||||
keys=hand01
|
||||
|
||||
[formatters]
|
||||
keys=form01
|
||||
|
||||
[logger_root]
|
||||
level=WARN
|
||||
propagate=1
|
||||
channel=
|
||||
parent=
|
||||
qualname=(root)
|
||||
handlers=hand01
|
||||
|
||||
[logger_log02]
|
||||
level=CRITICAL
|
||||
propagate=1
|
||||
channel=A
|
||||
parent=(root)
|
||||
qualname=A
|
||||
handlers=
|
||||
|
||||
[logger_log03]
|
||||
level=CRITICAL
|
||||
propagate=1
|
||||
channel=B
|
||||
parent=log02
|
||||
qualname=A.B
|
||||
handlers=
|
||||
|
||||
[logger_log04]
|
||||
level=CRITICAL
|
||||
propagate=1
|
||||
channel=C
|
||||
parent=log03
|
||||
qualname=A.B.C
|
||||
handlers=
|
||||
|
||||
[logger_log05]
|
||||
level=CRITICAL
|
||||
propagate=1
|
||||
channel=D
|
||||
parent=log04
|
||||
qualname=A.B.C.D
|
||||
handlers=
|
||||
|
||||
[handler_hand01]
|
||||
class=StreamHandler
|
||||
level=NOTSET
|
||||
formatter=form01
|
||||
stream=sys.stderr
|
||||
args=(sys.stderr,)
|
||||
|
||||
[formatter_form01]
|
||||
format=critical.ini %(name)s %(levelname)s %(message)s
|
||||
datefmt=
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
[loggers]
|
||||
keys=root,log02,log03,log04,log05
|
||||
|
||||
[handlers]
|
||||
keys=hand01
|
||||
|
||||
[formatters]
|
||||
keys=form01
|
||||
|
||||
[logger_root]
|
||||
level=WARN
|
||||
propagate=1
|
||||
channel=
|
||||
parent=
|
||||
qualname=(root)
|
||||
handlers=hand01
|
||||
|
||||
[logger_log02]
|
||||
level=DEBUG
|
||||
propagate=1
|
||||
channel=A
|
||||
parent=(root)
|
||||
qualname=A
|
||||
handlers=
|
||||
|
||||
[logger_log03]
|
||||
level=DEBUG
|
||||
propagate=1
|
||||
channel=B
|
||||
parent=log02
|
||||
qualname=A.B
|
||||
handlers=
|
||||
|
||||
[logger_log04]
|
||||
level=DEBUG
|
||||
propagate=1
|
||||
channel=C
|
||||
parent=log03
|
||||
qualname=A.B.C
|
||||
handlers=
|
||||
|
||||
[logger_log05]
|
||||
level=DEBUG
|
||||
propagate=1
|
||||
channel=D
|
||||
parent=log04
|
||||
qualname=A.B.C.D
|
||||
handlers=
|
||||
|
||||
[handler_hand01]
|
||||
class=StreamHandler
|
||||
level=NOTSET
|
||||
formatter=form01
|
||||
stream=sys.stderr
|
||||
args=(sys.stderr,)
|
||||
|
||||
[formatter_form01]
|
||||
format=debug.ini %(name)s %(levelname)s %(message)s
|
||||
datefmt=
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
[loggers]
|
||||
keys=root,log02,log03,log04,log05
|
||||
|
||||
[handlers]
|
||||
keys=hand01
|
||||
|
||||
[formatters]
|
||||
keys=form01
|
||||
|
||||
[logger_root]
|
||||
level=WARN
|
||||
propagate=1
|
||||
channel=
|
||||
parent=
|
||||
qualname=(root)
|
||||
handlers=hand01
|
||||
|
||||
[logger_log02]
|
||||
level=ERROR
|
||||
propagate=1
|
||||
channel=A
|
||||
parent=(root)
|
||||
qualname=A
|
||||
handlers=
|
||||
|
||||
[logger_log03]
|
||||
level=ERROR
|
||||
propagate=1
|
||||
channel=B
|
||||
parent=log02
|
||||
qualname=A.B
|
||||
handlers=
|
||||
|
||||
[logger_log04]
|
||||
level=ERROR
|
||||
propagate=1
|
||||
channel=C
|
||||
parent=log03
|
||||
qualname=A.B.C
|
||||
handlers=
|
||||
|
||||
[logger_log05]
|
||||
level=ERROR
|
||||
propagate=1
|
||||
channel=D
|
||||
parent=log04
|
||||
qualname=A.B.C.D
|
||||
handlers=
|
||||
|
||||
[handler_hand01]
|
||||
class=StreamHandler
|
||||
level=NOTSET
|
||||
formatter=form01
|
||||
stream=sys.stderr
|
||||
args=(sys.stderr,)
|
||||
|
||||
[formatter_form01]
|
||||
format=error.ini %(name)s %(levelname)s %(message)s
|
||||
datefmt=
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
|
||||
<event name="root" level="20" filename="log_test9.py" lineno="66">
|
||||
<message>Info index = 90</message>
|
||||
</event>
|
||||
<event name="root" level="20" filename="log_test9.py" lineno="66">
|
||||
<message>Info index = 91</message>
|
||||
</event>
|
||||
<event name="root" level="20" filename="log_test9.py" lineno="66">
|
||||
<message>Info index = 92</message>
|
||||
</event>
|
||||
<event name="root" level="20" filename="log_test9.py" lineno="66">
|
||||
<message>Info index = 93</message>
|
||||
</event>
|
||||
<event name="root" level="20" filename="log_test9.py" lineno="66">
|
||||
<message>Info index = 94</message>
|
||||
</event>
|
||||
<event name="root" level="20" filename="log_test9.py" lineno="66">
|
||||
<message>Info index = 95</message>
|
||||
</event>
|
||||
<event name="root" level="20" filename="log_test9.py" lineno="66">
|
||||
<message>Info index = 96</message>
|
||||
</event>
|
||||
<event name="root" level="20" filename="log_test9.py" lineno="66">
|
||||
<message>Info index = 97</message>
|
||||
</event>
|
||||
<event name="root" level="20" filename="log_test9.py" lineno="66">
|
||||
<message>Info index = 98</message>
|
||||
</event>
|
||||
<event name="root" level="20" filename="log_test9.py" lineno="66">
|
||||
<message>Info index = 99</message>
|
||||
</event>
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2001-2002 by Vinay Sajip. 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 Vinay Sajip
|
||||
# not be used in advertising or publicity pertaining to distribution
|
||||
# of the software without specific, written prior permission.
|
||||
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
# VINAY SAJIP 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.
|
||||
#
|
||||
# This file is part of the Python logging distribution. See
|
||||
# http://www.red-dove.com/python_logging.html
|
||||
#
|
||||
"""Test harness for the logging module. Run all tests.
|
||||
|
||||
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
|
||||
"""
|
||||
|
||||
import os, sys, logging, threading, time
|
||||
|
||||
BANNER = "-- %-10s %-6s --------------------------------------------------------\n"
|
||||
|
||||
def banner(nm, typ):
|
||||
sep = BANNER % (nm, typ)
|
||||
sys.stdout.write(sep)
|
||||
sys.stdout.flush()
|
||||
sys.stderr.write(sep)
|
||||
sys.stderr.flush()
|
||||
|
||||
def main():
|
||||
oldout = sys.stdout
|
||||
olderr = sys.stderr
|
||||
sys.stdout = open("stdout.log", "w")
|
||||
sys.stderr = open("stderr.log", "w")
|
||||
logging.basicConfig()
|
||||
root = logging.getLogger("")
|
||||
hdlr0 = root.handlers[0]
|
||||
#Set up servers
|
||||
import logrecv
|
||||
threads = []
|
||||
tcpserver = logrecv.LogRecordSocketReceiver()
|
||||
tcpserver.logname = ""
|
||||
threads.append(threading.Thread(target=logrecv.runTCP, args=(tcpserver,)))
|
||||
udpserver = logrecv.LogRecordDatagramReceiver()
|
||||
udpserver.logname = ""
|
||||
threads.append(threading.Thread(target=logrecv.runUDP, args=(udpserver,)))
|
||||
httpserver = logrecv.LogRecordHTTPReceiver()
|
||||
httpserver.logname = ""
|
||||
threads.append(threading.Thread(target=logrecv.runHTTP, args=(httpserver,)))
|
||||
soapserver = None
|
||||
if logrecv.SOAPServer:
|
||||
soapserver = logrecv.SOAPServer()
|
||||
soapserver.modules = (sys.modules["logrecv"],)
|
||||
soapserver.logname = ""
|
||||
threads.append(threading.Thread(target=logrecv.runSOAP, args=(soapserver,)))
|
||||
|
||||
for thread in threads:
|
||||
thread.start()
|
||||
try:
|
||||
import log_test0
|
||||
banner("log_test0", "begin")
|
||||
log_test0.main()
|
||||
banner("log_test0", "end")
|
||||
try:
|
||||
import log_test1
|
||||
banner("log_test1", "begin")
|
||||
log_test1.main()
|
||||
banner("log_test1", "end")
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
import log_test2
|
||||
banner("log_test2", "begin")
|
||||
log_test2.main()
|
||||
banner("log_test2", "end")
|
||||
time.sleep(3)
|
||||
|
||||
#Skip 3 as it tests fileConfig
|
||||
|
||||
banner("log_test4", "begin")
|
||||
import log_test4
|
||||
banner("log_test4", "end")
|
||||
|
||||
#Skip 5 as it tests SMTPHandler, can't easily check results automatically
|
||||
|
||||
#Skip 6 as it tests NTEventLogHandler, can't easily check results automatically
|
||||
|
||||
banner("log_test7", "begin")
|
||||
root.removeHandler(hdlr0)
|
||||
import log_test7
|
||||
root.addHandler(hdlr0)
|
||||
banner("log_test7", "end")
|
||||
|
||||
banner("log_test8", "begin")
|
||||
import log_test8
|
||||
root.removeHandler(hdlr0)
|
||||
log_test8.main()
|
||||
root.addHandler(hdlr0)
|
||||
banner("log_test8", "end")
|
||||
|
||||
banner("log_test9", "begin")
|
||||
import log_test9
|
||||
root.removeHandler(hdlr0)
|
||||
log_test9.main()
|
||||
root.addHandler(hdlr0)
|
||||
banner("log_test9", "end")
|
||||
|
||||
banner("log_test10", "begin")
|
||||
import log_test10
|
||||
log_test10.main()
|
||||
banner("log_test10", "end")
|
||||
|
||||
#Skip 11 as it tests SMTPHandler, can't easily check results automatically
|
||||
|
||||
import log_test12
|
||||
banner("log_test12", "begin")
|
||||
log_test12.main()
|
||||
banner("log_test12", "end")
|
||||
|
||||
import log_test13
|
||||
banner("log_test13", "begin")
|
||||
log_test13.main()
|
||||
banner("log_test13", "end")
|
||||
|
||||
import log_test15
|
||||
banner("log_test15", "begin")
|
||||
log_test15.test(log_test15.FILTER)
|
||||
banner("log_test15", "end")
|
||||
|
||||
time.sleep(3)
|
||||
|
||||
finally:
|
||||
#shut down servers
|
||||
olderr.write("Tidying up...")
|
||||
tcpserver.abort = 1
|
||||
udpserver.abort = 1
|
||||
httpserver.abort = 1
|
||||
if soapserver:
|
||||
soapserver.abort = 1
|
||||
for thread in threads:
|
||||
thread.join()
|
||||
sys.stdout.close()
|
||||
sys.stdout = oldout
|
||||
#don't close this, as hdlr0 references it. hdlr0 will be closed at application exit
|
||||
#sys.stderr.close()
|
||||
sys.stderr = olderr
|
||||
print "Test run completed."
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2001-2002 by Vinay Sajip. 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 Vinay Sajip
|
||||
# not be used in advertising or publicity pertaining to distribution
|
||||
# of the software without specific, written prior permission.
|
||||
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
# VINAY SAJIP 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.
|
||||
#
|
||||
# This file is part of the Python logging distribution. See
|
||||
# http://www.red-dove.com/python_logging.html
|
||||
#
|
||||
"""Test harness for the logging module. A basic test of levels.
|
||||
|
||||
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
|
||||
"""
|
||||
|
||||
import logging
|
||||
msgcount = 0
|
||||
|
||||
def nextmessage():
|
||||
global msgcount
|
||||
rv = "Message %d" % msgcount
|
||||
msgcount = msgcount + 1
|
||||
return rv
|
||||
|
||||
def main():
|
||||
logging.basicConfig()
|
||||
logging.getLogger("").setLevel(logging.DEBUG)
|
||||
ERR = logging.getLogger("ERR")
|
||||
ERR.setLevel(logging.ERROR)
|
||||
INF = logging.getLogger("INF")
|
||||
INF.setLevel(logging.INFO)
|
||||
INF_ERR = logging.getLogger("INF.ERR")
|
||||
INF_ERR.setLevel(logging.ERROR)
|
||||
DEB = logging.getLogger("DEB")
|
||||
DEB.setLevel(logging.DEBUG)
|
||||
|
||||
INF_UNDEF = logging.getLogger("INF.UNDEF")
|
||||
INF_ERR_UNDEF = logging.getLogger("INF.ERR.UNDEF")
|
||||
UNDEF = logging.getLogger("UNDEF")
|
||||
|
||||
GRANDCHILD = logging.getLogger("INF.BADPARENT.UNDEF")
|
||||
CHILD = logging.getLogger("INF.BADPARENT")
|
||||
|
||||
#These should log
|
||||
ERR.log(logging.CRITICAL, nextmessage())
|
||||
ERR.error(nextmessage())
|
||||
|
||||
INF.log(logging.CRITICAL, nextmessage())
|
||||
INF.error(nextmessage())
|
||||
INF.warning(nextmessage())
|
||||
INF.info(nextmessage())
|
||||
|
||||
INF_UNDEF.log(logging.CRITICAL, nextmessage())
|
||||
INF_UNDEF.error(nextmessage())
|
||||
INF_UNDEF.warning(nextmessage())
|
||||
INF_UNDEF.info(nextmessage())
|
||||
|
||||
INF_ERR.log(logging.CRITICAL, nextmessage())
|
||||
INF_ERR.error(nextmessage())
|
||||
|
||||
INF_ERR_UNDEF.log(logging.CRITICAL, nextmessage())
|
||||
INF_ERR_UNDEF.error(nextmessage())
|
||||
|
||||
DEB.log(logging.CRITICAL, nextmessage())
|
||||
DEB.error(nextmessage())
|
||||
DEB.warning(nextmessage())
|
||||
DEB.info(nextmessage())
|
||||
DEB.debug(nextmessage())
|
||||
|
||||
UNDEF.log(logging.CRITICAL, nextmessage())
|
||||
UNDEF.error(nextmessage())
|
||||
UNDEF.warning(nextmessage())
|
||||
UNDEF.info(nextmessage())
|
||||
|
||||
GRANDCHILD.log(logging.CRITICAL, nextmessage())
|
||||
CHILD.log(logging.CRITICAL, nextmessage())
|
||||
|
||||
#These should not log
|
||||
ERR.warning(nextmessage())
|
||||
ERR.info(nextmessage())
|
||||
ERR.debug(nextmessage())
|
||||
|
||||
INF.debug(nextmessage())
|
||||
INF_UNDEF.debug(nextmessage())
|
||||
|
||||
INF_ERR.warning(nextmessage())
|
||||
INF_ERR.info(nextmessage())
|
||||
INF_ERR.debug(nextmessage())
|
||||
INF_ERR_UNDEF.warning(nextmessage())
|
||||
INF_ERR_UNDEF.info(nextmessage())
|
||||
INF_ERR_UNDEF.debug(nextmessage())
|
||||
|
||||
INF.info("Messages should bear numbers 0 through 24.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
#print sys.argv[0]
|
||||
args = sys.argv[1:]
|
||||
if "-profile" in args:
|
||||
import profile, pstats
|
||||
args.remove("-profile")
|
||||
statf = "log_test0.pro"
|
||||
profile.run("main()", statf)
|
||||
stats = pstats.Stats(statf)
|
||||
stats.strip_dirs().sort_stats('time').print_stats()
|
||||
else:
|
||||
main()
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2001-2002 by Vinay Sajip. 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 Vinay Sajip
|
||||
# not be used in advertising or publicity pertaining to distribution
|
||||
# of the software without specific, written prior permission.
|
||||
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
# VINAY SAJIP 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.
|
||||
#
|
||||
# This file is part of the Python logging distribution. See
|
||||
# http://www.red-dove.com/python_logging.html
|
||||
#
|
||||
"""Test harness for the logging module. A test showing exception handling and use of SysLogHandler.
|
||||
|
||||
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
|
||||
"""
|
||||
import sys, logging
|
||||
import syslog
|
||||
|
||||
class SLHandler(logging.Handler):
|
||||
def __init__(self, ident, logopt=0, facility=syslog.LOG_USER):
|
||||
logging.Handler.__init__(self)
|
||||
self.ident = ident
|
||||
self.logopt = logopt
|
||||
self.facility = facility
|
||||
self.mappings = {
|
||||
logging.DEBUG: syslog.LOG_DEBUG,
|
||||
logging.INFO: syslog.LOG_INFO,
|
||||
logging.WARNING: syslog.LOG_WARNING,
|
||||
logging.ERROR: syslog.LOG_ERR,
|
||||
logging.CRITICAL: syslog.LOG_CRIT,
|
||||
}
|
||||
|
||||
def encodeLevel(self, level):
|
||||
return self.mappings.get(level, syslog.LOG_INFO)
|
||||
|
||||
def emit(self, record):
|
||||
syslog.openlog(self.ident, self.logopt, self.facility)
|
||||
msg = self.format(record)
|
||||
prio = self.encodeLevel(record.levelno)
|
||||
syslog.syslog(prio, msg)
|
||||
syslog.closelog()
|
||||
|
||||
def config():
|
||||
logging.basicConfig()
|
||||
logging.getLogger("").setLevel(logging.DEBUG)
|
||||
if __name__ == "__main__":
|
||||
fmt = logging.Formatter("%(asctime)s %(filename)s:%(lineno)d %(levelname)-5s - %(message)s")
|
||||
hdlr = logging.FileHandler("tmp.tmp")
|
||||
hdlr.setFormatter(fmt)
|
||||
logging.getLogger("").addHandler(hdlr)
|
||||
else:
|
||||
fmt = None
|
||||
hdlr = SLHandler("log_test1")
|
||||
if fmt:
|
||||
hdlr.setFormatter(fmt)
|
||||
logging.getLogger("").addHandler(hdlr)
|
||||
return hdlr
|
||||
|
||||
def run():
|
||||
logging.info("Starting...")
|
||||
try:
|
||||
print "7" + 4
|
||||
except Exception, e:
|
||||
logging.error("Problem %s (%d)", "ERROR", logging.ERROR, exc_info=1)
|
||||
logging.debug("Problem %s (%d)", "DEBUG", logging.DEBUG, exc_info=1)
|
||||
logging.info("Done.")
|
||||
|
||||
|
||||
def main():
|
||||
hdlr = config()
|
||||
run()
|
||||
logging.getLogger("").removeHandler(hdlr)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2001-2002 by Vinay Sajip. 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 Vinay Sajip
|
||||
# not be used in advertising or publicity pertaining to distribution
|
||||
# of the software without specific, written prior permission.
|
||||
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
# VINAY SAJIP 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.
|
||||
#
|
||||
# This file is part of the Python logging distribution. See
|
||||
# http://www.red-dove.com/python_logging.html
|
||||
#
|
||||
"""Test harness for the logging module. Shows use of a user-defined Logger subclass.
|
||||
|
||||
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
|
||||
"""
|
||||
import sys
|
||||
import locale
|
||||
|
||||
locale.setlocale(locale.LC_ALL, '')
|
||||
|
||||
from logging import *
|
||||
|
||||
LOG_FORMAT = "%(asctime)s %(levelname)-5s %(message)s"
|
||||
DATE_FORMAT = "%x %X"
|
||||
|
||||
class MyLogger(Logger):
|
||||
"""
|
||||
A simple example of a logger extension.
|
||||
"""
|
||||
def debug(self, msg, *args, **kwargs):
|
||||
"""
|
||||
This overridden method passes exception information for DEBUG level calls
|
||||
"""
|
||||
if self.manager.disable >= DEBUG:
|
||||
return
|
||||
if DEBUG >= self.getEffectiveLevel():
|
||||
exc_info = kwargs.get("exc_info", 0)
|
||||
ei = None
|
||||
if exc_info:
|
||||
ei = sys.exc_info()
|
||||
if not ei[1]:
|
||||
ei = None
|
||||
self._log(DEBUG, msg, args, ei)
|
||||
del ei
|
||||
|
||||
class NotALogger:
|
||||
pass
|
||||
|
||||
def config():
|
||||
try:
|
||||
setLoggerClass(NotALogger)
|
||||
except Exception, e:
|
||||
sys.stderr.write("%s\n" % e)
|
||||
setLoggerClass(MyLogger)
|
||||
if __name__ == "__main__":
|
||||
basicConfig()
|
||||
if __name__ == "__main__":
|
||||
getLogger("").handlers[0].setFormatter(Formatter(LOG_FORMAT, DATE_FORMAT))
|
||||
|
||||
def run():
|
||||
getLogger("").setLevel(DEBUG)
|
||||
logger = getLogger("mylogger")
|
||||
logger.info("Starting...")
|
||||
logger.debug("Debug message not in exception handler (no traceback)")
|
||||
logger.info("About to throw exception...")
|
||||
try:
|
||||
print "7" + 4
|
||||
except Exception, e:
|
||||
logger.debug("Debug message inside exception handler (traceback)",exc_info=1)
|
||||
logger.info("Done.")
|
||||
|
||||
def main():
|
||||
config()
|
||||
run()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2001-2002 by Vinay Sajip. 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 Vinay Sajip
|
||||
# not be used in advertising or publicity pertaining to distribution
|
||||
# of the software without specific, written prior permission.
|
||||
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
# VINAY SAJIP 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.
|
||||
#
|
||||
# This file is part of the Python logging distribution. See
|
||||
# http://www.red-dove.com/python_logging.html
|
||||
#
|
||||
"""Test harness for the logging module. Tests BufferingSMTPHandler, an alternative implementation
|
||||
of SMTPHandler.
|
||||
|
||||
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
|
||||
"""
|
||||
import string, logging, logging.handlers
|
||||
|
||||
MAILHOST = 'beta'
|
||||
FROM = 'log_test11@red-dove.com'
|
||||
TO = ['arkadi_renko']
|
||||
SUBJECT = 'Test Logging email from Python logging module (buffering)'
|
||||
|
||||
class BufferingSMTPHandler(logging.handlers.BufferingHandler):
|
||||
def __init__(self, mailhost, fromaddr, toaddrs, subject, capacity):
|
||||
logging.handlers.BufferingHandler.__init__(self, capacity)
|
||||
self.mailhost = mailhost
|
||||
self.mailport = None
|
||||
self.fromaddr = fromaddr
|
||||
self.toaddrs = toaddrs
|
||||
self.subject = subject
|
||||
self.setFormatter(logging.Formatter("%(asctime)s %(levelname)-5s %(message)s"))
|
||||
|
||||
def flush(self):
|
||||
if len(self.buffer) > 0:
|
||||
try:
|
||||
import smtplib
|
||||
port = self.mailport
|
||||
if not port:
|
||||
port = smtplib.SMTP_PORT
|
||||
smtp = smtplib.SMTP(self.mailhost, port)
|
||||
msg = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % (self.fromaddr, string.join(self.toaddrs, ","), self.subject)
|
||||
for record in self.buffer:
|
||||
s = self.format(record)
|
||||
print s
|
||||
msg = msg + s + "\r\n"
|
||||
smtp.sendmail(self.fromaddr, self.toaddrs, msg)
|
||||
smtp.quit()
|
||||
except:
|
||||
self.handleError(None) # no particular record
|
||||
self.buffer = []
|
||||
|
||||
def test():
|
||||
logger = logging.getLogger("")
|
||||
logger.setLevel(logging.DEBUG)
|
||||
logger.addHandler(BufferingSMTPHandler(MAILHOST, FROM, TO, SUBJECT, 10))
|
||||
for i in xrange(102):
|
||||
logger.info("Info index = %d", i)
|
||||
logging.shutdown()
|
||||
|
||||
if __name__ == "__main__":
|
||||
test()
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2001-2002 by Vinay Sajip. 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 Vinay Sajip
|
||||
# not be used in advertising or publicity pertaining to distribution
|
||||
# of the software without specific, written prior permission.
|
||||
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
# VINAY SAJIP 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.
|
||||
#
|
||||
# This file is part of the Python logging distribution. See
|
||||
# http://www.red-dove.com/python_logging.html
|
||||
#
|
||||
"""
|
||||
A test harness for the logging module. Tests HTTPHandler.
|
||||
|
||||
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
|
||||
"""
|
||||
import sys, string, logging, logging.handlers
|
||||
|
||||
def main():
|
||||
import pdb
|
||||
host = "localhost:%d" % logging.handlers.DEFAULT_HTTP_LOGGING_PORT
|
||||
gh = logging.handlers.HTTPHandler(host, '/log', 'GET')
|
||||
ph = logging.handlers.HTTPHandler(host, '/log', 'POST')
|
||||
logger = logging.getLogger("log_test12")
|
||||
logger.propagate = 0
|
||||
logger.addHandler(gh)
|
||||
logger.addHandler(ph)
|
||||
logging.getLogger("").setLevel(logging.DEBUG)
|
||||
logger.info("Jackdaws love my big %s of %s", "sphinx", "quartz")
|
||||
logger.debug("Pack my %s with twelve dozen %s", "box", "liquor jugs")
|
||||
gh.close()
|
||||
ph.close()
|
||||
logger.removeHandler(gh)
|
||||
logger.removeHandler(ph)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2001-2002 by Vinay Sajip. 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 Vinay Sajip
|
||||
# not be used in advertising or publicity pertaining to distribution
|
||||
# of the software without specific, written prior permission.
|
||||
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
# VINAY SAJIP 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.
|
||||
#
|
||||
# This file is part of the Python logging distribution. See
|
||||
# http://www.red-dove.com/python_logging.html
|
||||
#
|
||||
"""
|
||||
A test harness for the logging module. Implements a SOAPHandler class which
|
||||
can be used to form the basis of extended SOAP functionality.
|
||||
|
||||
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
|
||||
"""
|
||||
import string, logging, logging.handlers, types
|
||||
|
||||
SOAP_MESSAGE = """<SOAP-ENV:Envelope
|
||||
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:logging="http://www.red-dove.com/logging"
|
||||
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
|
||||
>
|
||||
<SOAP-ENV:Body>
|
||||
<logging:log>
|
||||
%s
|
||||
</logging:log>
|
||||
</SOAP-ENV:Body>
|
||||
</SOAP-ENV:Envelope>
|
||||
"""
|
||||
|
||||
class SOAPHandler(logging.Handler):
|
||||
"""
|
||||
A class which sends records to a SOAP server.
|
||||
"""
|
||||
def __init__(self, host, url):
|
||||
"""
|
||||
Initialize the instance with the host and the request URL
|
||||
"""
|
||||
logging.Handler.__init__(self)
|
||||
self.host = host
|
||||
self.url = url
|
||||
|
||||
def emit(self, record):
|
||||
"""
|
||||
Send the record to the Web server as a SOAP message
|
||||
"""
|
||||
try:
|
||||
import httplib
|
||||
h = httplib.HTTP(self.host)
|
||||
h.putrequest("POST", self.url)
|
||||
keys = record.__dict__.keys()
|
||||
keys.sort()
|
||||
args = ""
|
||||
for key in keys:
|
||||
v = record.__dict__[key]
|
||||
if type(v) == types.StringType:
|
||||
t = "string"
|
||||
elif (type(v) == types.IntType) or (type(v) == types.LongType):
|
||||
t = "integer"
|
||||
elif type(v) == types.FloatType:
|
||||
t = "float"
|
||||
else:
|
||||
t = "string"
|
||||
args = args + "%12s<logging:%s xsi:type=\"xsd:%s\">%s</logging:%s>\n" % ("",
|
||||
key, t, str(v), key)
|
||||
data = SOAP_MESSAGE % args[:-1]
|
||||
h.putheader("Content-type", "text/plain; charset=\"utf-8\"")
|
||||
h.putheader("Content-length", str(len(data)))
|
||||
h.endheaders()
|
||||
#print data
|
||||
h.send(data)
|
||||
r = h.getreply() #can't do anything with the result
|
||||
f = h.getfile()
|
||||
if f:
|
||||
#print f.read()
|
||||
f.close()
|
||||
except:
|
||||
self.handleError(record)
|
||||
|
||||
def main():
|
||||
sh = SOAPHandler('localhost:%d' % logging.handlers.DEFAULT_SOAP_LOGGING_PORT, '/log')
|
||||
logger = logging.getLogger("log_test13")
|
||||
logging.getLogger("").setLevel(logging.DEBUG)
|
||||
logger.propagate = 0
|
||||
logger.addHandler(sh)
|
||||
logger.info("Jackdaws love my big %s of %s", "sphinx", "quartz")
|
||||
logger.debug("Pack my %s with five dozen %s", "box", "liquor jugs")
|
||||
logger.removeHandler(sh)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2001-2002 by Vinay Sajip. 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 Vinay Sajip
|
||||
# not be used in advertising or publicity pertaining to distribution
|
||||
# of the software without specific, written prior permission.
|
||||
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
# VINAY SAJIP 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.
|
||||
#
|
||||
# This file is part of the Python logging distribution. See
|
||||
# http://www.red-dove.com/python_logging.html
|
||||
#
|
||||
"""
|
||||
A test harness for the logging module. An example handler - DBHandler -
|
||||
which writes to an Python DB API 2.0 data source. You'll need to set this
|
||||
source up before you run the test.
|
||||
|
||||
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
|
||||
"""
|
||||
import sys, string, time, logging
|
||||
|
||||
class DBHandler(logging.Handler):
|
||||
def __init__(self, dsn, uid='', pwd=''):
|
||||
logging.Handler.__init__(self)
|
||||
import mx.ODBC.Windows
|
||||
self.dsn = dsn
|
||||
self.uid = uid
|
||||
self.pwd = pwd
|
||||
self.conn = mx.ODBC.Windows.connect(self.dsn, self.uid, self.pwd)
|
||||
self.SQL = """INSERT INTO Events (
|
||||
Created,
|
||||
RelativeCreated,
|
||||
Name,
|
||||
LogLevel,
|
||||
LevelText,
|
||||
Message,
|
||||
Filename,
|
||||
Pathname,
|
||||
Lineno,
|
||||
Milliseconds,
|
||||
Exception,
|
||||
Thread
|
||||
)
|
||||
VALUES (
|
||||
%(dbtime)s,
|
||||
%(relativeCreated)d,
|
||||
'%(name)s',
|
||||
%(levelno)d,
|
||||
'%(levelname)s',
|
||||
'%(message)s',
|
||||
'%(filename)s',
|
||||
'%(pathname)s',
|
||||
%(lineno)d,
|
||||
%(msecs)d,
|
||||
'%(exc_text)s',
|
||||
'%(thread)s'
|
||||
);
|
||||
"""
|
||||
self.cursor = self.conn.cursor()
|
||||
|
||||
def formatDBTime(self, record):
|
||||
record.dbtime = time.strftime("#%m/%d/%Y#", time.localtime(record.created))
|
||||
|
||||
def emit(self, record):
|
||||
try:
|
||||
#use default formatting
|
||||
self.format(record)
|
||||
#now set the database time up
|
||||
self.formatDBTime(record)
|
||||
if record.exc_info:
|
||||
record.exc_text = logging._defaultFormatter.formatException(record.exc_info)
|
||||
else:
|
||||
record.exc_text = ""
|
||||
sql = self.SQL % record.__dict__
|
||||
self.cursor.execute(sql)
|
||||
self.conn.commit()
|
||||
except:
|
||||
import traceback
|
||||
ei = sys.exc_info()
|
||||
traceback.print_exception(ei[0], ei[1], ei[2], None, sys.stderr)
|
||||
del ei
|
||||
|
||||
def close(self):
|
||||
self.cursor.close()
|
||||
self.conn.close()
|
||||
logging.Handler.close(self)
|
||||
|
||||
dh = DBHandler('Logging')
|
||||
logger = logging.getLogger("")
|
||||
logger.setLevel(logging.DEBUG)
|
||||
logger.addHandler(dh)
|
||||
logger.info("Jackdaws love my big %s of %s", "sphinx", "quartz")
|
||||
logger.debug("Pack my %s with five dozen %s", "box", "liquor jugs")
|
||||
try:
|
||||
import math
|
||||
math.exp(1000)
|
||||
except:
|
||||
logger.exception("Problem with %s", "math.exp")
|
||||
logging.shutdown()
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2001-2002 by Vinay Sajip. 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 Vinay Sajip
|
||||
# not be used in advertising or publicity pertaining to distribution
|
||||
# of the software without specific, written prior permission.
|
||||
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
# VINAY SAJIP 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.
|
||||
#
|
||||
# This file is part of the Python logging distribution. See
|
||||
# http://www.red-dove.com/python_logging.html
|
||||
#
|
||||
"""
|
||||
A test harness for the logging module. Tests Filter.
|
||||
|
||||
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
|
||||
"""
|
||||
|
||||
import sys, logging
|
||||
|
||||
FILTER = "a.b"
|
||||
|
||||
def message(s):
|
||||
sys.stderr.write("%s\n" % s)
|
||||
|
||||
def doLog():
|
||||
logging.getLogger("a").info("Info 1")
|
||||
logging.getLogger("a.b").info("Info 2")
|
||||
logging.getLogger("a.c").info("Info 3")
|
||||
logging.getLogger("a.b.c").info("Info 4")
|
||||
logging.getLogger("a.b.c.d").info("Info 5")
|
||||
logging.getLogger("a.bb.c").info("Info 6")
|
||||
logging.getLogger("b").info("Info 7")
|
||||
logging.getLogger("b.a").info("Info 8")
|
||||
logging.getLogger("c.a.b").info("Info 9")
|
||||
logging.getLogger("a.bb").info("Info 10")
|
||||
|
||||
def test(fs):
|
||||
root = logging.getLogger()
|
||||
root.setLevel(logging.DEBUG)
|
||||
if __name__ == "__main__":
|
||||
hand = logging.StreamHandler()
|
||||
hand.setFormatter(logging.Formatter("%(name)-10s %(message)s"))
|
||||
root.addHandler(hand)
|
||||
else:
|
||||
hand = root.handlers[0]
|
||||
message("Unfiltered...")
|
||||
doLog()
|
||||
message("Filtered with '%s'..." % fs)
|
||||
filt = logging.Filter(fs)
|
||||
hand.addFilter(filt)
|
||||
doLog()
|
||||
hand.removeFilter(filt)
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
if len(sys.argv) > 1:
|
||||
fs = sys.argv[1]
|
||||
else:
|
||||
fs = FILTER
|
||||
test(fs)
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2001-2002 by Vinay Sajip. 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 Vinay Sajip
|
||||
# not be used in advertising or publicity pertaining to distribution
|
||||
# of the software without specific, written prior permission.
|
||||
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
# VINAY SAJIP 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.
|
||||
#
|
||||
# This file is part of the Python logging distribution. See
|
||||
# http://www.red-dove.com/python_logging.html
|
||||
#
|
||||
"""
|
||||
A test harness for the logging module. Tests thread safety.
|
||||
|
||||
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
|
||||
"""
|
||||
|
||||
import logging, logging.handlers, thread, threading, random
|
||||
|
||||
logging.raiseExceptions = 1
|
||||
|
||||
NUM_THREADS = 10
|
||||
LOOP_COUNT = 10000
|
||||
|
||||
LOG_MESSAGES = [
|
||||
(logging.DEBUG, "%3d This is a %s message", "debug"),
|
||||
(logging.INFO, "%3d This is an %s message", "informational"),
|
||||
(logging.WARNING, "%3d This is a %s message", "warning"),
|
||||
(logging.ERROR, "%3d This is an %s message", "error"),
|
||||
(logging.CRITICAL, "%3d This is a %s message", "critical"),
|
||||
]
|
||||
|
||||
LOG_NAMES = ["A", "A.B", "A.B.C", "A.B.C.D"]
|
||||
|
||||
def doLog(num):
|
||||
logger = logging.getLogger('')
|
||||
logger.info("*** thread %s started (%d)", thread.get_ident(), num)
|
||||
for i in xrange(LOOP_COUNT):
|
||||
logger = logging.getLogger(random.choice(LOG_NAMES))
|
||||
a = random.choice(LOG_MESSAGES)
|
||||
args = a[0:2] + (num,) + a[2:]
|
||||
apply(logger.log, args)
|
||||
|
||||
def test():
|
||||
f = logging.Formatter("%(asctime)s %(levelname)-9s %(name)-8s %(thread)5s %(message)s")
|
||||
root = logging.getLogger('')
|
||||
root.setLevel(logging.DEBUG)
|
||||
h = logging.FileHandler('thread.log', 'w')
|
||||
root.addHandler(h)
|
||||
h.setFormatter(f)
|
||||
h = logging.handlers.SocketHandler('localhost', logging.handlers.DEFAULT_TCP_LOGGING_PORT)
|
||||
#h = logging.handlers.DatagramHandler('localhost', logging.handlers.DEFAULT_UDP_LOGGING_PORT)
|
||||
root.addHandler(h)
|
||||
threads = []
|
||||
for i in xrange(NUM_THREADS):
|
||||
threads.append(threading.Thread(target=doLog, args=(len(threads),)))
|
||||
for t in threads:
|
||||
t.start()
|
||||
for t in threads:
|
||||
t.join()
|
||||
|
||||
if __name__ == "__main__":
|
||||
test()
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2001-2002 by Vinay Sajip. 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 Vinay Sajip
|
||||
# not be used in advertising or publicity pertaining to distribution
|
||||
# of the software without specific, written prior permission.
|
||||
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
# VINAY SAJIP 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.
|
||||
#
|
||||
# This file is part of the Python logging distribution. See
|
||||
# http://www.red-dove.com/python_logging.html
|
||||
#
|
||||
"""
|
||||
A test harness for the logging module. Tests thread safety.
|
||||
|
||||
To use as a server, run with no arguments in one process.
|
||||
To use as a client, run with arguments "-client <filename>" where <filename>
|
||||
is the name of a file containing a logging configuration.
|
||||
The example files debug.ini, warn.ini, error.ini and critical.ini are
|
||||
provided to use in the test. They each have a customized message format
|
||||
(prefixed with their name) and the loggers have their levels set to the
|
||||
value implied by their name.
|
||||
|
||||
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
|
||||
"""
|
||||
|
||||
import sys, logging, logging.config, thread, threading, random, time, struct
|
||||
|
||||
NUM_THREADS = 10
|
||||
LOOP_COUNT = 10
|
||||
|
||||
CONFIG_PORT = 9077
|
||||
|
||||
logging.raiseExceptions = 1
|
||||
|
||||
LOG_MESSAGES = [
|
||||
(logging.DEBUG, "%3d This is a %s message", "debug"),
|
||||
(logging.INFO, "%3d This is an %s message", "informational"),
|
||||
(logging.WARNING, "%3d This is a %s message", "warning"),
|
||||
(logging.ERROR, "%3d This is an %s message", "error"),
|
||||
(logging.CRITICAL, "%3d This is a %s message", "critical"),
|
||||
]
|
||||
|
||||
LOG_NAMES = ["A", "A.B", "A.B.C", "A.B.C.D"]
|
||||
|
||||
def doLog(num):
|
||||
logger = logging.getLogger('')
|
||||
logger.setLevel(logging.DEBUG)
|
||||
logger.info("*** thread %s started (%d)", thread.get_ident(), num)
|
||||
for i in xrange(LOOP_COUNT):
|
||||
logger = logging.getLogger(random.choice(LOG_NAMES))
|
||||
a = random.choice(LOG_MESSAGES)
|
||||
args = a[0:2] + (num,) + a[2:]
|
||||
time.sleep(random.random() * 3)
|
||||
apply(logger.log, args)
|
||||
|
||||
def runserver():
|
||||
f = logging.Formatter("%(asctime)s %(levelname)-9s %(name)-8s %(thread)5s %(message)s")
|
||||
root = logging.getLogger('')
|
||||
h = logging.StreamHandler()
|
||||
root.addHandler(h)
|
||||
h.setFormatter(f)
|
||||
threads = []
|
||||
for i in xrange(NUM_THREADS):
|
||||
threads.append(threading.Thread(target=doLog, args=(len(threads),)))
|
||||
threads.append(logging.config.listen(CONFIG_PORT)) #don't use default port
|
||||
for t in threads:
|
||||
t.start()
|
||||
for t in threads[:-1]:
|
||||
t.join()
|
||||
logging.config.stopListening()
|
||||
threads[-1].join()
|
||||
|
||||
def runclient(fname):
|
||||
import socket
|
||||
|
||||
print "configuring with '%s'" % fname
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.connect(('localhost', CONFIG_PORT))
|
||||
f = open(fname, "r")
|
||||
s = f.read()
|
||||
f.close()
|
||||
slen = struct.pack(">L", len(s))
|
||||
s = slen + s
|
||||
sentsofar = 0
|
||||
left = len(s)
|
||||
while left > 0:
|
||||
sent = sock.send(s[sentsofar:])
|
||||
sentsofar = sentsofar + sent
|
||||
left = left - sent
|
||||
sock.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
if "-client" not in sys.argv:
|
||||
runserver()
|
||||
else:
|
||||
sys.argv.remove("-client")
|
||||
if len(sys.argv) > 1:
|
||||
fname = sys.argv[1]
|
||||
else:
|
||||
fname = "warn.ini"
|
||||
runclient(fname)
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2001-2002 by Vinay Sajip. 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 Vinay Sajip
|
||||
# not be used in advertising or publicity pertaining to distribution
|
||||
# of the software without specific, written prior permission.
|
||||
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
# VINAY SAJIP 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.
|
||||
#
|
||||
# This file is part of the Python logging distribution. See
|
||||
# http://www.red-dove.com/python_logging.html
|
||||
#
|
||||
"""
|
||||
A test harness for the logging module. Tests MatchFilter.
|
||||
|
||||
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
|
||||
"""
|
||||
|
||||
import logging, types, string
|
||||
|
||||
class MatchFilter(logging.Filter):
|
||||
def __init__(self, **kwargs):
|
||||
self.dict = kwargs
|
||||
|
||||
def matchOne(self, key, value, record):
|
||||
rv = getattr(record, key)
|
||||
if key != "name":
|
||||
if key not in ["message", "msg"]:
|
||||
return rv == value
|
||||
else:
|
||||
return string.find(str(rv), value) >= 0
|
||||
else:
|
||||
if rv == value:
|
||||
return 1
|
||||
nlen = len(value)
|
||||
if string.find(rv, value, 0, nlen) != 0:
|
||||
return 0
|
||||
if rv[nlen] == ".":
|
||||
return 1
|
||||
|
||||
def matchValue(self, key, record):
|
||||
vl = self.dict [key]
|
||||
if type(vl) != types.ListType:
|
||||
rv = self.matchOne(key, vl, record)
|
||||
else:
|
||||
for v in vl:
|
||||
rv = self.matchOne(key, v, record)
|
||||
if rv:
|
||||
break
|
||||
return rv
|
||||
|
||||
def filter(self, record):
|
||||
rv = 1
|
||||
for k in self.dict.keys():
|
||||
if self.matchValue(k, record):
|
||||
rv = 0
|
||||
break
|
||||
return rv
|
||||
|
||||
def doLog(logger, n):
|
||||
logger.debug("Debug %d" % n)
|
||||
logger.info("Info %d" % n)
|
||||
logger.warning("Warning %d" % n)
|
||||
logger.error("Error %d" % n)
|
||||
logger.critical("Critical %d" % n)
|
||||
|
||||
def test():
|
||||
fmt = logging.Formatter("%(name)-10s %(levelname)-9s %(message)s")
|
||||
hand = logging.StreamHandler()
|
||||
hand.setFormatter(fmt)
|
||||
root = logging.getLogger("")
|
||||
root.setLevel(logging.DEBUG)
|
||||
root.addHandler(hand)
|
||||
loggers = ['A',
|
||||
'A.B',
|
||||
'A.BB',
|
||||
'A.C',
|
||||
'AA.B',
|
||||
'A.B.C',
|
||||
'A.B.C.D',
|
||||
'A.B.C.D.E',
|
||||
'Z.A.B',
|
||||
]
|
||||
filt = MatchFilter(name = ['A.C', 'A.B.C'], #reject these loggers and their children
|
||||
levelno = [logging.WARNING, logging.CRITICAL], #reject these levels,
|
||||
msg = 'bug 2' #reject if this in message
|
||||
)
|
||||
hand.addFilter(filt)
|
||||
for log in loggers:
|
||||
doLog(logging.getLogger(log), loggers.index(log))
|
||||
|
||||
if __name__ == "__main__":
|
||||
test()
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2001-2002 by Vinay Sajip. 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 Vinay Sajip
|
||||
# not be used in advertising or publicity pertaining to distribution
|
||||
# of the software without specific, written prior permission.
|
||||
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
# VINAY SAJIP 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.
|
||||
#
|
||||
# This file is part of the Python logging distribution. See
|
||||
# http://www.red-dove.com/python_logging.html
|
||||
#
|
||||
"""Test harness for the logging module. A basic test of parents.
|
||||
|
||||
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
def main():
|
||||
logging.basicConfig()
|
||||
root = logging.getLogger("")
|
||||
ab = logging.getLogger("a.b")
|
||||
abc = logging.getLogger("a.b.c")
|
||||
root.setLevel(logging.ERROR)
|
||||
ab.setLevel(logging.INFO)
|
||||
abc.info("Info")
|
||||
abc.warning("Warning")
|
||||
abc.error("Error")
|
||||
print "abc = %s" % abc
|
||||
print "abc.parent = %s" % abc.parent
|
||||
print "ab = %s" % ab
|
||||
print "ab.parent = %s" % ab.parent
|
||||
print "root = %s" % root
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
print sys.argv[0]
|
||||
args = sys.argv[1:]
|
||||
if "-profile" in args:
|
||||
import profile, pstats
|
||||
args.remove("-profile")
|
||||
statf = "log_test19.pro"
|
||||
profile.run("main()", statf)
|
||||
stats = pstats.Stats(statf)
|
||||
stats.strip_dirs().sort_stats('time').print_stats()
|
||||
else:
|
||||
main()
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2001-2002 by Vinay Sajip. 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 Vinay Sajip
|
||||
# not be used in advertising or publicity pertaining to distribution
|
||||
# of the software without specific, written prior permission.
|
||||
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
# VINAY SAJIP 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.
|
||||
#
|
||||
# This file is part of the Python logging distribution. See
|
||||
# http://www.red-dove.com/python_logging.html
|
||||
#
|
||||
"""
|
||||
A test harness for the logging module. Tests logger levels and basic Formatter, and logging to
|
||||
sockets.
|
||||
|
||||
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
|
||||
"""
|
||||
|
||||
import logging, logging.handlers, socket
|
||||
|
||||
msgcount = 0
|
||||
|
||||
def nextmessage():
|
||||
global msgcount
|
||||
rv = "Message %d" % msgcount
|
||||
msgcount = msgcount + 1
|
||||
return rv
|
||||
|
||||
def main():
|
||||
logging.basicConfig()
|
||||
logging.getLogger("").setLevel(logging.DEBUG)
|
||||
hdlr = logging.handlers.SocketHandler('localhost', logging.handlers.DEFAULT_TCP_LOGGING_PORT)
|
||||
if __name__ == "__main__":
|
||||
hdlr.setFormatter(logging.Formatter("%(asctime)s %(name)-19s %(levelname)-5s - %(message)s"))
|
||||
logging.getLogger("").addHandler(hdlr)
|
||||
ERR = logging.getLogger("ERR")
|
||||
ERR.setLevel(logging.ERROR)
|
||||
INF = logging.getLogger("INF")
|
||||
INF.setLevel(logging.INFO)
|
||||
INF_ERR = logging.getLogger("INF.ERR")
|
||||
INF_ERR.setLevel(logging.ERROR)
|
||||
DEB = logging.getLogger("DEB")
|
||||
DEB.setLevel(logging.DEBUG)
|
||||
|
||||
INF_UNDEF = logging.getLogger("INF.UNDEF")
|
||||
INF_ERR_UNDEF = logging.getLogger("INF.ERR.UNDEF")
|
||||
UNDEF = logging.getLogger("UNDEF")
|
||||
|
||||
GRANDCHILD = logging.getLogger("INF.BADPARENT.UNDEF")
|
||||
CHILD = logging.getLogger("INF.BADPARENT")
|
||||
|
||||
#These should log
|
||||
ERR.log(logging.CRITICAL, nextmessage())
|
||||
ERR.error(nextmessage())
|
||||
|
||||
INF.log(logging.CRITICAL, nextmessage())
|
||||
INF.error(nextmessage())
|
||||
INF.warning(nextmessage())
|
||||
INF.info(nextmessage())
|
||||
|
||||
INF_UNDEF.log(logging.CRITICAL, nextmessage())
|
||||
INF_UNDEF.error(nextmessage())
|
||||
INF_UNDEF.warning(nextmessage())
|
||||
INF_UNDEF.info(nextmessage())
|
||||
|
||||
INF_ERR.log(logging.CRITICAL, nextmessage())
|
||||
INF_ERR.error(nextmessage())
|
||||
|
||||
INF_ERR_UNDEF.log(logging.CRITICAL, nextmessage())
|
||||
INF_ERR_UNDEF.error(nextmessage())
|
||||
|
||||
DEB.log(logging.CRITICAL, nextmessage())
|
||||
DEB.error(nextmessage())
|
||||
DEB.warning(nextmessage())
|
||||
DEB.info(nextmessage())
|
||||
DEB.debug(nextmessage())
|
||||
|
||||
UNDEF.log(logging.CRITICAL, nextmessage())
|
||||
UNDEF.error(nextmessage())
|
||||
UNDEF.warning(nextmessage())
|
||||
UNDEF.info(nextmessage())
|
||||
|
||||
GRANDCHILD.log(logging.CRITICAL, nextmessage())
|
||||
CHILD.log(logging.CRITICAL, nextmessage())
|
||||
|
||||
#These should not log
|
||||
ERR.warning(nextmessage())
|
||||
ERR.info(nextmessage())
|
||||
ERR.debug(nextmessage())
|
||||
|
||||
INF.debug(nextmessage())
|
||||
INF_UNDEF.debug(nextmessage())
|
||||
|
||||
INF_ERR.warning(nextmessage())
|
||||
INF_ERR.info(nextmessage())
|
||||
INF_ERR.debug(nextmessage())
|
||||
INF_ERR_UNDEF.warning(nextmessage())
|
||||
INF_ERR_UNDEF.info(nextmessage())
|
||||
INF_ERR_UNDEF.debug(nextmessage())
|
||||
|
||||
INF.info("Messages should bear numbers 0 through 24.")
|
||||
hdlr.close()
|
||||
logging.getLogger("").removeHandler(hdlr)
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
except socket.error:
|
||||
print "\nA socket error occurred. Ensure that logrecv.py is running to receive logging requests from this script."
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2001-2002 by Vinay Sajip. 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 Vinay Sajip
|
||||
# not be used in advertising or publicity pertaining to distribution
|
||||
# of the software without specific, written prior permission.
|
||||
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
# VINAY SAJIP 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.
|
||||
#
|
||||
# This file is part of the Python logging distribution. See
|
||||
# http://www.red-dove.com/python_logging.html
|
||||
#
|
||||
"""Test harness for the logging module. Demonstrates the use of custom class
|
||||
instances for messages and filtering based on classes.
|
||||
|
||||
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
class MyClass:
|
||||
def __init__(self, arg1, arg2):
|
||||
self.arg1 = arg1
|
||||
self.arg2 = arg2
|
||||
|
||||
def __str__(self):
|
||||
return "%s, %s" % (self.arg1, self.arg2)
|
||||
|
||||
class MyChildClass(MyClass):
|
||||
pass
|
||||
|
||||
class ClassFilter(logging.Filter):
|
||||
def __init__(self, klass):
|
||||
self.klass = klass
|
||||
|
||||
def filter(self, record):
|
||||
return isinstance(record.msg, self.klass)
|
||||
|
||||
class MyClassFilter(ClassFilter):
|
||||
def __init__(self, arg):
|
||||
ClassFilter.__init__(self, MyClass)
|
||||
self.arg = arg
|
||||
|
||||
def filter(self, record):
|
||||
return ClassFilter.filter(self, record) and (record.msg.arg2 == self.arg)
|
||||
|
||||
def main():
|
||||
handler = logging.StreamHandler()
|
||||
root = logging.getLogger("")
|
||||
root.setLevel(logging.DEBUG)
|
||||
root.addHandler(handler)
|
||||
root.addFilter(MyClassFilter("world"))
|
||||
#Not logged, as it's not a MyClass instance
|
||||
root.info("%s, %s", "Hello", "world")
|
||||
#Logged, as it's an appropriate instance which matches the filter criteria
|
||||
root.info(MyClass("Hello", "world"))
|
||||
#Not logged, as it's an appropriate class but doesn't match the filter criteria
|
||||
root.info(MyClass("Hello", "world!"))
|
||||
#Logged, as it's an appropriate instance which matches the filter criteria
|
||||
root.info(MyClass("Goodbye", "world"))
|
||||
#Logged, as it's an appropriate class which matches the filter criteria
|
||||
root.info(MyChildClass("Hello again", "world"))
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
args = sys.argv[1:]
|
||||
if "-profile" in args:
|
||||
import profile, pstats
|
||||
args.remove("-profile")
|
||||
statf = "log_test20.pro"
|
||||
profile.run("main()", statf)
|
||||
stats = pstats.Stats(statf)
|
||||
stats.strip_dirs().sort_stats('time').print_stats()
|
||||
else:
|
||||
main()
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2001-2002 by Vinay Sajip. 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 Vinay Sajip
|
||||
# not be used in advertising or publicity pertaining to distribution
|
||||
# of the software without specific, written prior permission.
|
||||
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
# VINAY SAJIP 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.
|
||||
#
|
||||
# This file is part of the Python logging distribution. See
|
||||
# http://www.red-dove.com/python_logging.html
|
||||
#
|
||||
"""Test harness for the logging module. Demonstrates the use of a wildcard
|
||||
name-space filter with and without custom message classes.
|
||||
|
||||
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
|
||||
"""
|
||||
|
||||
import logging, re, string, types
|
||||
|
||||
class TaggedEvent:
|
||||
def __init__(self, tag, msg):
|
||||
self.tag = tag
|
||||
self.msg = msg
|
||||
|
||||
def __str__(self):
|
||||
return "%s: %s" % (self.tag, self.msg)
|
||||
|
||||
class WildcardFilter(logging.Filter):
|
||||
def __init__(self, wildcards):
|
||||
self.setWildcards(wildcards)
|
||||
|
||||
def setWildcard(self, wildcard):
|
||||
arr = string.split(wildcard, ".")
|
||||
for i in xrange(len(arr)):
|
||||
s = arr[i]
|
||||
if s == "*":
|
||||
arr[i] = r'[\w.]*'
|
||||
elif string.find(s, "*") > 0:
|
||||
arr[i] = string.replace(s, "*", r'[\w]*')
|
||||
s = "^%s$" % string.join(arr, r'\.')
|
||||
self.patterns.append(re.compile(s))
|
||||
|
||||
def setWildcards(self, wildcards):
|
||||
if type(wildcards) != types.ListType:
|
||||
wildcards = [wildcards]
|
||||
self.patterns = []
|
||||
for wildcard in wildcards:
|
||||
self.setWildcard(wildcard)
|
||||
|
||||
def filter(self, record):
|
||||
rv = 0
|
||||
for pat in self.patterns:
|
||||
m = pat.match(record.name)
|
||||
if m is not None:
|
||||
rv = 1
|
||||
break
|
||||
return rv
|
||||
|
||||
class TagFilter(WildcardFilter):
|
||||
def filter(self, record):
|
||||
rv = 0
|
||||
if isinstance(record.msg, TaggedEvent):
|
||||
tag = record.msg.tag
|
||||
else:
|
||||
tag = record.name
|
||||
for pat in self.patterns:
|
||||
m = pat.match(tag)
|
||||
if m is not None:
|
||||
rv = 1
|
||||
break
|
||||
return rv
|
||||
|
||||
def main():
|
||||
handler = logging.StreamHandler()
|
||||
root = logging.getLogger("")
|
||||
root.setLevel(logging.DEBUG)
|
||||
ab = logging.getLogger("a.b")
|
||||
abc = logging.getLogger("a.b.c")
|
||||
|
||||
root.addHandler(handler)
|
||||
filter = WildcardFilter("*.b")
|
||||
handler.addFilter(filter)
|
||||
|
||||
ab.info("#1 from a.b") #logged
|
||||
abc.info("#1 from a.b.c") #not logged
|
||||
filter.setWildcards("*.b.c")
|
||||
ab.info("#2 from a.b") #not logged
|
||||
abc.info("#2 from a.b.c") #logged
|
||||
filter.setWildcards("*.b*")
|
||||
ab.info("#3 from a.b") #logged
|
||||
abc.info("#3 from a.b.c") #not logged
|
||||
filter.setWildcards("*")
|
||||
ab.info("#4 from a.b") #logged
|
||||
abc.info("#4 from a.b.c") #logged
|
||||
filter.setWildcards("a*")
|
||||
ab.info("#5 from a.b") #not logged
|
||||
abc.info("#5 from a.b.c") #not logged
|
||||
filter.setWildcards("a.*")
|
||||
ab.info("#6 from a.b") #logged
|
||||
abc.info("#6 from a.b.c") #logged
|
||||
filter.setWildcards("*.b.*")
|
||||
ab.info("#7 from a.b") #not logged
|
||||
abc.info("#7 from a.b.c") #logged
|
||||
filter.setWildcards(["*.b", "*.b.*"])
|
||||
ab.info("#8 from a.b") #logged
|
||||
abc.info("#8 from a.b.c") #logged
|
||||
filter.setWildcards(["a.*.c"])
|
||||
ab.info("#9 from a.b") #not logged
|
||||
abc.info("#9 from a.b.c") #logged
|
||||
|
||||
#Now test filtering with a tagged class
|
||||
handler.removeFilter(filter)
|
||||
tagfilter = TagFilter(["*.b", "*.b.*"])
|
||||
root.addFilter(tagfilter)
|
||||
root.info(TaggedEvent("a.b", "#10")) #logged
|
||||
root.info(TaggedEvent("a.c", "#10")) #not logged
|
||||
root.info(TaggedEvent("a.b.c", "#10")) #logged
|
||||
root.info(TaggedEvent("a.b.d", "#10")) #logged
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
args = sys.argv[1:]
|
||||
if "-profile" in args:
|
||||
import profile, pstats
|
||||
args.remove("-profile")
|
||||
statf = "log_test21.pro"
|
||||
profile.run("main()", statf)
|
||||
stats = pstats.Stats(statf)
|
||||
stats.strip_dirs().sort_stats('time').print_stats()
|
||||
else:
|
||||
main()
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2001-2002 by Vinay Sajip. 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 Vinay Sajip
|
||||
# not be used in advertising or publicity pertaining to distribution
|
||||
# of the software without specific, written prior permission.
|
||||
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
# VINAY SAJIP 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.
|
||||
#
|
||||
# This file is part of the Python logging distribution. See
|
||||
# http://www.red-dove.com/python_logging.html
|
||||
#
|
||||
"""Test harness for the logging module. Demonstrates the use of different
|
||||
converters for time(secs) -> time(tuple).
|
||||
|
||||
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
|
||||
"""
|
||||
|
||||
import logging, time
|
||||
|
||||
def main():
|
||||
handler = logging.StreamHandler()
|
||||
f1 = logging.Formatter("%(asctime)s %(message)s", "%m/%d %H:%M:%S")
|
||||
f2 = logging.Formatter("%(asctime)s %(message)s", "%m/%d %H:%M:%S")
|
||||
f2.converter = time.gmtime
|
||||
handler.setFormatter(f1)
|
||||
root = logging.getLogger("")
|
||||
root.setLevel(logging.DEBUG)
|
||||
root.addHandler(handler)
|
||||
root.info("Something happened! [should be in local time]")
|
||||
handler.setFormatter(f2)
|
||||
root.info("Something else happened! [should be in GMT]")
|
||||
handler.setFormatter(f1)
|
||||
root.info("Something happened again! [should be in local time]")
|
||||
logging.Formatter.converter = time.gmtime
|
||||
root.info("Something else happened again! [should be in GMT]")
|
||||
logging.Formatter.converter = time.localtime
|
||||
root.info("Something else happened yet again! [should be in local time]")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,95 @@
|
||||
[loggers]
|
||||
keys=root,area1,area11,area111,area1111,area11111,area111111
|
||||
|
||||
[handlers]
|
||||
keys=console,file,socket,datagram,syslog,NT,SMTP
|
||||
|
||||
[formatters]
|
||||
keys=short,medium,long
|
||||
|
||||
[logger_root]
|
||||
handlers=console
|
||||
level=DEBUG
|
||||
|
||||
[logger_area1]
|
||||
level=DEBUG
|
||||
qualname=log02
|
||||
handlers=file
|
||||
|
||||
[logger_area11]
|
||||
level=INFO
|
||||
qualname=log02.log03
|
||||
handlers=socket
|
||||
|
||||
[logger_area111]
|
||||
level=WARN
|
||||
propagate=0
|
||||
qualname=log02.log03.log04
|
||||
handlers=datagram
|
||||
|
||||
[logger_area1111]
|
||||
level=ERROR
|
||||
qualname=log02.log03.log04.log05
|
||||
handlers=syslog
|
||||
|
||||
[logger_area11111]
|
||||
level=CRITICAL
|
||||
qualname=log02.log03.log04.log05.log06
|
||||
handlers=NT
|
||||
|
||||
[logger_area111111]
|
||||
level=WARN
|
||||
qualname=log02.log03.log04.log05.log06.log07
|
||||
handlers=SMTP
|
||||
|
||||
[handler_console]
|
||||
class=StreamHandler
|
||||
formatter=medium
|
||||
stream=sys.stdout
|
||||
args=(sys.stdout,)
|
||||
|
||||
[handler_file]
|
||||
class=FileHandler
|
||||
level=DEBUG
|
||||
formatter=long
|
||||
args=('python.log', 'w')
|
||||
|
||||
[handler_socket]
|
||||
class=handlers.SocketHandler
|
||||
level=INFO
|
||||
formatter=medium
|
||||
args=('localhost', handlers.DEFAULT_TCP_LOGGING_PORT)
|
||||
|
||||
[handler_datagram]
|
||||
class=handlers.DatagramHandler
|
||||
level=WARN
|
||||
formatter=medium
|
||||
args=('localhost', handlers.DEFAULT_UDP_LOGGING_PORT)
|
||||
|
||||
[handler_syslog]
|
||||
class=handlers.SysLogHandler
|
||||
level=ERROR
|
||||
formatter=short
|
||||
args=(('localhost', handlers.SYSLOG_UDP_PORT), handlers.SysLogHandler.LOG_USER)
|
||||
|
||||
[handler_NT]
|
||||
class=handlers.NTEventLogHandler
|
||||
level=CRITICAL
|
||||
formatter=medium
|
||||
args=('Python Application', '', 'Application')
|
||||
|
||||
[handler_SMTP]
|
||||
class=handlers.SMTPHandler
|
||||
level=WARN
|
||||
formatter=long
|
||||
args=('localhost', 'from@abc', ['user1@abc', 'user2@xyz'], 'Logger Subject')
|
||||
|
||||
[formatter_short]
|
||||
format=%(message)s
|
||||
|
||||
[formatter_long]
|
||||
format=%(asctime)s %(pathname)s(%(lineno)d): %(levelname)s %(message)s
|
||||
|
||||
[formatter_medium]
|
||||
format=%(asctime)s %(levelname)s %(message)s
|
||||
datefmt=%m-%d-%Y
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2001-2002 by Vinay Sajip. 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 Vinay Sajip
|
||||
# not be used in advertising or publicity pertaining to distribution
|
||||
# of the software without specific, written prior permission.
|
||||
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
# VINAY SAJIP 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.
|
||||
#
|
||||
# This file is part of the Python logging distribution. See
|
||||
# http://www.red-dove.com/python_logging.html
|
||||
#
|
||||
"""
|
||||
A test harness for the logging module. Tests new fileConfig (not yet a complete test).
|
||||
|
||||
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
|
||||
"""
|
||||
import logging, logging.config
|
||||
|
||||
def doLog(logger):
|
||||
logger.debug("Debug")
|
||||
logger.info("Info")
|
||||
logger.warning("Warning")
|
||||
logger.error("Error")
|
||||
logger.critical("Critical")
|
||||
|
||||
def main():
|
||||
logging.config.fileConfig("log_test3.ini")
|
||||
logger = logging.getLogger(None)
|
||||
print "---------------------------------------------------"
|
||||
print "-- Logging to root; messages appear on console only"
|
||||
print "---------------------------------------------------"
|
||||
doLog(logger)
|
||||
print "----------------------------------------------------------------------"
|
||||
print "-- Logging to log02; messages appear on console and in file python.log"
|
||||
print "----------------------------------------------------------------------"
|
||||
logger = logging.getLogger("log02")
|
||||
doLog(logger)
|
||||
print "--------------------------------------------------------------------------"
|
||||
print "-- Logging to log02.log03; messages appear on console, in file python.log,"
|
||||
print "-- and at logrecv.py tcp (if running. <= DEBUG messages will not appear)."
|
||||
print "--------------------------------------------------------------------------"
|
||||
logger = logging.getLogger("log02.log03")
|
||||
doLog(logger)
|
||||
print "-----------------------------------------------------------------------"
|
||||
print "-- Logging to log02.log03.log04; messages appear only at logrecv.py udp"
|
||||
print "-- (if running. <= INFO messages will not appear)."
|
||||
print "-----------------------------------------------------------------------"
|
||||
logger = logging.getLogger("log02.log03.log04")
|
||||
doLog(logger)
|
||||
print "--------------------------------------------------------------------"
|
||||
print "-- Logging to log02.log03.log04.log05.log06; messages appear at"
|
||||
print "-- logrecv.py udp (if running. < CRITICAL messages will not appear)."
|
||||
print "--------------------------------------------------------------------"
|
||||
logger = logging.getLogger("log02.log03.log04.log05.log06")
|
||||
doLog(logger)
|
||||
print "-- All done."
|
||||
logging.shutdown()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
+168
@@ -0,0 +1,168 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2001-2002 by Vinay Sajip. 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 Vinay Sajip
|
||||
# not be used in advertising or publicity pertaining to distribution
|
||||
# of the software without specific, written prior permission.
|
||||
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
# VINAY SAJIP 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.
|
||||
#
|
||||
# This file is part of the Python logging distribution. See
|
||||
# http://www.red-dove.com/python_logging.html
|
||||
#
|
||||
"""
|
||||
A test harness for the logging module. Tests arbitrary logging levels, filtering, and
|
||||
use of strftime formatting.
|
||||
|
||||
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import locale, sys
|
||||
|
||||
locale.setlocale(locale.LC_ALL, '')
|
||||
|
||||
def message(s):
|
||||
sys.stderr.write("%s\n" % s)
|
||||
|
||||
#
|
||||
# First, we define our levels. There can be as many as you want - the only limitations are that
|
||||
# they should be integers, the lowest should be > 0 and larger values mean less information being
|
||||
# logged. If you need specific level values which do not fit into these limitations, you can use
|
||||
# a mapping dictionary to convert between your application levels and the logging system.
|
||||
#
|
||||
SILENT = 10
|
||||
TACITURN = 9
|
||||
TERSE = 8
|
||||
EFFUSIVE = 7
|
||||
SOCIABLE = 6
|
||||
VERBOSE = 5
|
||||
TALKATIVE = 4
|
||||
GARRULOUS = 3
|
||||
CHATTERBOX = 2
|
||||
BORING = 1
|
||||
|
||||
LEVEL_RANGE = range(BORING, SILENT + 1)
|
||||
|
||||
#
|
||||
# Next, we define names for our levels. You don't need to do this - in which case the system will
|
||||
# use "Level n" to denote the text for the level.
|
||||
#
|
||||
my_logging_levels = {
|
||||
SILENT : 'Silent',
|
||||
TACITURN : 'Taciturn',
|
||||
TERSE : 'Terse',
|
||||
EFFUSIVE : 'Effusive',
|
||||
SOCIABLE : 'Sociable',
|
||||
VERBOSE : 'Verbose',
|
||||
TALKATIVE : 'Talkative',
|
||||
GARRULOUS : 'Garrulous',
|
||||
CHATTERBOX: 'Chatterbox',
|
||||
BORING : 'Boring',
|
||||
}
|
||||
|
||||
#
|
||||
# Now, tell the logging system to associate names with our levels.
|
||||
#
|
||||
for lvl in my_logging_levels.keys():
|
||||
logging.addLevelName(lvl, my_logging_levels[lvl])
|
||||
|
||||
#
|
||||
# Now, define a test function which logs an event at each of our levels.
|
||||
#
|
||||
def doLog(log):
|
||||
for lvl in LEVEL_RANGE:
|
||||
log.log(lvl, "This should only be seen at the '%s' logging level (or lower)", logging.getLevelName(lvl))
|
||||
|
||||
#
|
||||
# Get the root logger and add a console hander to it, when run as a script.
|
||||
#
|
||||
log = logging.getLogger("")
|
||||
|
||||
if __name__ == "__main__":
|
||||
hdlr = logging.StreamHandler()
|
||||
hdlr.setFormatter(logging.Formatter("%(asctime)s %(message)s", "%X")) #date format is as per the locale
|
||||
log.addHandler(hdlr)
|
||||
else:
|
||||
hdlr = log.handlers[0]
|
||||
#
|
||||
# Set the logging level to each different value and call the utility function to log events.
|
||||
# In the output, you should see that each time round the loop, the logging events actually output
|
||||
# decreases.
|
||||
#
|
||||
for lvl in LEVEL_RANGE:
|
||||
message("-- setting logging level to '%s' -----" % logging.getLevelName(lvl))
|
||||
log.setLevel(lvl)
|
||||
doLog(log)
|
||||
#
|
||||
# Now, we demonstrate level filtering at the handler level. Tell the handler defined above
|
||||
# to filter at level 'SOCIABLE', and repeat the above loop. Compare the output from the two runs.
|
||||
#
|
||||
hdlr.setLevel(SOCIABLE)
|
||||
message("-- Filtering at handler level to SOCIABLE --")
|
||||
for lvl in LEVEL_RANGE:
|
||||
message("-- setting logging level to '%s' -----" % logging.getLevelName(lvl))
|
||||
log.setLevel(lvl)
|
||||
doLog(log)
|
||||
|
||||
hdlr.setLevel(0) #turn off level filtering at the handler
|
||||
|
||||
#
|
||||
# Now, let's demonstrate filtering. Suppose for some perverse reason we only want to print out
|
||||
# all except GARRULOUS messages. Let's create a filter for this purpose...
|
||||
#
|
||||
class SpecificLevelFilter(logging.Filter):
|
||||
def __init__(self, lvl):
|
||||
self.level = lvl
|
||||
|
||||
def filter(self, record):
|
||||
return self.level != record.levelno
|
||||
|
||||
class GarrulousFilter(SpecificLevelFilter):
|
||||
def __init__(self):
|
||||
SpecificLevelFilter.__init__(self, GARRULOUS)
|
||||
|
||||
garr = GarrulousFilter()
|
||||
hdlr.addFilter(garr)
|
||||
message("-- Filtering using GARRULOUS filter --")
|
||||
for lvl in LEVEL_RANGE:
|
||||
message("-- setting logging level to '%s' -----" % logging.getLevelName(lvl))
|
||||
log.setLevel(lvl)
|
||||
doLog(log)
|
||||
#
|
||||
# Now, let's demonstrate filtering at the logger. This time, use a filter which excludes SOCIABLE
|
||||
# and TACITURN messages. Note that GARRULOUS events are still excluded.
|
||||
#
|
||||
class VerySpecificFilter(logging.Filter):
|
||||
def filter(self, record):
|
||||
return record.levelno not in [SOCIABLE, TACITURN]
|
||||
|
||||
spec = VerySpecificFilter()
|
||||
log.addFilter(spec)
|
||||
message("-- Filtering using specific filter for SOCIABLE, TACITURN --")
|
||||
for lvl in LEVEL_RANGE:
|
||||
message("-- setting logging level to '%s' -----" % logging.getLevelName(lvl))
|
||||
log.setLevel(lvl)
|
||||
doLog(log)
|
||||
|
||||
log.removeFilter(spec)
|
||||
hdlr.removeFilter(garr)
|
||||
#Undo the one level which clashes...for regression tests
|
||||
logging.addLevelName(logging.DEBUG, "DEBUG")
|
||||
|
||||
#
|
||||
# Er...that's it for now
|
||||
#
|
||||
if __name__ == "__main__":
|
||||
print "All done."
|
||||
logging.shutdown()
|
||||
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2001-2002 by Vinay Sajip. 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 Vinay Sajip
|
||||
# not be used in advertising or publicity pertaining to distribution
|
||||
# of the software without specific, written prior permission.
|
||||
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
# VINAY SAJIP 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.
|
||||
#
|
||||
# This file is part of the Python logging distribution. See
|
||||
# http://www.red-dove.com/python_logging.html
|
||||
#
|
||||
"""
|
||||
A test harness for the logging module. Tests SMTPHandler.
|
||||
|
||||
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
|
||||
"""
|
||||
import logging, logging.handlers
|
||||
|
||||
MAILHOST = 'beta'
|
||||
FROM = 'log_test5@yourdomain.com'
|
||||
TO = ['arkadi_renko']
|
||||
SUBJECT = 'Test Logging email from Python logging module (non-buffering)'
|
||||
|
||||
def main():
|
||||
log = logging.getLogger("")
|
||||
log.setLevel(logging.DEBUG)
|
||||
hdlr = logging.handlers.SMTPHandler(MAILHOST, FROM, TO, SUBJECT)
|
||||
hdlr.setFormatter(logging.Formatter("%(asctime)s %(levelname)-5s %(message)s"))
|
||||
log.addHandler(hdlr)
|
||||
log.info("Test email contents")
|
||||
log.removeHandler(hdlr)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2001-2002 by Vinay Sajip. 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 Vinay Sajip
|
||||
# not be used in advertising or publicity pertaining to distribution
|
||||
# of the software without specific, written prior permission.
|
||||
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
# VINAY SAJIP 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.
|
||||
#
|
||||
# This file is part of the Python logging distribution. See
|
||||
# http://www.red-dove.com/python_logging.html
|
||||
#
|
||||
"""
|
||||
A test harness for the logging module. Tests NTEventLogHandler.
|
||||
|
||||
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
|
||||
"""
|
||||
import logging, logging.handlers
|
||||
|
||||
def main():
|
||||
ntl = logging.handlers.NTEventLogHandler("Python Logging Test")
|
||||
logger = logging.getLogger("")
|
||||
logger.setLevel(logging.DEBUG)
|
||||
logger.addHandler(ntl)
|
||||
logger.debug("This is a '%s' message", "Debug")
|
||||
logger.info("This is a '%s' message", "Info")
|
||||
logger.warning("This is a '%s' message", "Warning")
|
||||
logger.error("This is a '%s' message", "Error")
|
||||
logger.critical("This is a '%s' message", "Critical")
|
||||
try:
|
||||
x = 4 / 0
|
||||
except:
|
||||
logger.info("This is an %s (or should that be %s?)", "informational exception", "exceptional information", exc_info=1)
|
||||
logger.exception("This is the same stuff, via a %s", "exception() call")
|
||||
logger.removeHandler(ntl)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2001-2002 by Vinay Sajip. 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 Vinay Sajip
|
||||
# not be used in advertising or publicity pertaining to distribution
|
||||
# of the software without specific, written prior permission.
|
||||
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
# VINAY SAJIP 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.
|
||||
#
|
||||
# This file is part of the Python logging distribution. See
|
||||
# http://www.red-dove.com/python_logging.html
|
||||
#
|
||||
"""
|
||||
A test harness for the logging module. Tests MemoryHandler.
|
||||
|
||||
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
|
||||
"""
|
||||
import sys, logging, logging.handlers
|
||||
|
||||
def message(s):
|
||||
sys.stderr.write("%s\n" % s)
|
||||
|
||||
sh = logging.StreamHandler()
|
||||
mh = logging.handlers.MemoryHandler(10,logging.WARNING, sh)
|
||||
logger = logging.getLogger("")
|
||||
logger.setLevel(logging.DEBUG)
|
||||
logger.addHandler(mh)
|
||||
message("-- logging at DEBUG, nothing should be seen yet --")
|
||||
logger.debug("Debug message")
|
||||
message("-- logging at INFO, nothing should be seen yet --")
|
||||
logger.info("Info message")
|
||||
message("-- logging at WARNING, 3 messages should be seen --")
|
||||
logger.warning("Warning message")
|
||||
for i in xrange(102):
|
||||
message("-- logging %d at level INFO, messages should be seen every 10 events --" % i)
|
||||
logger.info("Info index = %d", i)
|
||||
sh.close()
|
||||
mh.close()
|
||||
logger.removeHandler(mh)
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2001-2002 by Vinay Sajip. 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 Vinay Sajip
|
||||
# not be used in advertising or publicity pertaining to distribution
|
||||
# of the software without specific, written prior permission.
|
||||
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
# VINAY SAJIP 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.
|
||||
#
|
||||
# This file is part of the Python logging distribution. See
|
||||
# http://www.red-dove.com/python_logging.html
|
||||
#
|
||||
"""
|
||||
A test harness for the logging module. Tests FileHandler rollover.
|
||||
|
||||
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
|
||||
"""
|
||||
import logging, logging.handlers
|
||||
import locale
|
||||
|
||||
locale.setlocale(locale.LC_ALL, '')
|
||||
|
||||
sequence = 0
|
||||
|
||||
def doLog(logger):
|
||||
global sequence
|
||||
sequence = sequence + 1
|
||||
logger.debug("%6d This message should be at level %d - %s", sequence,\
|
||||
logging.DEBUG, logging.getLevelName(logging.DEBUG))
|
||||
sequence = sequence + 1
|
||||
logger.info("%6d This message should be at level %d - %s", sequence,
|
||||
logging.INFO, logging.getLevelName(logging.INFO))
|
||||
sequence = sequence + 1
|
||||
logger.warning("%6d This message should be at level %d - %s", sequence,\
|
||||
logging.WARNING, logging.getLevelName(logging.WARNING))
|
||||
sequence = sequence + 1
|
||||
logger.error("%6d This message should be at level %d - %s", sequence,\
|
||||
logging.ERROR, logging.getLevelName(logging.ERROR))
|
||||
sequence = sequence + 1
|
||||
logger.critical("%6d This message should be at level %d - %s", sequence,\
|
||||
logging.CRITICAL, logging.getLevelName(logging.CRITICAL))
|
||||
|
||||
def main():
|
||||
logger = logging.getLogger("") #root logger
|
||||
logger.setLevel(logging.DEBUG)
|
||||
if __name__ == "__main__":
|
||||
logname = "rollover.log"
|
||||
else:
|
||||
logname = "log_test_rollover.log"
|
||||
hdlr = logging.handlers.RotatingFileHandler(logname, "a", 5000, 3)
|
||||
if __name__ == "__main__":
|
||||
fmt = logging.Formatter("%(asctime)s %(levelname)-5s %(message)s", "%x %X")
|
||||
hdlr.setFormatter(fmt)
|
||||
logger.addHandler(hdlr)
|
||||
for i in xrange(100):
|
||||
doLog(logger)
|
||||
logger.removeHandler(hdlr)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2001-2002 by Vinay Sajip. 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 Vinay Sajip
|
||||
# not be used in advertising or publicity pertaining to distribution
|
||||
# of the software without specific, written prior permission.
|
||||
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
# VINAY SAJIP 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.
|
||||
#
|
||||
# This file is part of the Python logging distribution. See
|
||||
# http://www.red-dove.com/python_logging.html
|
||||
#
|
||||
"""
|
||||
A test harness for the logging module. Tests BufferingHandler, BufferingFormatter.
|
||||
|
||||
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
|
||||
"""
|
||||
import logging, logging.handlers
|
||||
|
||||
class XMLFormatter(logging.BufferingFormatter):
|
||||
"""
|
||||
A formatter which formats a set of records using XML, using an example DTD called "logging.dtd".
|
||||
"""
|
||||
def __init__(self):
|
||||
fmtstr = """
|
||||
<event name="%(name)s" level="%(levelno)d" filename="%(filename)s" lineno="%(lineno)d">
|
||||
<message>%(message)s</message>
|
||||
</event>"""
|
||||
logging.BufferingFormatter.__init__(self, logging.Formatter(fmtstr))
|
||||
|
||||
# def formatHeader(self, records):
|
||||
# return """
|
||||
#<?xml version="1.0" ?><!DOCTYPE eventSet SYSTEM "logging.dtd">
|
||||
#<eventSet xmlns="http://www.red-dove.com/logging">"""
|
||||
#
|
||||
# def formatFooter(self, records):
|
||||
# return "</eventSet>"
|
||||
|
||||
class XMLHandler(logging.handlers.BufferingHandler):
|
||||
def __init__(self, capacity):
|
||||
logging.handlers.BufferingHandler.__init__(self, capacity)
|
||||
self.setFormatter(XMLFormatter())
|
||||
|
||||
def flush(self):
|
||||
if len(self.buffer) > 0:
|
||||
file = open("events.xml","w")
|
||||
file.write(self.formatter.format(self.buffer))
|
||||
file.close()
|
||||
self.buffer = []
|
||||
|
||||
def main():
|
||||
logger = logging.getLogger("")
|
||||
logger.setLevel(logging.DEBUG)
|
||||
xh = XMLHandler(10)
|
||||
logger.addHandler(xh)
|
||||
for i in xrange(100):
|
||||
logger.info("Info index = %d", i)
|
||||
xh.close()
|
||||
logger.removeHandler(xh)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,180 @@
|
||||
[loggers]
|
||||
keys=root,log02,log03,log04,log05,log06,log07
|
||||
|
||||
[handlers]
|
||||
keys=hand01,hand02,hand03,hand04,hand05,hand06,hand07,hand08,hand09
|
||||
|
||||
[formatters]
|
||||
keys=form01,form02,form03,form04,form05,form06,form07,form08,form09
|
||||
|
||||
[logger_root]
|
||||
level=NOTSET
|
||||
propagate=1
|
||||
channel=
|
||||
parent=
|
||||
qualname=(root)
|
||||
handlers=hand01
|
||||
|
||||
[logger_log02]
|
||||
level=DEBUG
|
||||
propagate=1
|
||||
channel=log02
|
||||
parent=(root)
|
||||
qualname=log02
|
||||
handlers=hand02
|
||||
|
||||
[logger_log03]
|
||||
level=INFO
|
||||
propagate=1
|
||||
channel=log03
|
||||
parent=log02
|
||||
qualname=log02.log03
|
||||
handlers=hand03
|
||||
|
||||
[logger_log04]
|
||||
level=WARN
|
||||
propagate=0
|
||||
channel=log04
|
||||
parent=log03
|
||||
qualname=log02.log03.log04
|
||||
handlers=hand04
|
||||
|
||||
[logger_log05]
|
||||
level=ERROR
|
||||
propagate=1
|
||||
channel=log05
|
||||
parent=log04
|
||||
qualname=log02.log03.log04.log05
|
||||
handlers=hand05
|
||||
|
||||
[logger_log06]
|
||||
level=CRITICAL
|
||||
propagate=1
|
||||
channel=log06
|
||||
parent=log05
|
||||
qualname=log02.log03.log04.log05.log06
|
||||
handlers=hand06
|
||||
|
||||
[logger_log07]
|
||||
level=WARN
|
||||
propagate=1
|
||||
channel=log07
|
||||
parent=log06
|
||||
qualname=log02.log03.log04.log05.log06.log07
|
||||
handlers=hand07
|
||||
|
||||
[handler_hand01]
|
||||
class=StreamHandler
|
||||
level=NOTSET
|
||||
formatter=form01
|
||||
stream=sys.stdout
|
||||
args=(sys.stdout,)
|
||||
|
||||
[handler_hand02]
|
||||
class=FileHandler
|
||||
level=DEBUG
|
||||
formatter=form02
|
||||
filename=python.log
|
||||
mode=w
|
||||
args=('python.log', 'w')
|
||||
|
||||
[handler_hand03]
|
||||
class=handlers.SocketHandler
|
||||
level=INFO
|
||||
formatter=form03
|
||||
host=localhost
|
||||
port=handlers.DEFAULT_TCP_LOGGING_PORT
|
||||
args=('localhost', handlers.DEFAULT_TCP_LOGGING_PORT)
|
||||
|
||||
[handler_hand04]
|
||||
class=handlers.DatagramHandler
|
||||
level=WARN
|
||||
formatter=form04
|
||||
host=localhost
|
||||
port=handlers.DEFAULT_UDP_LOGGING_PORT
|
||||
args=('localhost', handlers.DEFAULT_UDP_LOGGING_PORT)
|
||||
|
||||
[handler_hand05]
|
||||
class=handlers.SysLogHandler
|
||||
level=ERROR
|
||||
formatter=form05
|
||||
host=localhost
|
||||
port=handlers.SYSLOG_UDP_PORT
|
||||
facility=LOG_USER
|
||||
args=(('localhost', handlers.SYSLOG_UDP_PORT), handlers.SysLogHandler.LOG_USER)
|
||||
|
||||
[handler_hand06]
|
||||
class=handlers.NTEventLogHandler
|
||||
level=CRITICAL
|
||||
formatter=form06
|
||||
appname=Python Application
|
||||
dllname=
|
||||
logtype=Application
|
||||
args=('Python Application', '', 'Application')
|
||||
|
||||
[handler_hand07]
|
||||
class=handlers.SMTPHandler
|
||||
level=WARN
|
||||
formatter=form07
|
||||
host=localhost
|
||||
port=25
|
||||
from=from@abc
|
||||
to=user1@abc,user2@xyz
|
||||
subject=Logger Subject
|
||||
args=('localhost', 'from@abc', ['user1@abc', 'user2@xyz'], 'Logger Subject')
|
||||
|
||||
[handler_hand08]
|
||||
class=handlers.MemoryHandler
|
||||
level=NOTSET
|
||||
formatter=form08
|
||||
capacity=10
|
||||
flushlevel=ERROR
|
||||
target=
|
||||
args=(10, ERROR)
|
||||
|
||||
[handler_hand09]
|
||||
class=handlers.HTTPHandler
|
||||
level=NOTSET
|
||||
formatter=form09
|
||||
host=localhost
|
||||
port=9022
|
||||
url=/log
|
||||
method=GET
|
||||
args=('localhost:9022', '/log', 'GET')
|
||||
|
||||
[formatter_form01]
|
||||
format=F1 %(asctime)s %(levelname)s %(message)s
|
||||
datefmt=
|
||||
|
||||
[formatter_form02]
|
||||
format=F2 %(asctime)s %(pathname)s(%(lineno)d): %(levelname)s %(message)s
|
||||
datefmt=
|
||||
|
||||
[formatter_form03]
|
||||
format=F3 %(asctime)s %(levelname)s %(message)s
|
||||
datefmt=
|
||||
|
||||
[formatter_form04]
|
||||
format=%(asctime)s %(levelname)s %(message)s
|
||||
datefmt=
|
||||
|
||||
[formatter_form05]
|
||||
format=F5 %(asctime)s %(levelname)s %(message)s
|
||||
datefmt=
|
||||
|
||||
[formatter_form06]
|
||||
format=F6 %(asctime)s %(levelname)s %(message)s
|
||||
datefmt=
|
||||
|
||||
[formatter_form07]
|
||||
format=F7 %(asctime)s %(levelname)s %(message)s
|
||||
datefmt=
|
||||
|
||||
[formatter_form08]
|
||||
format=F8 %(asctime)s %(levelname)s %(message)s
|
||||
datefmt=
|
||||
|
||||
[formatter_form09]
|
||||
format=F9 %(asctime)s %(levelname)s %(message)s
|
||||
datefmt=
|
||||
|
||||
+1738
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<!-- Author: Vinay Sajip, Red Dove Consultants Ltd. http://www.red-dove.com/ -->
|
||||
|
||||
<!-- THIS IS ONLY A VERY SIMPLE EXAMPLE -->
|
||||
|
||||
<!ELEMENT logging:events (logging:event*)>
|
||||
|
||||
<!ELEMENT logging:event (logging:message)>
|
||||
|
||||
<!ATTLIST logging:event
|
||||
name CDATA #REQUIRED
|
||||
level CDATA #REQUIRED
|
||||
created CDATA #IMPLIED
|
||||
filename CDATA #IMPLIED
|
||||
lineno CDATA #IMPLIED
|
||||
>
|
||||
|
||||
<!ELEMENT logging:message (#PCDATA)>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" ?>
|
||||
<!DOCTYPE events SYSTEM "logging.dtd" [<!ENTITY data SYSTEM "events.xml">]>
|
||||
<events xmlns="http://www.red-dove.com/logging">
|
||||
&data;
|
||||
</events>
|
||||
@@ -0,0 +1,36 @@
|
||||
[loggers]
|
||||
keys=root
|
||||
|
||||
[handlers]
|
||||
keys=hand01,hand02
|
||||
|
||||
[formatters]
|
||||
keys=form01
|
||||
|
||||
[logger_root]
|
||||
level=NOTSET
|
||||
propagate=1
|
||||
channel=
|
||||
parent=
|
||||
qualname=(root)
|
||||
handlers=hand01,hand02
|
||||
|
||||
[handler_hand01]
|
||||
class=FileHandler
|
||||
level=NOTSET
|
||||
formatter=form01
|
||||
filename=logrecv.log
|
||||
mode=w
|
||||
args=('logrecv.log', 'w')
|
||||
|
||||
[handler_hand02]
|
||||
class=StreamHandler
|
||||
level=NOTSET
|
||||
formatter=form01
|
||||
stream=sys.stderr
|
||||
args=(sys.stderr,)
|
||||
|
||||
[formatter_form01]
|
||||
format=%(asctime)s %(levelname)-9s %(name)-8s %(thread)5s %(message)s
|
||||
datefmt=
|
||||
|
||||
+443
@@ -0,0 +1,443 @@
|
||||
#! /usr/bin/env python
|
||||
#
|
||||
# Copyright 2001-2002 by Vinay Sajip. 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 Vinay Sajip
|
||||
# not be used in advertising or publicity pertaining to distribution
|
||||
# of the software without specific, written prior permission.
|
||||
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
# VINAY SAJIP 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.
|
||||
#
|
||||
|
||||
"""
|
||||
Simple socket-based logging event receiver for use with "logging.py" logging
|
||||
module.
|
||||
|
||||
Should work under Python versions >= 1.5.2, except that source line information
|
||||
is not available unless 'inspect' is.
|
||||
|
||||
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
|
||||
"""
|
||||
|
||||
from select import select
|
||||
import sys, string, struct, types, cPickle, socket
|
||||
import logging, logging.handlers, logging.config
|
||||
|
||||
TIMEOUT = 10
|
||||
if sys.platform == "win32":
|
||||
RESET_ERROR = 10054
|
||||
else:
|
||||
RESET_ERROR = 0 #FIXME get correct value for Unix...
|
||||
|
||||
logging.raiseExceptions = 1
|
||||
|
||||
#
|
||||
# TCP receiver
|
||||
#
|
||||
|
||||
from SocketServer import ThreadingTCPServer, StreamRequestHandler
|
||||
|
||||
class LogRecordStreamHandler(StreamRequestHandler):
|
||||
"""
|
||||
Handler for a streaming logging request. It basically logs the record
|
||||
using whatever logging policy is configured locally.
|
||||
"""
|
||||
|
||||
def handle(self):
|
||||
"""
|
||||
Handle multiple requests - each expected to be a 4-byte length,
|
||||
followed by the LogRecord in pickle format. Logs the record
|
||||
according to whatever policy is configured locally.
|
||||
"""
|
||||
while 1:
|
||||
try:
|
||||
chunk = self.connection.recv(4)
|
||||
if len(chunk) < 4:
|
||||
break
|
||||
slen = struct.unpack(">L", chunk)[0]
|
||||
chunk = self.connection.recv(slen)
|
||||
while len(chunk) < slen:
|
||||
chunk = chunk + self.connection.recv(slen - len(chunk))
|
||||
obj = self.unPickle(chunk)
|
||||
record = logging.makeLogRecord(obj)
|
||||
self.handleLogRecord(record)
|
||||
except socket.error, e:
|
||||
if type(e.args) != types.TupleType:
|
||||
raise
|
||||
else:
|
||||
errcode = e.args[0]
|
||||
if errcode != RESET_ERROR:
|
||||
raise
|
||||
break
|
||||
|
||||
def unPickle(self, data):
|
||||
return cPickle.loads(data)
|
||||
|
||||
def handleLogRecord(self, record):
|
||||
#if a name is specified, we use the named logger rather than the one
|
||||
#implied by the record. This is so test harnesses don't get into
|
||||
#endless loops (particularly log_test.py, which has this code and the
|
||||
#client code in the same Python instance)
|
||||
if self.server.logname is not None:
|
||||
name = self.server.logname
|
||||
else:
|
||||
name = record.name
|
||||
logger = logging.getLogger(name)
|
||||
logger.handle(record)
|
||||
|
||||
class LogRecordSocketReceiver(ThreadingTCPServer):
|
||||
"""
|
||||
A simple-minded TCP socket-based logging receiver suitable for test
|
||||
purposes.
|
||||
"""
|
||||
|
||||
allow_reuse_address = 1
|
||||
|
||||
def __init__(self, host='localhost', port=logging.handlers.DEFAULT_TCP_LOGGING_PORT,
|
||||
handler=LogRecordStreamHandler):
|
||||
ThreadingTCPServer.__init__(self, (host, port), handler)
|
||||
self.abort = 0
|
||||
self.timeout = 1
|
||||
self.logname = None
|
||||
|
||||
def serve_until_stopped(self):
|
||||
import select
|
||||
abort = 0
|
||||
while not abort:
|
||||
rd, wr, ex = select.select([self.socket.fileno()],
|
||||
[], [],
|
||||
self.timeout)
|
||||
if rd:
|
||||
self.handle_request()
|
||||
abort = self.abort
|
||||
|
||||
#
|
||||
# UDP receiver
|
||||
#
|
||||
|
||||
from SocketServer import ThreadingUDPServer, DatagramRequestHandler
|
||||
|
||||
class LogRecordDatagramHandler(DatagramRequestHandler):
|
||||
"""
|
||||
Handler for a datagram logging request. It basically logs the record using
|
||||
whatever logging policy is configured locally.
|
||||
"""
|
||||
def handle(self):
|
||||
chunk = self.packet
|
||||
slen = struct.unpack(">L", chunk[:4])[0]
|
||||
chunk = chunk[4:]
|
||||
assert len(chunk) == slen
|
||||
obj = self.unPickle(chunk)
|
||||
record = logging.LogRecord(None, None, "", 0, "", (), None)
|
||||
record.__dict__.update(obj)
|
||||
self.handleLogRecord(record)
|
||||
|
||||
def unPickle(self, data):
|
||||
return cPickle.loads(data)
|
||||
|
||||
def handleLogRecord(self, record):
|
||||
#if a name is specified, we use the named logger rather than the one
|
||||
#implied by the record. This is so test harnesses don't get into
|
||||
#endless loops (particularly log_test.py, which has this code and the
|
||||
#client code in the same Python instance)
|
||||
if self.server.logname is not None:
|
||||
name = self.server.logname
|
||||
else:
|
||||
name = record.name
|
||||
logger = logging.getLogger(name)
|
||||
logger.handle(record)
|
||||
|
||||
def finish(self):
|
||||
pass
|
||||
|
||||
class LogRecordDatagramReceiver(ThreadingUDPServer):
|
||||
"""
|
||||
A simple-minded UDP datagram-based logging receiver suitable for test
|
||||
purposes.
|
||||
"""
|
||||
|
||||
allow_reuse_address = 1
|
||||
|
||||
def __init__(self, host='localhost', port=logging.handlers.DEFAULT_UDP_LOGGING_PORT,
|
||||
handler=LogRecordDatagramHandler):
|
||||
ThreadingUDPServer.__init__(self, (host, port), handler)
|
||||
self.abort = 0
|
||||
self.timeout = 1
|
||||
self.logname = None
|
||||
|
||||
def serve_until_stopped(self):
|
||||
import select
|
||||
abort = 0
|
||||
while not abort:
|
||||
rd, wr, ex = select.select([self.socket.fileno()],
|
||||
[], [],
|
||||
self.timeout)
|
||||
if rd:
|
||||
self.handle_request()
|
||||
abort = self.abort
|
||||
|
||||
#
|
||||
# HTTP receiver
|
||||
#
|
||||
|
||||
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
|
||||
|
||||
import cgi
|
||||
|
||||
class LogRecordHTTPHandler(BaseHTTPRequestHandler):
|
||||
def makeDict(self, fs):
|
||||
dict = {}
|
||||
for mfs in fs.list:
|
||||
dict[mfs.name] = mfs.value
|
||||
for key in ["args", "exc_info", "exc_text", "lineno", "msecs", "created",
|
||||
"thread", "levelno", "relativeCreated"]:
|
||||
if dict.has_key(key):
|
||||
dict[key] = eval(dict[key])
|
||||
return dict
|
||||
|
||||
def do_GET(self):
|
||||
"""Serve a GET request."""
|
||||
sts = "OK"
|
||||
env = { 'REQUEST_METHOD' : 'GET'}
|
||||
try:
|
||||
i = string.find(self.path, '?')
|
||||
if i >= 0:
|
||||
env['QUERY_STRING'] = self.path[i + 1:]
|
||||
fs = cgi.FieldStorage(environ=env)
|
||||
dict = self.makeDict(fs)
|
||||
record = logging.LogRecord(None, None, "", 0, "", (), None)
|
||||
record.__dict__.update(dict)
|
||||
self.handleLogRecord(record)
|
||||
except Exception, e:
|
||||
sts = "ERROR"
|
||||
raise
|
||||
self.send_head()
|
||||
self.wfile.write("GET %s" % sts)
|
||||
|
||||
def handleLogRecord(self, record):
|
||||
#if a name is specified, we use the named logger rather than the one
|
||||
#implied by the record. This is so test harnesses don't get into
|
||||
#endless loops (particularly log_test.py, which has this code and the
|
||||
#client code in the same Python instance)
|
||||
if self.server.logname is not None:
|
||||
name = self.server.logname
|
||||
else:
|
||||
name = record.name
|
||||
logger = logging.getLogger(name)
|
||||
logger.handle(record)
|
||||
|
||||
def do_HEAD(self):
|
||||
"""Serve a HEAD request."""
|
||||
self.send_head()
|
||||
|
||||
def do_POST(self):
|
||||
"""Serve a POST request."""
|
||||
sts = "OK"
|
||||
env = { 'REQUEST_METHOD' : 'POST'}
|
||||
try:
|
||||
length = self.headers.getheader('content-length')
|
||||
if length:
|
||||
env['CONTENT_LENGTH'] = length
|
||||
#print self.headers
|
||||
i = string.find(self.path, '?')
|
||||
if i >= 0:
|
||||
env['QUERY_STRING'] = self.path[i + 1:]
|
||||
fs = cgi.FieldStorage(fp=self.rfile, environ=env)
|
||||
dict = self.makeDict(fs)
|
||||
record = logging.LogRecord(None, None, "", 0, "", (), None)
|
||||
record.__dict__.update(dict)
|
||||
self.handleLogRecord(record)
|
||||
except Exception, e:
|
||||
print e
|
||||
sys.stdout.flush()
|
||||
sts = "ERROR"
|
||||
raise
|
||||
self.send_head()
|
||||
self.wfile.write("POST %s" % sts)
|
||||
|
||||
def send_head(self):
|
||||
"""Common code for GET and HEAD commands.
|
||||
|
||||
This sends the response code and MIME headers.
|
||||
|
||||
Return value is either a file object (which has to be copied
|
||||
to the outputfile by the caller unless the command was HEAD,
|
||||
and must be closed by the caller under all circumstances), or
|
||||
None, in which case the caller has nothing further to do.
|
||||
|
||||
"""
|
||||
self.send_response(200)
|
||||
self.send_header("Content-type", "text/plain")
|
||||
self.end_headers()
|
||||
|
||||
def log_message(self, *args):
|
||||
#comment out the following line if you don't want to show requests
|
||||
#apply(BaseHTTPRequestHandler.log_message, (self,) + args)
|
||||
pass
|
||||
|
||||
class LogRecordHTTPReceiver(HTTPServer):
|
||||
def __init__(self, host='localhost', port=logging.handlers.DEFAULT_HTTP_LOGGING_PORT,
|
||||
handler=LogRecordHTTPHandler):
|
||||
HTTPServer.__init__(self, (host, port), handler)
|
||||
self.abort = 0
|
||||
self.timeout = 1
|
||||
self.logname = None
|
||||
|
||||
def serve_until_stopped(self):
|
||||
import select
|
||||
abort = 0
|
||||
while not abort:
|
||||
rd, wr, ex = select.select([self.socket.fileno()],
|
||||
[], [],
|
||||
self.timeout)
|
||||
if rd:
|
||||
self.handle_request()
|
||||
abort = self.abort
|
||||
|
||||
|
||||
#
|
||||
# SOAP receiver
|
||||
#
|
||||
|
||||
try:
|
||||
from ZSI import dispatch
|
||||
|
||||
logname = None
|
||||
|
||||
def log(args, created, exc_info, exc_text, filename, levelname, levelno, lineno, module, msecs, msg, name, pathname, process, relativeCreated, thread):
|
||||
record = logging.LogRecord(None, None, "", 0, "", (), None)
|
||||
record.args = eval(args)
|
||||
record.exc_info = eval(exc_info)
|
||||
record.exc_text = eval(exc_text)
|
||||
record.created = created
|
||||
record.filename = filename
|
||||
record.module = module
|
||||
record.levelname = levelname
|
||||
record.lineno = lineno
|
||||
record.levelno = levelno
|
||||
record.msecs = msecs
|
||||
record.msg = msg
|
||||
record.name = name
|
||||
record.pathname = pathname
|
||||
record.process = process
|
||||
record.relativeCreated = relativeCreated
|
||||
record.thread = thread
|
||||
#if a name is specified, we use the named logger rather than the one
|
||||
#implied by the record. This is so test harnesses don't get into
|
||||
#endless loops (particularly log_test.py, which has this code and the
|
||||
#client code in the same Python instance)
|
||||
if logname is not None:
|
||||
lname = logname
|
||||
else:
|
||||
lname = name
|
||||
logger = logging.getLogger(lname)
|
||||
logger.handle(record)
|
||||
|
||||
class MySOAPRequestHandler(dispatch.SOAPRequestHandler):
|
||||
def log_message(self, *args):
|
||||
#comment out the following line if you don't want to show requests
|
||||
#apply(BaseHTTPRequestHandler.log_message, (self,) + args)
|
||||
pass
|
||||
|
||||
class SOAPServer(HTTPServer):
|
||||
def __init__(self, port=logging.handlers.DEFAULT_SOAP_LOGGING_PORT):
|
||||
address = ('', port)
|
||||
HTTPServer.__init__(self, address, MySOAPRequestHandler)
|
||||
self.abort = 0
|
||||
self.timeout = 1
|
||||
self.logname = None
|
||||
self.docstyle = 0
|
||||
self.nsdict = {}
|
||||
self.typesmodule = None
|
||||
self.rpc = 1
|
||||
self.modules = (sys.modules["__main__"],)
|
||||
|
||||
def serve_until_stopped(self):
|
||||
import select
|
||||
abort = 0
|
||||
while not abort:
|
||||
rd, wr, ex = select.select([self.socket.fileno()],
|
||||
[], [],
|
||||
self.timeout)
|
||||
if rd:
|
||||
global logname
|
||||
logname = self.logname
|
||||
self.handle_request()
|
||||
abort = self.abort
|
||||
|
||||
except ImportError:
|
||||
"Import failed"
|
||||
SOAPServer = None
|
||||
|
||||
def runTCP(tcpserver=None):
|
||||
if not tcpserver:
|
||||
tcpserver = LogRecordSocketReceiver()
|
||||
print "About to start TCP server..."
|
||||
tcpserver.serve_until_stopped()
|
||||
|
||||
def runUDP(udpserver=None):
|
||||
if not udpserver:
|
||||
udpserver = LogRecordDatagramReceiver()
|
||||
print "About to start UDP server..."
|
||||
udpserver.serve_until_stopped()
|
||||
|
||||
def runHTTP(httpserver=None):
|
||||
if not httpserver:
|
||||
httpserver = LogRecordHTTPReceiver()
|
||||
print "About to start HTTP server..."
|
||||
httpserver.serve_until_stopped()
|
||||
|
||||
def runSOAP(soapserver=None):
|
||||
if not SOAPServer:
|
||||
print "Sorry, ZSI is not available. Install PyXML-0.6.6 and ZSI first."
|
||||
print "See README.txt and python_logging.html for more information."
|
||||
else:
|
||||
if not soapserver:
|
||||
soapserver = SOAPServer()
|
||||
print "About to start SOAP server..."
|
||||
soapserver.serve_until_stopped()
|
||||
|
||||
FORMAT_STR = "%(asctime)s %(name)-19s %(levelname)-5s - %(message)s"
|
||||
|
||||
if __name__ == "__main__":
|
||||
if (len(sys.argv) < 2) or not (string.lower(sys.argv[1]) in \
|
||||
["udp", "tcp", "http", "soap"]):
|
||||
print "usage: logrecv.py [UDP|TCP|HTTP|SOAP]"
|
||||
else:
|
||||
#logging.basicConfig()
|
||||
logging.config.fileConfig("logrecv.ini")
|
||||
# both = string.lower(sys.argv[1]) == "both"
|
||||
# hdlr = logging.FileHandler("test.log")
|
||||
# hdlr.setFormatter(logging.Formatter(FORMAT_STR))
|
||||
# logging.getLogger("").addHandler(hdlr)
|
||||
# if both:
|
||||
# import threading
|
||||
# tcpthread = threading.Thread(target=runTCP)
|
||||
# udpthread = threading.Thread(target=runUDP)
|
||||
# tcpthread.start()
|
||||
# udpthread.start()
|
||||
# tcpthread.join()
|
||||
# udpthread.join()
|
||||
# else:
|
||||
# tcp = string.lower(sys.argv[1]) == "tcp"
|
||||
# if tcp:
|
||||
# runTCP()
|
||||
# else:
|
||||
# runUDP()
|
||||
arg = string.lower(sys.argv[1])
|
||||
if arg == "tcp":
|
||||
runTCP()
|
||||
elif arg == "udp":
|
||||
runUDP()
|
||||
elif arg == "http":
|
||||
runHTTP()
|
||||
elif arg == "soap":
|
||||
runSOAP()
|
||||
@@ -0,0 +1,13 @@
|
||||
import logging, mymodule
|
||||
|
||||
logging.basicConfig()
|
||||
|
||||
log = logging.getLogger("MyApp")
|
||||
log.setLevel(logging.DEBUG) #set verbosity to show all messages of severity >= DEBUG
|
||||
log.info("Starting my app")
|
||||
try:
|
||||
mymodule.doIt()
|
||||
except Exception, e:
|
||||
log.exception("There was a problem.")
|
||||
log.info("Ending my app")
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import logging
|
||||
log = logging.getLogger("MyModule")
|
||||
|
||||
def doIt():
|
||||
log.debug("Doin' stuff...")
|
||||
#do stuff...
|
||||
raise TypeError, "Bogus type error for testing"
|
||||
|
||||
@@ -0,0 +1,566 @@
|
||||
-- log_test0 begin --------------------------------------------------------
|
||||
CRITICAL:ERR:Message 0
|
||||
ERROR:ERR:Message 1
|
||||
CRITICAL:INF:Message 2
|
||||
ERROR:INF:Message 3
|
||||
WARNING:INF:Message 4
|
||||
INFO:INF:Message 5
|
||||
CRITICAL:INF.UNDEF:Message 6
|
||||
ERROR:INF.UNDEF:Message 7
|
||||
WARNING:INF.UNDEF:Message 8
|
||||
INFO:INF.UNDEF:Message 9
|
||||
CRITICAL:INF.ERR:Message 10
|
||||
ERROR:INF.ERR:Message 11
|
||||
CRITICAL:INF.ERR.UNDEF:Message 12
|
||||
ERROR:INF.ERR.UNDEF:Message 13
|
||||
CRITICAL:DEB:Message 14
|
||||
ERROR:DEB:Message 15
|
||||
WARNING:DEB:Message 16
|
||||
INFO:DEB:Message 17
|
||||
DEBUG:DEB:Message 18
|
||||
CRITICAL:UNDEF:Message 19
|
||||
ERROR:UNDEF:Message 20
|
||||
WARNING:UNDEF:Message 21
|
||||
INFO:UNDEF:Message 22
|
||||
CRITICAL:INF.BADPARENT.UNDEF:Message 23
|
||||
CRITICAL:INF.BADPARENT:Message 24
|
||||
INFO:INF:Messages should bear numbers 0 through 24.
|
||||
-- log_test0 end --------------------------------------------------------
|
||||
-- log_test2 begin --------------------------------------------------------
|
||||
CRITICAL:ERR:Message 0
|
||||
ERROR:ERR:Message 1
|
||||
CRITICAL:INF:Message 2
|
||||
ERROR:INF:Message 3
|
||||
WARNING:INF:Message 4
|
||||
INFO:INF:Message 5
|
||||
CRITICAL:INF.UNDEF:Message 6
|
||||
ERROR:INF.UNDEF:Message 7
|
||||
WARNING:INF.UNDEF:Message 8
|
||||
INFO:INF.UNDEF:Message 9
|
||||
CRITICAL:INF.ERR:Message 10
|
||||
ERROR:INF.ERR:Message 11
|
||||
CRITICAL:INF.ERR.UNDEF:Message 12
|
||||
ERROR:INF.ERR.UNDEF:Message 13
|
||||
CRITICAL:DEB:Message 14
|
||||
ERROR:DEB:Message 15
|
||||
WARNING:DEB:Message 16
|
||||
INFO:DEB:Message 17
|
||||
DEBUG:DEB:Message 18
|
||||
CRITICAL:UNDEF:Message 19
|
||||
ERROR:UNDEF:Message 20
|
||||
WARNING:UNDEF:Message 21
|
||||
INFO:UNDEF:Message 22
|
||||
CRITICAL:INF.BADPARENT.UNDEF:Message 23
|
||||
CRITICAL:INF.BADPARENT:Message 24
|
||||
INFO:INF:Messages should bear numbers 0 through 24.
|
||||
-- log_test2 end --------------------------------------------------------
|
||||
CRITICAL:ERR:Message 0
|
||||
ERROR:ERR:Message 1
|
||||
CRITICAL:INF:Message 2
|
||||
ERROR:INF:Message 3
|
||||
WARNING:INF:Message 4
|
||||
INFO:INF:Message 5
|
||||
CRITICAL:INF.UNDEF:Message 6
|
||||
ERROR:INF.UNDEF:Message 7
|
||||
WARNING:INF.UNDEF:Message 8
|
||||
INFO:INF.UNDEF:Message 9
|
||||
CRITICAL:INF.ERR:Message 10
|
||||
ERROR:INF.ERR:Message 11
|
||||
CRITICAL:INF.ERR.UNDEF:Message 12
|
||||
ERROR:INF.ERR.UNDEF:Message 13
|
||||
CRITICAL:DEB:Message 14
|
||||
ERROR:DEB:Message 15
|
||||
WARNING:DEB:Message 16
|
||||
INFO:DEB:Message 17
|
||||
DEBUG:DEB:Message 18
|
||||
CRITICAL:UNDEF:Message 19
|
||||
ERROR:UNDEF:Message 20
|
||||
WARNING:UNDEF:Message 21
|
||||
INFO:UNDEF:Message 22
|
||||
CRITICAL:INF.BADPARENT.UNDEF:Message 23
|
||||
CRITICAL:INF.BADPARENT:Message 24
|
||||
INFO:INF:Messages should bear numbers 0 through 24.
|
||||
-- log_test4 begin --------------------------------------------------------
|
||||
-- setting logging level to 'Boring' -----
|
||||
Boring:root:This should only be seen at the 'Boring' logging level (or lower)
|
||||
Chatterbox:root:This should only be seen at the 'Chatterbox' logging level (or lower)
|
||||
Garrulous:root:This should only be seen at the 'Garrulous' logging level (or lower)
|
||||
Talkative:root:This should only be seen at the 'Talkative' logging level (or lower)
|
||||
Verbose:root:This should only be seen at the 'Verbose' logging level (or lower)
|
||||
Sociable:root:This should only be seen at the 'Sociable' logging level (or lower)
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Chatterbox' -----
|
||||
Chatterbox:root:This should only be seen at the 'Chatterbox' logging level (or lower)
|
||||
Garrulous:root:This should only be seen at the 'Garrulous' logging level (or lower)
|
||||
Talkative:root:This should only be seen at the 'Talkative' logging level (or lower)
|
||||
Verbose:root:This should only be seen at the 'Verbose' logging level (or lower)
|
||||
Sociable:root:This should only be seen at the 'Sociable' logging level (or lower)
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Garrulous' -----
|
||||
Garrulous:root:This should only be seen at the 'Garrulous' logging level (or lower)
|
||||
Talkative:root:This should only be seen at the 'Talkative' logging level (or lower)
|
||||
Verbose:root:This should only be seen at the 'Verbose' logging level (or lower)
|
||||
Sociable:root:This should only be seen at the 'Sociable' logging level (or lower)
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Talkative' -----
|
||||
Talkative:root:This should only be seen at the 'Talkative' logging level (or lower)
|
||||
Verbose:root:This should only be seen at the 'Verbose' logging level (or lower)
|
||||
Sociable:root:This should only be seen at the 'Sociable' logging level (or lower)
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Verbose' -----
|
||||
Verbose:root:This should only be seen at the 'Verbose' logging level (or lower)
|
||||
Sociable:root:This should only be seen at the 'Sociable' logging level (or lower)
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Sociable' -----
|
||||
Sociable:root:This should only be seen at the 'Sociable' logging level (or lower)
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Effusive' -----
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Terse' -----
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Taciturn' -----
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Silent' -----
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- Filtering at handler level to SOCIABLE --
|
||||
-- setting logging level to 'Boring' -----
|
||||
Sociable:root:This should only be seen at the 'Sociable' logging level (or lower)
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Chatterbox' -----
|
||||
Sociable:root:This should only be seen at the 'Sociable' logging level (or lower)
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Garrulous' -----
|
||||
Sociable:root:This should only be seen at the 'Sociable' logging level (or lower)
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Talkative' -----
|
||||
Sociable:root:This should only be seen at the 'Sociable' logging level (or lower)
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Verbose' -----
|
||||
Sociable:root:This should only be seen at the 'Sociable' logging level (or lower)
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Sociable' -----
|
||||
Sociable:root:This should only be seen at the 'Sociable' logging level (or lower)
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Effusive' -----
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Terse' -----
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Taciturn' -----
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Silent' -----
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- Filtering using GARRULOUS filter --
|
||||
-- setting logging level to 'Boring' -----
|
||||
Boring:root:This should only be seen at the 'Boring' logging level (or lower)
|
||||
Chatterbox:root:This should only be seen at the 'Chatterbox' logging level (or lower)
|
||||
Talkative:root:This should only be seen at the 'Talkative' logging level (or lower)
|
||||
Verbose:root:This should only be seen at the 'Verbose' logging level (or lower)
|
||||
Sociable:root:This should only be seen at the 'Sociable' logging level (or lower)
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Chatterbox' -----
|
||||
Chatterbox:root:This should only be seen at the 'Chatterbox' logging level (or lower)
|
||||
Talkative:root:This should only be seen at the 'Talkative' logging level (or lower)
|
||||
Verbose:root:This should only be seen at the 'Verbose' logging level (or lower)
|
||||
Sociable:root:This should only be seen at the 'Sociable' logging level (or lower)
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Garrulous' -----
|
||||
Talkative:root:This should only be seen at the 'Talkative' logging level (or lower)
|
||||
Verbose:root:This should only be seen at the 'Verbose' logging level (or lower)
|
||||
Sociable:root:This should only be seen at the 'Sociable' logging level (or lower)
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Talkative' -----
|
||||
Talkative:root:This should only be seen at the 'Talkative' logging level (or lower)
|
||||
Verbose:root:This should only be seen at the 'Verbose' logging level (or lower)
|
||||
Sociable:root:This should only be seen at the 'Sociable' logging level (or lower)
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Verbose' -----
|
||||
Verbose:root:This should only be seen at the 'Verbose' logging level (or lower)
|
||||
Sociable:root:This should only be seen at the 'Sociable' logging level (or lower)
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Sociable' -----
|
||||
Sociable:root:This should only be seen at the 'Sociable' logging level (or lower)
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Effusive' -----
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Terse' -----
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Taciturn' -----
|
||||
Taciturn:root:This should only be seen at the 'Taciturn' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Silent' -----
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- Filtering using specific filter for SOCIABLE, TACITURN --
|
||||
-- setting logging level to 'Boring' -----
|
||||
Boring:root:This should only be seen at the 'Boring' logging level (or lower)
|
||||
Chatterbox:root:This should only be seen at the 'Chatterbox' logging level (or lower)
|
||||
Talkative:root:This should only be seen at the 'Talkative' logging level (or lower)
|
||||
Verbose:root:This should only be seen at the 'Verbose' logging level (or lower)
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Chatterbox' -----
|
||||
Chatterbox:root:This should only be seen at the 'Chatterbox' logging level (or lower)
|
||||
Talkative:root:This should only be seen at the 'Talkative' logging level (or lower)
|
||||
Verbose:root:This should only be seen at the 'Verbose' logging level (or lower)
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Garrulous' -----
|
||||
Talkative:root:This should only be seen at the 'Talkative' logging level (or lower)
|
||||
Verbose:root:This should only be seen at the 'Verbose' logging level (or lower)
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Talkative' -----
|
||||
Talkative:root:This should only be seen at the 'Talkative' logging level (or lower)
|
||||
Verbose:root:This should only be seen at the 'Verbose' logging level (or lower)
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Verbose' -----
|
||||
Verbose:root:This should only be seen at the 'Verbose' logging level (or lower)
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Sociable' -----
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Effusive' -----
|
||||
Effusive:root:This should only be seen at the 'Effusive' logging level (or lower)
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Terse' -----
|
||||
Terse:root:This should only be seen at the 'Terse' logging level (or lower)
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Taciturn' -----
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- setting logging level to 'Silent' -----
|
||||
Silent:root:This should only be seen at the 'Silent' logging level (or lower)
|
||||
-- log_test4 end --------------------------------------------------------
|
||||
-- log_test7 begin --------------------------------------------------------
|
||||
-- logging at DEBUG, nothing should be seen yet --
|
||||
-- logging at INFO, nothing should be seen yet --
|
||||
-- logging at WARNING, 3 messages should be seen --
|
||||
Debug message
|
||||
Info message
|
||||
Warning message
|
||||
-- logging 0 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 1 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 2 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 3 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 4 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 5 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 6 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 7 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 8 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 9 at level INFO, messages should be seen every 10 events --
|
||||
Info index = 0
|
||||
Info index = 1
|
||||
Info index = 2
|
||||
Info index = 3
|
||||
Info index = 4
|
||||
Info index = 5
|
||||
Info index = 6
|
||||
Info index = 7
|
||||
Info index = 8
|
||||
Info index = 9
|
||||
-- logging 10 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 11 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 12 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 13 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 14 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 15 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 16 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 17 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 18 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 19 at level INFO, messages should be seen every 10 events --
|
||||
Info index = 10
|
||||
Info index = 11
|
||||
Info index = 12
|
||||
Info index = 13
|
||||
Info index = 14
|
||||
Info index = 15
|
||||
Info index = 16
|
||||
Info index = 17
|
||||
Info index = 18
|
||||
Info index = 19
|
||||
-- logging 20 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 21 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 22 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 23 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 24 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 25 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 26 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 27 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 28 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 29 at level INFO, messages should be seen every 10 events --
|
||||
Info index = 20
|
||||
Info index = 21
|
||||
Info index = 22
|
||||
Info index = 23
|
||||
Info index = 24
|
||||
Info index = 25
|
||||
Info index = 26
|
||||
Info index = 27
|
||||
Info index = 28
|
||||
Info index = 29
|
||||
-- logging 30 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 31 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 32 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 33 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 34 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 35 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 36 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 37 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 38 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 39 at level INFO, messages should be seen every 10 events --
|
||||
Info index = 30
|
||||
Info index = 31
|
||||
Info index = 32
|
||||
Info index = 33
|
||||
Info index = 34
|
||||
Info index = 35
|
||||
Info index = 36
|
||||
Info index = 37
|
||||
Info index = 38
|
||||
Info index = 39
|
||||
-- logging 40 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 41 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 42 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 43 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 44 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 45 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 46 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 47 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 48 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 49 at level INFO, messages should be seen every 10 events --
|
||||
Info index = 40
|
||||
Info index = 41
|
||||
Info index = 42
|
||||
Info index = 43
|
||||
Info index = 44
|
||||
Info index = 45
|
||||
Info index = 46
|
||||
Info index = 47
|
||||
Info index = 48
|
||||
Info index = 49
|
||||
-- logging 50 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 51 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 52 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 53 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 54 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 55 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 56 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 57 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 58 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 59 at level INFO, messages should be seen every 10 events --
|
||||
Info index = 50
|
||||
Info index = 51
|
||||
Info index = 52
|
||||
Info index = 53
|
||||
Info index = 54
|
||||
Info index = 55
|
||||
Info index = 56
|
||||
Info index = 57
|
||||
Info index = 58
|
||||
Info index = 59
|
||||
-- logging 60 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 61 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 62 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 63 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 64 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 65 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 66 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 67 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 68 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 69 at level INFO, messages should be seen every 10 events --
|
||||
Info index = 60
|
||||
Info index = 61
|
||||
Info index = 62
|
||||
Info index = 63
|
||||
Info index = 64
|
||||
Info index = 65
|
||||
Info index = 66
|
||||
Info index = 67
|
||||
Info index = 68
|
||||
Info index = 69
|
||||
-- logging 70 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 71 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 72 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 73 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 74 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 75 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 76 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 77 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 78 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 79 at level INFO, messages should be seen every 10 events --
|
||||
Info index = 70
|
||||
Info index = 71
|
||||
Info index = 72
|
||||
Info index = 73
|
||||
Info index = 74
|
||||
Info index = 75
|
||||
Info index = 76
|
||||
Info index = 77
|
||||
Info index = 78
|
||||
Info index = 79
|
||||
-- logging 80 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 81 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 82 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 83 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 84 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 85 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 86 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 87 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 88 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 89 at level INFO, messages should be seen every 10 events --
|
||||
Info index = 80
|
||||
Info index = 81
|
||||
Info index = 82
|
||||
Info index = 83
|
||||
Info index = 84
|
||||
Info index = 85
|
||||
Info index = 86
|
||||
Info index = 87
|
||||
Info index = 88
|
||||
Info index = 89
|
||||
-- logging 90 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 91 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 92 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 93 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 94 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 95 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 96 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 97 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 98 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 99 at level INFO, messages should be seen every 10 events --
|
||||
Info index = 90
|
||||
Info index = 91
|
||||
Info index = 92
|
||||
Info index = 93
|
||||
Info index = 94
|
||||
Info index = 95
|
||||
Info index = 96
|
||||
Info index = 97
|
||||
Info index = 98
|
||||
Info index = 99
|
||||
-- logging 100 at level INFO, messages should be seen every 10 events --
|
||||
-- logging 101 at level INFO, messages should be seen every 10 events --
|
||||
Info index = 100
|
||||
Info index = 101
|
||||
-- log_test7 end --------------------------------------------------------
|
||||
-- log_test8 begin --------------------------------------------------------
|
||||
-- log_test8 end --------------------------------------------------------
|
||||
-- log_test9 begin --------------------------------------------------------
|
||||
-- log_test9 end --------------------------------------------------------
|
||||
-- log_test10 begin --------------------------------------------------------
|
||||
logger not derived from logging.Logger: NotALogger
|
||||
INFO:mylogger:Starting...
|
||||
DEBUG:mylogger:Debug message not in exception handler (no traceback)
|
||||
INFO:mylogger:About to throw exception...
|
||||
DEBUG:mylogger:Debug message inside exception handler (traceback)
|
||||
Traceback (most recent call last):
|
||||
File "C:\Projects\RDC\Python\packages\logging\test\log_test10.py", line 77, in run
|
||||
print "7" + 4
|
||||
TypeError: cannot concatenate 'str' and 'int' objects
|
||||
INFO:mylogger:Done.
|
||||
-- log_test10 end --------------------------------------------------------
|
||||
-- log_test12 begin --------------------------------------------------------
|
||||
INFO:log_test12:Jackdaws love my big sphinx of quartz
|
||||
INFO:log_test12:Jackdaws love my big sphinx of quartz
|
||||
DEBUG:log_test12:Pack my box with twelve dozen liquor jugs
|
||||
DEBUG:log_test12:Pack my box with twelve dozen liquor jugs
|
||||
-- log_test12 end --------------------------------------------------------
|
||||
-- log_test13 begin --------------------------------------------------------
|
||||
INFO:log_test13:Jackdaws love my big sphinx of quartz
|
||||
DEBUG:log_test13:Pack my box with five dozen liquor jugs
|
||||
-- log_test13 end --------------------------------------------------------
|
||||
-- log_test15 begin --------------------------------------------------------
|
||||
Unfiltered...
|
||||
INFO:a:Info 1
|
||||
INFO:a.b:Info 2
|
||||
INFO:a.c:Info 3
|
||||
INFO:a.b.c:Info 4
|
||||
INFO:a.b.c.d:Info 5
|
||||
INFO:a.bb.c:Info 6
|
||||
INFO:b:Info 7
|
||||
INFO:b.a:Info 8
|
||||
INFO:c.a.b:Info 9
|
||||
INFO:a.bb:Info 10
|
||||
Filtered with 'a.b'...
|
||||
INFO:a.b:Info 2
|
||||
INFO:a.b.c:Info 4
|
||||
INFO:a.b.c.d:Info 5
|
||||
-- log_test15 end --------------------------------------------------------
|
||||
@@ -0,0 +1,24 @@
|
||||
About to start TCP server...
|
||||
About to start UDP server...
|
||||
About to start HTTP server...
|
||||
About to start SOAP server...
|
||||
-- log_test0 begin --------------------------------------------------------
|
||||
-- log_test0 end --------------------------------------------------------
|
||||
-- log_test2 begin --------------------------------------------------------
|
||||
-- log_test2 end --------------------------------------------------------
|
||||
-- log_test4 begin --------------------------------------------------------
|
||||
-- log_test4 end --------------------------------------------------------
|
||||
-- log_test7 begin --------------------------------------------------------
|
||||
-- log_test7 end --------------------------------------------------------
|
||||
-- log_test8 begin --------------------------------------------------------
|
||||
-- log_test8 end --------------------------------------------------------
|
||||
-- log_test9 begin --------------------------------------------------------
|
||||
-- log_test9 end --------------------------------------------------------
|
||||
-- log_test10 begin --------------------------------------------------------
|
||||
-- log_test10 end --------------------------------------------------------
|
||||
-- log_test12 begin --------------------------------------------------------
|
||||
-- log_test12 end --------------------------------------------------------
|
||||
-- log_test13 begin --------------------------------------------------------
|
||||
-- log_test13 end --------------------------------------------------------
|
||||
-- log_test15 begin --------------------------------------------------------
|
||||
-- log_test15 end --------------------------------------------------------
|
||||
@@ -0,0 +1,60 @@
|
||||
[loggers]
|
||||
keys=root,log02,log03,log04,log05
|
||||
|
||||
[handlers]
|
||||
keys=hand01
|
||||
|
||||
[formatters]
|
||||
keys=form01
|
||||
|
||||
[logger_root]
|
||||
level=WARN
|
||||
propagate=1
|
||||
channel=
|
||||
parent=
|
||||
qualname=(root)
|
||||
handlers=hand01
|
||||
|
||||
[logger_log02]
|
||||
level=WARN
|
||||
propagate=1
|
||||
channel=A
|
||||
parent=(root)
|
||||
qualname=A
|
||||
handlers=
|
||||
|
||||
[logger_log03]
|
||||
level=WARN
|
||||
propagate=1
|
||||
channel=B
|
||||
parent=log02
|
||||
qualname=A.B
|
||||
handlers=
|
||||
|
||||
[logger_log04]
|
||||
level=WARN
|
||||
propagate=1
|
||||
channel=C
|
||||
parent=log03
|
||||
qualname=A.B.C
|
||||
handlers=
|
||||
|
||||
[logger_log05]
|
||||
level=WARN
|
||||
propagate=1
|
||||
channel=D
|
||||
parent=log04
|
||||
qualname=A.B.C.D
|
||||
handlers=
|
||||
|
||||
[handler_hand01]
|
||||
class=StreamHandler
|
||||
level=NOTSET
|
||||
formatter=form01
|
||||
stream=sys.stderr
|
||||
args=(sys.stderr,)
|
||||
|
||||
[formatter_form01]
|
||||
format=warn.ini %(name)s %(levelname)s %(message)s
|
||||
datefmt=
|
||||
|
||||