~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/testing/logger.py

  • Committer: Tim Penhey
  • Date: 2010-12-15 02:53:37 UTC
  • mto: This revision was merged to the branch mainline in revision 12116.
  • Revision ID: tim.penhey@canonical.com-20101215025337-eu5dqoqh7n0ae422
Log the recipes that are having daily builds requested.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
"""Frequently-used logging utilities for test suite."""
5
5
 
6
6
__metaclass__ = type
7
 
__all__ = ['MockLogger']
 
7
__all__ = [
 
8
    'MockLogger',
 
9
    'TestLogger',
 
10
    ]
8
11
 
9
12
import logging
10
13
import sys
63
66
 
64
67
    def exception(self, *args):
65
68
        self.log(*args, **{'exc_info': True})
 
69
 
 
70
 
 
71
class TestLogger:
 
72
    """Imitates a logger, but records output."""
 
73
 
 
74
    def __init__(self, outfile=None):
 
75
        self.output = []
 
76
 
 
77
    def log(self, prefix, msg, *args):
 
78
        # The standard logger takes a template string as the first
 
79
        # argument, but we must only attempt to use it as one if we have
 
80
        # arguments. Otherwise logging of messages with string formatting
 
81
        # sequences will die.
 
82
        if len(args) > 0:
 
83
            msg %= args
 
84
        self.output.append('%s %s' % (prefix, msg))
 
85
 
 
86
    def debug(self, *args):
 
87
        self.log('DEBUG', *args)