Package library :: Package pyjamas :: Package logging
[hide private]
[frames] | no frames]

Source Code for Package library.pyjamas.logging

 1  """ 
 2  Logging module for Pyjamas, mimicking CPython's logging module. 
 3   
 4  Usage example:: 
 5   
 6      from pyjamas import logging 
 7      log = logging.getConsoleLogger() 
 8      log.debug('This is a debug message') 
 9  """ 
10  __author__ = 'Peter Bittner <peter.bittner@gmx.net>' 
11   
12  from pyjamas.logging.handlers import \ 
13      AlertHandler, AppendHandler, ConsoleHandler, NullHandler 
14  # blatantly copy everything from CPython's logging (was: `from logging import *` replaced due to Python 2.6 issues) 
15  from logging import getLogger, Formatter, StreamHandler, DEBUG, BASIC_FORMAT 
16   
17  # a handy replacement for BASIC_FORMAT printing nothing but the plain text 
18  PLAIN_FORMAT = '%(message)s' 
19   
20 -def getLoggerForHandler(handler, name=__name__, level=DEBUG, fmt=BASIC_FORMAT):
21 """Use this function to easily include new loggers in your application, 22 e.g. <code>log = logging.getLoggerForHandler(NullHandler())</code>""" 23 formatter = Formatter(fmt) 24 handler.setFormatter(formatter) 25 logger = getLogger(name) 26 logger.setLevel(level) 27 logger.addHandler(handler) 28 return logger
29
30 -def getAlertLogger(name=__name__, level=DEBUG, fmt=BASIC_FORMAT):
31 """A logger that shows any log message in a browser's alert popup dialog.""" 32 return getLoggerForHandler(AlertHandler(), name, level, fmt)
33
34 -def getAppendLogger(name=__name__, level=DEBUG, fmt=BASIC_FORMAT):
35 """A logger that appends text to the end of the HTML document body.""" 36 return getLoggerForHandler(AppendHandler(name), name, level, fmt)
37
38 -def getConsoleLogger(name=__name__, level=DEBUG, fmt=BASIC_FORMAT):
39 """A logger that uses Firebug's console.log() function.""" 40 return getLoggerForHandler(ConsoleHandler(), name, level, fmt)
41
42 -def getNullLogger(name=__name__, level=DEBUG, fmt=BASIC_FORMAT):
43 """A logger that does nothing. Use it to disable logging.""" 44 return getLoggerForHandler(NullHandler(), name, level, fmt)
45
46 -def getPrintLogger(name=__name__, level=DEBUG, fmt=BASIC_FORMAT):
47 """A logger that prints text to cerr, the default error output stream.""" 48 return getLoggerForHandler(StreamHandler(), name, level, fmt)
49