paulbaumgart edited this page Aug 12, 2010 · 8 revisions


CPLog is a generic logging facility, along with logging “providers” for browsers as well as command line tools.

Log Levels

The log levels are (in order): “fatal”, “error”, “warn”, “info”, “debug”, “trace”

You can log at each level by using CPLog.(message). For example: CPLog.debug(@"doing something buggy");

Log Providers

  • CPLogPopup – For browsers, pops up an interactive log display with numerous options.
  • CPLogConsole – For browsers with a window.console object (Firefox, Safari, Chrome, Opera?), prints to console.error, console.warn, etc.
  • CPLogAlert – For browsers, brings up an alert (blocking execution). Allows you to cancel all future CPLogAlerts until reloading application.
  • CPLogPrint – For command line applications, prints to stdout. Currently colorizes the logs (red for “fatal”, yellow for “error”, etc)

Registering log providers

To register a logging provider, call one of the following functions

  • CPLogRegister(aProvider, aMaxLevel) // registers for log levels up to a max level (passed in as a string) or all log levels if no max is provided.
  • CPLogRegisterRange(aProvider, aMinLevel, aMaxLevel) // registers for for a range of log levels (passed in as strings)
  • CPLogRegisterSingle(aProvider, aLevel) // registers for a single log level

For example, to register CPLogPopup for all log levels:


Writing your own provider

The interface for log providers is very simple:
var MyLogProvider = function (aMessage, aLevel, aTitle) { /* logging logic */ }