~ubuntu-branches/ubuntu/dapper/xen/dapper

« back to all changes in this revision

Viewing changes to tools/python/logging/logging-0.4.9.2/test/log_test15.py

  • Committer: Bazaar Package Importer
  • Author(s): Adam Heath
  • Date: 2005-07-06 12:35:50 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050706123550-9yx08wy5jdxmsxfq
Tags: 2.0.6-1
* Patches applied upstream: non-xen-init-exit.patch, add-build.patch,
  python-install.patch, disable-html-docs.patch.
* New upstream released.  Closes: #311336.
* Remove comparison to UML from xen short description.  Closes: #317066.
* Make packages conflicts with 1.2 doc debs.  Closes: #304285.
* Add iproute to xen depends, as it uses /bin/ip.  Closes: #300488,
  #317468.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
"""
 
23
A test harness for the logging module. Tests Filter.
 
24
 
 
25
Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
 
26
"""
 
27
 
 
28
import sys, logging
 
29
 
 
30
FILTER = "a.b"
 
31
 
 
32
def message(s):
 
33
    sys.stderr.write("%s\n" % s)
 
34
 
 
35
def doLog():
 
36
    logging.getLogger("a").info("Info 1")
 
37
    logging.getLogger("a.b").info("Info 2")
 
38
    logging.getLogger("a.c").info("Info 3")
 
39
    logging.getLogger("a.b.c").info("Info 4")
 
40
    logging.getLogger("a.b.c.d").info("Info 5")
 
41
    logging.getLogger("a.bb.c").info("Info 6")
 
42
    logging.getLogger("b").info("Info 7")
 
43
    logging.getLogger("b.a").info("Info 8")
 
44
    logging.getLogger("c.a.b").info("Info 9")
 
45
    logging.getLogger("a.bb").info("Info 10")
 
46
 
 
47
def test(fs):
 
48
    root = logging.getLogger()
 
49
    root.setLevel(logging.DEBUG)
 
50
    if __name__ == "__main__":
 
51
        hand = logging.StreamHandler()
 
52
        hand.setFormatter(logging.Formatter("%(name)-10s %(message)s"))
 
53
        root.addHandler(hand)
 
54
    else:
 
55
        hand = root.handlers[0]
 
56
    message("Unfiltered...")
 
57
    doLog()
 
58
    message("Filtered with '%s'..." % fs)
 
59
    filt = logging.Filter(fs)
 
60
    hand.addFilter(filt)
 
61
    doLog()
 
62
    hand.removeFilter(filt)
 
63
 
 
64
if __name__ == "__main__":
 
65
    import sys
 
66
    if len(sys.argv) > 1:
 
67
        fs = sys.argv[1]
 
68
    else:
 
69
        fs = FILTER
 
70
    test(fs)