Taa-taa!

Pyjamas now has a flexible logging module. I just pushed the code.

The pyjamas.logging module builds upon CPython's logging module. This
means that the new module supports the whole features set of the
Python logging module, as described in the Python module documentation
[1]. The Pyjamas logging module provides 3 new handlers (as of today)
to print out log messages:

[1] http://docs.python.org/library/logging.html

  1) AlertHandler ... show messages a window.popup() dialog
  2) AppendHandler ... append messages to the end of document body
  3) ConsoleHandler ... print messages using Firebug's console.log() function

For your convenience the module provides 4 utility getters:

  - pyjamas.logging.getAlertLogger()
  - pyjamas.logging.getAppendLogger()
  - pyjamas.logging.getConsoleLogger()
  - pyjamas.logging.getPrintLogger() ... a logger printing to cerr
(error output stream)

Using the logging facility is easy, e.g.

    from pyjamas import logging
    log = logging.getPrintLogger()
    ...
    log.debug('This is a debug message')

There are 5 log levels (DEBUG, INFO, WARNING, ERROR, CRITICAL) and
their respective methods for logging a message (see [1] above). The
default log level is set to DEBUG (I felt this helps avoiding
misunderstandings), so "everything" you log is spit out. You can set
the level to a higher value, e.g. logging.ERROR, to print out regular
and critical errors only, at the same time leaving the log statements
as they are in the code.

I have replaced the print statements in doc/pyjs_site/website.py by
logger calls, check out this example!

TODO:
  * ConsoleHandler is not fully functional: The JS(...) function
requires the argument being a string constant. Unfortunately the log
messages aren't constant strings at compile time. This is the error
message:

    [...]
    translator_proto.TranslationError: pyjamas.logging.handlers line 49:
    JS function only supports constant strings
    CallFunc(Name('JS'), [Mod(Const(" console.log('%s') "),
Name('msg'))], None, None)

Any ideas how to fix this?

Cheers, Peter


2012/3/12 lkcl luke <[email protected]>:
> On Sun, Mar 11, 2012 at 11:55 PM, Peter Bittner <[email protected]> wrote:
>> Two new bug reports:
>>
>>  #700.) http://code.google.com/p/pyjamas/issues/detail?id=700
>>  #701.) http://code.google.com/p/pyjamas/issues/detail?id=701
>
>  *thumbs-up*
>
>> :-)

Reply via email to