source: trunk/packages/xen-3.1/xen-3.1/tools/python/logging/logging-0.4.9.2/test/log_test8.py @ 34

Last change on this file since 34 was 34, checked in by hartmans, 18 years ago

Add xen and xen-common

  • Property svn:executable set to *
  • Property svn:mime-type set to text/script
File size: 2.8 KB
Line 
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"""
23A test harness for the logging module. Tests FileHandler rollover.
24
25Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.
26"""
27import logging, logging.handlers
28import locale
29
30locale.setlocale(locale.LC_ALL, '')
31
32sequence = 0
33
34def doLog(logger):
35    global sequence
36    sequence = sequence + 1
37    logger.debug("%6d This message should be at level %d - %s", sequence,\
38                logging.DEBUG, logging.getLevelName(logging.DEBUG))
39    sequence = sequence + 1
40    logger.info("%6d This message should be at level %d - %s", sequence,
41                logging.INFO, logging.getLevelName(logging.INFO))
42    sequence = sequence + 1
43    logger.warning("%6d This message should be at level %d - %s", sequence,\
44                logging.WARNING, logging.getLevelName(logging.WARNING))
45    sequence = sequence + 1
46    logger.error("%6d This message should be at level %d - %s", sequence,\
47                logging.ERROR, logging.getLevelName(logging.ERROR))
48    sequence = sequence + 1
49    logger.critical("%6d This message should be at level %d - %s", sequence,\
50                logging.CRITICAL, logging.getLevelName(logging.CRITICAL))
51
52def main():
53    logger = logging.getLogger("")  #root logger
54    logger.setLevel(logging.DEBUG)
55    if __name__ == "__main__":
56        logname = "rollover.log"
57    else:
58        logname = "log_test_rollover.log"
59    hdlr = logging.handlers.RotatingFileHandler(logname, "a", 5000, 3)
60    if __name__ == "__main__":
61       fmt = logging.Formatter("%(asctime)s %(levelname)-5s %(message)s", "%x %X")
62       hdlr.setFormatter(fmt)
63    logger.addHandler(hdlr)
64    for i in xrange(100):
65        doLog(logger)
66    logger.removeHandler(hdlr)
67
68if __name__ == "__main__":
69    main()
Note: See TracBrowser for help on using the repository browser.