~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/log.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20080622211713-inlv5k4eifxckelr
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
"""
89
89
 
90
90
import os
91
 
import logging
92
 
import logging.config
93
 
import logging.handlers  # needed for handlers defined there being configurable in logging.conf file
 
91
import logging, logging.config
94
92
 
95
93
configured = False
96
94
fallback_config = False
97
95
 
98
 
import warnings
99
 
 
100
 
# 'CacheNeedsUpdate' string exception in Page.py is supported for backwards compat reasons:
101
 
warnings.filterwarnings('ignore', r'catching of string exceptions is deprecated', module='MoinMoin.Page')
102
 
 
103
 
# TODO: subprocess was added in python 2.4, we now can refactor the code to use it and remove this:
104
 
warnings.filterwarnings('ignore', r'The popen\d? module is deprecated.  Use the subprocess module.')
105
 
 
106
 
 
107
 
def _log_warning(message, category, filename, lineno, file=None, line=None):
108
 
    # for warnings, we just want to use the logging system, not stderr or other files
109
 
    msg = "%s:%s: %s: %s" % (filename, lineno, category.__name__, message)
110
 
    logger = getLogger(__name__)
111
 
    logger.warning(msg) # Note: the warning will look like coming from here,
112
 
                        # but msg contains info about where it really comes from
113
 
 
114
96
 
115
97
def load_config(conf_fname=None):
116
98
    """ load logging config from conffile """
124
106
            configured = True
125
107
            l = getLogger(__name__)
126
108
            l.info('using logging configuration read from "%s"' % conf_fname)
127
 
            warnings.showwarning = _log_warning
128
109
        except Exception, err: # XXX be more precise
129
110
            err_msg = str(err)
130
111
    if not configured:
137
118
        if err_msg:
138
119
            l.warning('load_config for "%s" failed with "%s".' % (conf_fname, err_msg))
139
120
        l.warning('using logging configuration read from built-in fallback in MoinMoin.log module!')
140
 
        warnings.showwarning = _log_warning
141
121
 
142
122
 
143
123
def getLogger(name):
154
134
            setattr(logger, levelname, levelnumber)
155
135
    return logger
156
136
 
 
137
 
 
138
# Python 2.3's logging module has no .log, this provides it:
 
139
if not hasattr(logging, 'log'):
 
140
    def log(level, msg, *args, **kwargs):
 
141
        if len(logging.root.handlers) == 0:
 
142
            logging.basicConfig()
 
143
        if logging.root.manager.disable >= level:
 
144
            return
 
145
        if level >= logging.root.getEffectiveLevel():
 
146
            logging.root._log(level, msg, args, **kwargs)
 
147
    logging.log = log
 
148