pyjs FAQ

Contents

I have made changes to a pyjs source file. How do I submit my contribution?

Contributions are very welcome! For all source changes use the workflows provided by GitHub: Fork the project, apply your changes, make a pull request. See the website's Contribute page for more details.

I want to throw some debug output onto the screen. How do I best do that?

With pyjs you can use full Python-style logging (Python's flexible event logging module has been ported to pyjs). Additional handlers allow you to display log messages in a dedicated div element in the HTML document, in the Web browser's error console, and with JavaScript's alert() function.

from pyjamas import logging
log = logging.getConsoleLogger()   # other loggers: Alert, Append, Print ...
...
log.error("Hello, here is an %s error", err_name)

For a good understanding of the logging module read the Python Logging HOWTO; most of it directly applies to pyjs. Additional Loggers provided by pyjs, and how you'd use them:

  1. AlertLogger: log = logging.getAlertLogger() shows a browser alert popup dialog for each log message.
  2. AppendLogger: log = logging.getAppendLogger() appends text to the end of the HTML document body. The div element holding the log messages can be accessed by its element ID ('logging_*loggername*', 'logging_pyjs' by default) for styling.
  3. ConsoleLogger: log = logging.getConsoleLogger() passes log messages on to the error console of Firebug/Chrome/Opera/IE8+ using the console logging functions.
  4. PrintLogger: log = logging.getPrintLogger() prints text to cerr, the default error output stream. This is a good choice when developing/testing with pyjs Desktop.
  5. NullLogger: log = logging.getNullLogger() disable logging completely and safely.