debuggers.hg

view tools/python/logging/logging-0.4.9.2/test/log_test0.py @ 0:7d21f7218375

Exact replica of unstable on 051908 + README-this
author Mukesh Rathor
date Mon May 19 15:34:57 2008 -0700 (2008-05-19)
parents
children dae98734f12e
line source
1 #!/usr/bin/env python
2 #
3 # Copyright 2001-2002 by Vinay Sajip. All Rights Reserved.
4 #
5 # Permission to use, copy, modify, and distribute this software and its
6 # documentation for any purpose and without fee is hereby granted,
7 # provided that the above copyright notice appear in all copies and that
8 # both that copyright notice and this permission notice appear in
9 # supporting documentation, and that the name of Vinay Sajip
10 # not be used in advertising or publicity pertaining to distribution
11 # of the software without specific, written prior permission.
12 # VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
13 # ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
14 # VINAY SAJIP BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
15 # ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
16 # IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
17 # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #
19 # This file is part of the Python logging distribution. See
20 # http://www.red-dove.com/python_logging.html
21 #
22 """Test harness for the logging module. A basic test of levels.
24 Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
25 """
27 import logging
28 msgcount = 0
30 def nextmessage():
31 global msgcount
32 rv = "Message %d" % msgcount
33 msgcount = msgcount + 1
34 return rv
36 def main():
37 logging.basicConfig()
38 logging.getLogger("").setLevel(logging.DEBUG)
39 ERR = logging.getLogger("ERR")
40 ERR.setLevel(logging.ERROR)
41 INF = logging.getLogger("INF")
42 INF.setLevel(logging.INFO)
43 INF_ERR = logging.getLogger("INF.ERR")
44 INF_ERR.setLevel(logging.ERROR)
45 DEB = logging.getLogger("DEB")
46 DEB.setLevel(logging.DEBUG)
48 INF_UNDEF = logging.getLogger("INF.UNDEF")
49 INF_ERR_UNDEF = logging.getLogger("INF.ERR.UNDEF")
50 UNDEF = logging.getLogger("UNDEF")
52 GRANDCHILD = logging.getLogger("INF.BADPARENT.UNDEF")
53 CHILD = logging.getLogger("INF.BADPARENT")
55 #These should log
56 ERR.log(logging.CRITICAL, nextmessage())
57 ERR.error(nextmessage())
59 INF.log(logging.CRITICAL, nextmessage())
60 INF.error(nextmessage())
61 INF.warning(nextmessage())
62 INF.info(nextmessage())
64 INF_UNDEF.log(logging.CRITICAL, nextmessage())
65 INF_UNDEF.error(nextmessage())
66 INF_UNDEF.warning(nextmessage())
67 INF_UNDEF.info(nextmessage())
69 INF_ERR.log(logging.CRITICAL, nextmessage())
70 INF_ERR.error(nextmessage())
72 INF_ERR_UNDEF.log(logging.CRITICAL, nextmessage())
73 INF_ERR_UNDEF.error(nextmessage())
75 DEB.log(logging.CRITICAL, nextmessage())
76 DEB.error(nextmessage())
77 DEB.warning(nextmessage())
78 DEB.info(nextmessage())
79 DEB.debug(nextmessage())
81 UNDEF.log(logging.CRITICAL, nextmessage())
82 UNDEF.error(nextmessage())
83 UNDEF.warning(nextmessage())
84 UNDEF.info(nextmessage())
86 GRANDCHILD.log(logging.CRITICAL, nextmessage())
87 CHILD.log(logging.CRITICAL, nextmessage())
89 #These should not log
90 ERR.warning(nextmessage())
91 ERR.info(nextmessage())
92 ERR.debug(nextmessage())
94 INF.debug(nextmessage())
95 INF_UNDEF.debug(nextmessage())
97 INF_ERR.warning(nextmessage())
98 INF_ERR.info(nextmessage())
99 INF_ERR.debug(nextmessage())
100 INF_ERR_UNDEF.warning(nextmessage())
101 INF_ERR_UNDEF.info(nextmessage())
102 INF_ERR_UNDEF.debug(nextmessage())
104 INF.info("Messages should bear numbers 0 through 24.")
106 if __name__ == "__main__":
107 import sys
108 #print sys.argv[0]
109 args = sys.argv[1:]
110 if "-profile" in args:
111 import profile, pstats
112 args.remove("-profile")
113 statf = "log_test0.pro"
114 profile.run("main()", statf)
115 stats = pstats.Stats(statf)
116 stats.strip_dirs().sort_stats('time').print_stats()
117 else:
118 main()