Skip to content

Commit

Permalink
logging: added Deprecation error, added PLAIN_FORMAT, removed PYJS_NAME
Browse files Browse the repository at this point in the history
  • Loading branch information
bittner committed Apr 9, 2012
1 parent ccdd736 commit 4594990
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
20 changes: 19 additions & 1 deletion library/pyjamas/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,27 @@
version of Python's logging module. You can use Pyjamas' logging directly as
you would with Python, at your option."""

raise DeprecationWarning("""pyjamas.log has been replaced by pyjamas.logging!
Please replace the import of your logging code as follows:
from pyjamas import logging
log = logging.getAppendLogger(__name__, logging.DEBUG, logging.PLAIN_FORMAT)
All occurrences of 'log.write()' and 'log.writebr()' must be replaced by
one of the standard logging functions:
log.debug()
log.info()
log.warning()
log.error()
log.critical()
If you want to continue using pyjamas.log for now remove the raise statement
on top of """ + __file__ + """
See the Pyjamas FAQ at http://pyjs.org#FAQ for more details on logging.""")

from pyjamas import logging

__logger = logging.getAppendLogger(__name__, logging.DEBUG, '%(message)s')
__logger = logging.getAppendLogger(__name__,
logging.DEBUG,
logging.PLAIN_FORMAT)

def setLogger(logger):
"""
Expand Down
15 changes: 8 additions & 7 deletions library/pyjamas/logging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
# blatantly copy everything from CPython's logging
from logging import *

PYJS_NAME = 'pyjs'
# a handy replacement for BASIC_FORMAT printing nothing but the plain text
PLAIN_FORMAT = '%(message)s'

def getLoggerForHandler(handler, name=PYJS_NAME, level=DEBUG, fmt=BASIC_FORMAT):
def getLoggerForHandler(handler, name=__name__, level=DEBUG, fmt=BASIC_FORMAT):
"""Use this function to easily include new loggers in your application,
e.g. <code>log = logging.getLoggerForHandler(NullHandler())</code>"""
formatter = Formatter(fmt)
Expand All @@ -24,23 +25,23 @@ def getLoggerForHandler(handler, name=PYJS_NAME, level=DEBUG, fmt=BASIC_FORMAT):
logger.addHandler(handler)
return logger

def getAlertLogger(name=PYJS_NAME, level=DEBUG, fmt=BASIC_FORMAT):
def getAlertLogger(name=__name__, level=DEBUG, fmt=BASIC_FORMAT):
"""A logger that shows any log message in a browser's alert popup dialog."""
return getLoggerForHandler(AlertHandler(), name, level, fmt)

def getAppendLogger(name=PYJS_NAME, level=DEBUG, fmt=BASIC_FORMAT):
def getAppendLogger(name=__name__, level=DEBUG, fmt=BASIC_FORMAT):
"""A logger that appends text to the end of the HTML document body."""
return getLoggerForHandler(AppendHandler(name), name, level, fmt)

def getConsoleLogger(name=PYJS_NAME, level=DEBUG, fmt=BASIC_FORMAT):
def getConsoleLogger(name=__name__, level=DEBUG, fmt=BASIC_FORMAT):
"""A logger that uses Firebug's console.log() function."""
return getLoggerForHandler(ConsoleHandler(), name, level, fmt)

def getNullLogger(name=PYJS_NAME, level=DEBUG, fmt=BASIC_FORMAT):
def getNullLogger(name=__name__, level=DEBUG, fmt=BASIC_FORMAT):
"""A logger that does nothing. Use it to disable logging."""
return getLoggerForHandler(NullHandler(), name, level, fmt)

def getPrintLogger(name=PYJS_NAME, level=DEBUG, fmt=BASIC_FORMAT):
def getPrintLogger(name=__name__, level=DEBUG, fmt=BASIC_FORMAT):
"""A logger that prints text to cerr, the default error output stream."""
return getLoggerForHandler(StreamHandler(), name, level, fmt)

0 comments on commit 4594990

Please sign in to comment.