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. Demonstrates the use of different |
---|
23 | converters for time(secs) -> time(tuple). |
---|
24 | |
---|
25 | Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved. |
---|
26 | """ |
---|
27 | |
---|
28 | import logging, time |
---|
29 | |
---|
30 | def main(): |
---|
31 | handler = logging.StreamHandler() |
---|
32 | f1 = logging.Formatter("%(asctime)s %(message)s", "%m/%d %H:%M:%S") |
---|
33 | f2 = logging.Formatter("%(asctime)s %(message)s", "%m/%d %H:%M:%S") |
---|
34 | f2.converter = time.gmtime |
---|
35 | handler.setFormatter(f1) |
---|
36 | root = logging.getLogger("") |
---|
37 | root.setLevel(logging.DEBUG) |
---|
38 | root.addHandler(handler) |
---|
39 | root.info("Something happened! [should be in local time]") |
---|
40 | handler.setFormatter(f2) |
---|
41 | root.info("Something else happened! [should be in GMT]") |
---|
42 | handler.setFormatter(f1) |
---|
43 | root.info("Something happened again! [should be in local time]") |
---|
44 | logging.Formatter.converter = time.gmtime |
---|
45 | root.info("Something else happened again! [should be in GMT]") |
---|
46 | logging.Formatter.converter = time.localtime |
---|
47 | root.info("Something else happened yet again! [should be in local time]") |
---|
48 | |
---|
49 | if __name__ == "__main__": |
---|
50 | main() |
---|