annotate MoinMoin/log.py @ 3579:ff4afe930cb2

logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 11 May 2008 22:38:06 +0200
parents cd43bbf56c33
children 27ba7445b480
rev   line source
3112
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
2 """
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
3 MoinMoin - init "logging" system
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
4
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
5 WARNING
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
6 -------
3579
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
7 logging must be configured VERY early, before the code in log.getLogger
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
8 gets executed. Thus, logging is configured either by:
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
9 a) an environment variable MOINLOGGINGCONF that contains the path/filename
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
10 of a logging configuration file - this method overrides all following
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
11 methods (except if it can't read or use that configuration, then it
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
12 will use c))
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
13 b) by an explicit call to MoinMoin.log.load_config('logging.conf') -
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
14 you need to do this very early or a) or c) will happen before
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
15 c) by using a builtin fallback logging conf
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
16
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
17 If logging is not yet configured, log.getLogger will do an implicit
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
18 configuration call - then a) or c) is done.
3112
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
19
3505
cd43bbf56c33 logging: removed logging to ./moin.log from fallback config, better docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3487
diff changeset
20 Usage (for wiki server admins)
cd43bbf56c33 logging: removed logging to ./moin.log from fallback config, better docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3487
diff changeset
21 ------------------------------
3579
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
22 Either use something like this in some shell script:
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
23 MOINLOGGINGCONF=/path/to/logging.conf
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
24 export MOINLOGGINGCONF
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
25
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
26 Or, modify your server adaptor script (e.g. moin.cgi) to do this:
3505
cd43bbf56c33 logging: removed logging to ./moin.log from fallback config, better docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3487
diff changeset
27
cd43bbf56c33 logging: removed logging to ./moin.log from fallback config, better docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3487
diff changeset
28 from MoinMoin import log
cd43bbf56c33 logging: removed logging to ./moin.log from fallback config, better docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3487
diff changeset
29 log.load_config('wiki/config/logging/logfile') # XXX please fix this path!
cd43bbf56c33 logging: removed logging to ./moin.log from fallback config, better docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3487
diff changeset
30
cd43bbf56c33 logging: removed logging to ./moin.log from fallback config, better docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3487
diff changeset
31 You have to fix that path to use a logging configuration matching your
cd43bbf56c33 logging: removed logging to ./moin.log from fallback config, better docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3487
diff changeset
32 needs (we provide some examples in the path given there, it is relative to
cd43bbf56c33 logging: removed logging to ./moin.log from fallback config, better docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3487
diff changeset
33 the uncompressed moin distribution archive - if you use some moin package,
cd43bbf56c33 logging: removed logging to ./moin.log from fallback config, better docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3487
diff changeset
34 you maybe find it under /usr/share/moin/).
cd43bbf56c33 logging: removed logging to ./moin.log from fallback config, better docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3487
diff changeset
35 It is likely that you also have to edit the sample logging configurations
cd43bbf56c33 logging: removed logging to ./moin.log from fallback config, better docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3487
diff changeset
36 we provide (e.g. to fix the logfile location).
cd43bbf56c33 logging: removed logging to ./moin.log from fallback config, better docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3487
diff changeset
37
cd43bbf56c33 logging: removed logging to ./moin.log from fallback config, better docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3487
diff changeset
38 Usage (for developers)
cd43bbf56c33 logging: removed logging to ./moin.log from fallback config, better docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3487
diff changeset
39 ----------------------
cd43bbf56c33 logging: removed logging to ./moin.log from fallback config, better docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3487
diff changeset
40 If you write code for moin, do this at top of your module:
3112
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
41
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
42 from MoinMoin import log
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
43 logging = log.getLogger(__name__)
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
44
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
45 This will create a logger with 'MoinMoin.your.module' as name.
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
46 The logger can optionally get configured in the logging configuration.
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
47 If you don't configure it, some upperlevel logger (e.g. the root logger)
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
48 will do the logging.
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
49
3165
b8dc6c2e6c53 integrate MoinMoin.support.logging_fix into MoinMoin.log
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3112
diff changeset
50 @copyright: 2008 MoinMoin:ThomasWaldmann,
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3165
diff changeset
51 2007 MoinMoin:JohannesBerg
3112
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
52 @license: GNU GPL, see COPYING for details.
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
53 """
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
54
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
55 # This is the "last resort" fallback logging configuration for the case
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
56 # that load_config() is either not called at all or with a non-working
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
57 # logging configuration.
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
58 # See http://www.python.org/doc/lib/logging-config-fileformat.html
3505
cd43bbf56c33 logging: removed logging to ./moin.log from fallback config, better docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3487
diff changeset
59 # We just use stderr output by default, if you want anything else,
cd43bbf56c33 logging: removed logging to ./moin.log from fallback config, better docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3487
diff changeset
60 # you will have to configure logging.
3112
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
61 logging_defaults = {
3487
71b403707c1d use INFO loglevel in fallback logging config
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3204
diff changeset
62 'loglevel': 'INFO',
3112
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
63 }
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
64 logging_config = """\
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
65 [loggers]
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
66 keys=root
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
67
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
68 [handlers]
3505
cd43bbf56c33 logging: removed logging to ./moin.log from fallback config, better docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3487
diff changeset
69 keys=stderr
3112
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
70
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
71 [formatters]
3505
cd43bbf56c33 logging: removed logging to ./moin.log from fallback config, better docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3487
diff changeset
72 keys=default
3112
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
73
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
74 [logger_root]
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
75 level=%(loglevel)s
3505
cd43bbf56c33 logging: removed logging to ./moin.log from fallback config, better docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3487
diff changeset
76 handlers=stderr
3112
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
77
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
78 [handler_stderr]
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
79 class=StreamHandler
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
80 level=NOTSET
3505
cd43bbf56c33 logging: removed logging to ./moin.log from fallback config, better docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3487
diff changeset
81 formatter=default
3112
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
82 args=(sys.stderr, )
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
83
3505
cd43bbf56c33 logging: removed logging to ./moin.log from fallback config, better docs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3487
diff changeset
84 [formatter_default]
3112
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
85 format=%(asctime)s %(levelname)s %(name)s:%(lineno)d %(message)s
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
86 datefmt=
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
87 class=logging.Formatter
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
88 """
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
89
3579
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
90 import os
3112
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
91 import logging, logging.config
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
92
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
93 configured = False
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
94 fallback_config = False
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
95
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
96
3579
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
97 def load_config(conf_fname=None):
3112
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
98 """ load logging config from conffile """
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
99 global configured
3579
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
100 err_msg = None
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
101 conf_fname = os.environ.get('MOINLOGGINGCONF', conf_fname)
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
102 if conf_fname:
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
103 try:
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
104 conf_fname = os.path.abspath(conf_fname)
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
105 logging.config.fileConfig(conf_fname)
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
106 configured = True
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
107 l = getLogger(__name__)
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
108 l.info('using logging configuration read from "%s"' % conf_fname)
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
109 except Exception, err: # XXX be more precise
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
110 err_msg = str(err)
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
111 if not configured:
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
112 # load builtin fallback logging config
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
113 from StringIO import StringIO
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
114 config_file = StringIO(logging_config)
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
115 logging.config.fileConfig(config_file, logging_defaults)
3112
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
116 configured = True
3579
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
117 l = getLogger(__name__)
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
118 if err:
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
119 l.warning('load_config for "%s" failed with "%s".' % (conf_fname, err_msg))
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
120 l.warning('using logging configuration read from built-in fallback in MoinMoin.log module!')
3112
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
121
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
122
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
123 def getLogger(name):
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
124 """ wrapper around logging.getLogger, so we can do some more stuff:
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
125 - preprocess logger name
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
126 - patch loglevel constants into logger object, so it can be used
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
127 instead of the logging module
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
128 """
3579
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
129 if not configured:
ff4afe930cb2 logging configuration: you can use MOINLOGGINGCONF env var now to override from where your logging conf is read, fix wikiserverlogging.conf to not create empty moin.log files
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3505
diff changeset
130 load_config()
3112
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
131 logger = logging.getLogger(name)
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
132 for levelnumber, levelname in logging._levelNames.items():
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
133 if isinstance(levelnumber, int): # that list has also the reverse mapping...
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
134 setattr(logger, levelname, levelnumber)
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
135 return logger
dc182f4936b1 logging: add missing file for previous changeset 79f850129782)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
136
3165
b8dc6c2e6c53 integrate MoinMoin.support.logging_fix into MoinMoin.log
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3112
diff changeset
137
b8dc6c2e6c53 integrate MoinMoin.support.logging_fix into MoinMoin.log
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3112
diff changeset
138 # Python 2.3's logging module has no .log, this provides it:
b8dc6c2e6c53 integrate MoinMoin.support.logging_fix into MoinMoin.log
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3112
diff changeset
139 if not hasattr(logging, 'log'):
b8dc6c2e6c53 integrate MoinMoin.support.logging_fix into MoinMoin.log
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3112
diff changeset
140 def log(level, msg, *args, **kwargs):
b8dc6c2e6c53 integrate MoinMoin.support.logging_fix into MoinMoin.log
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3112
diff changeset
141 if len(logging.root.handlers) == 0:
b8dc6c2e6c53 integrate MoinMoin.support.logging_fix into MoinMoin.log
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3112
diff changeset
142 logging.basicConfig()
b8dc6c2e6c53 integrate MoinMoin.support.logging_fix into MoinMoin.log
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3112
diff changeset
143 if logging.root.manager.disable >= level:
b8dc6c2e6c53 integrate MoinMoin.support.logging_fix into MoinMoin.log
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3112
diff changeset
144 return
b8dc6c2e6c53 integrate MoinMoin.support.logging_fix into MoinMoin.log
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3112
diff changeset
145 if level >= logging.root.getEffectiveLevel():
b8dc6c2e6c53 integrate MoinMoin.support.logging_fix into MoinMoin.log
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3112
diff changeset
146 logging.root._log(level, msg, args, **kwargs)
b8dc6c2e6c53 integrate MoinMoin.support.logging_fix into MoinMoin.log
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3112
diff changeset
147 logging.log = log
b8dc6c2e6c53 integrate MoinMoin.support.logging_fix into MoinMoin.log
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3112
diff changeset
148