~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/services/twistedsupport/loggingsupport.py

  • Committer: Julian Edwards
  • Date: 2011-02-23 15:16:38 UTC
  • mfrom: (12392.7.32 twisted-ftp-poppy)
  • mto: This revision was merged to the branch mainline in revision 12470.
  • Revision ID: julian.edwards@canonical.com-20110223151638-8cw0twgnyx2a8c0y
merge parent branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
    'log_oops_from_failure',
13
13
    'set_up_logging_for_script',
14
14
    'set_up_oops_reporting',
 
15
    'set_up_tacfile_logging',
15
16
    ]
16
17
 
17
18
 
75
76
    return logger_object
76
77
 
77
78
 
 
79
def set_up_tacfile_logging(name, level):
 
80
    """Create a `Logger` object for use in tac files.
 
81
 
 
82
    This is preferable to use over `set_up_logging_for_script` for .tac
 
83
    files since there's no options to pass through.  The logger object
 
84
    is connected to Twisted's log and returned.
 
85
 
 
86
    :param name: The logger instance name.
 
87
    :param level: The log level to use, eg. logging.INFO or logging.DEBUG
 
88
    """
 
89
    logger = logging.getLogger(name)
 
90
    channel = logging.StreamHandler(log.StdioOnnaStick())
 
91
    channel.setLevel(level)
 
92
    channel.setFormatter(logging.Formatter('%(message)s'))
 
93
    logger.addHandler(channel)
 
94
    logger.setLevel(level)
 
95
    return logger
 
96
 
 
97
 
78
98
def set_up_oops_reporting(configuration, name, mangle_stdout=True):
79
99
    """Set up OOPS reporting by starting the Twisted logger with an observer.
80
100
 
188
208
        self.request_count += 1
189
209
        self.logger.log(
190
210
            self.level, 'Sending request [%d]: %s%s', request, method, args)
 
211
 
191
212
        def _logResult(result):
192
213
            self.logger.log(
193
214
                self.level, 'Reply to request [%d]: %s', request, result)