コード例 #1
0
ファイル: test.py プロジェクト: mila/spadl
 def setUp(self):
     # Configure Python logging
     logger = logging.getLogger()
     self.origLevel, logger.level = logger.level, logging.NOTSET
     self.handlers = []
     # Configure DbgLog
     self.origLogMask = dbg.getLogMask()
     dbg.logMask('F1E1W1I1D1')
     self.origLogFile = dbg.getLogFile()
     self.filename = tempfile.mktemp(suffix='.log')
     dbg.logFile(self.filename)
コード例 #2
0
ファイル: test.py プロジェクト: seifert/spadl
 def setUp(self):
     # Configure Python logging
     logger = logging.getLogger()
     self.origLevel, logger.level = logger.level, logging.NOTSET
     self.handlers = []
     # Configure DbgLog
     self.origLogMask = dbg.getLogMask()
     dbg.logMask("F1E1W1I1D1")
     self.origLogFile = dbg.getLogFile()
     self.filename = tempfile.mktemp(suffix=".log")
     dbg.logFile(self.filename)
コード例 #3
0
ファイル: test.py プロジェクト: mila/spadl
 def tearDown(self):
     # Restore Python logging configuration
     logger = logging.getLogger()
     logger.level = self.origLevel
     for handler in self.handlers:
         logger.removeHandler(handler)
     # Restore DbgLog configuration
     dbg.logMask(self.origLogMask)
     dbg.logFile(self.origLogFile or '')
     try:
         os.remove(self.filename)
     except EnvironmentError:
         pass
コード例 #4
0
ファイル: test.py プロジェクト: seifert/spadl
 def tearDown(self):
     # Restore Python logging configuration
     logger = logging.getLogger()
     logger.level = self.origLevel
     for handler in self.handlers:
         logger.removeHandler(handler)
     # Restore DbgLog configuration
     dbg.logMask(self.origLogMask)
     dbg.logFile(self.origLogFile or "")
     try:
         os.remove(self.filename)
     except EnvironmentError:
         pass
コード例 #5
0
ファイル: example.py プロジェクト: mila/spadl
    # Specification of the default severity. If was not present here then
    # the default behaviour would be to ignore records from unknown loggers.
    '': 1,
}, level=logging.DEBUG)


# Configure DbgLog.
#
# Messages are written to error output for demonstration purposes
# but any DbgLog configuration is possible.
dbg.logStderr(True)
# It is a good idea to set a low DbgLog mask and filter records
# using standard logging levels. The effective logging levels can be
# easily checked using the `logging.Logger.isEnabledFor` method but
# testing DbgLog mask is insufficient if there are other logging handlers.
dbg.logMask('F1E1W1I1D1')


def demo():
    logging.debug('Hello world, this is logged as D1.')
    logging.getLogger('app.server').info('This application message is I4.')
    logging.getLogger('app.request').warning('But this message is W3.')
    logging.getLogger('rpc.stats').error('This is configured as E2.')
    logging.getLogger('db.connection').fatal('Level of this defaults to F1.')
    logging.getLogger('db.sql').debug('This is ignored and lost forever.')
    logging.log(25, 'Custom level is not a problem.')
    try:
        infinity = 1 / 0
    except ZeroDivisionError:
        logging.exception('Exceptions are logged too.')
    logging.getLogger('app').info('The last message must be %s!', 'GOOD')
コード例 #6
0
ファイル: example.py プロジェクト: mila/spadl
        # Specification of the default severity. If was not present here then
        # the default behaviour would be to ignore records from unknown loggers.
        '': 1,
    },
    level=logging.DEBUG)

# Configure DbgLog.
#
# Messages are written to error output for demonstration purposes
# but any DbgLog configuration is possible.
dbg.logStderr(True)
# It is a good idea to set a low DbgLog mask and filter records
# using standard logging levels. The effective logging levels can be
# easily checked using the `logging.Logger.isEnabledFor` method but
# testing DbgLog mask is insufficient if there are other logging handlers.
dbg.logMask('F1E1W1I1D1')


def demo():
    logging.debug('Hello world, this is logged as D1.')
    logging.getLogger('app.server').info('This application message is I4.')
    logging.getLogger('app.request').warning('But this message is W3.')
    logging.getLogger('rpc.stats').error('This is configured as E2.')
    logging.getLogger('db.connection').fatal('Level of this defaults to F1.')
    logging.getLogger('db.sql').debug('This is ignored and lost forever.')
    logging.log(25, 'Custom level is not a problem.')
    try:
        infinity = 1 / 0
    except ZeroDivisionError:
        logging.exception('Exceptions are logged too.')
    logging.getLogger('app').info('The last message must be %s!', 'GOOD')