Logging

Jaxer's logging capability is a useful tool for debugging errors during development and testing as well as capturing errors and warnings once your application goes into production. The Jaxer log file is located at Aptana_Jaxer/logs/jaxer.log.

Adding a log entry can be as simple as:

Jaxer.Log.debug("value: " + value);
Jaxer.Log.forModule("my-app").debug("value: " + value);

Logging Levels

Entries are logged based on significance and Jaxer's logging system can be specified to only capture entries at that level or higher. Jaxer.Log.getLevel returns a LogLevel object which you can use to find out if a given log object's level is at least, at most or less than a given level. The available log levels are, in order of severity:

  1. FATAL
  2. ERROR
  3. WARN
  4. INFO
  5. DEBUG
  6. TRACE

Calling Jaxer.Log.setLevel("ERROR") indicates that only errors including fatal errors will be logged - and not warning, info, debug or trace entries.

Logging per Module

Jaxer.Log.ModuleLogger has all the same capabilities as Jaxer.Log but enables you to set up logging differently for a specific module than for the application as a whole. This object is created by calling Jaxer.Log.forModule with the module name as parameter; you can check whether a module is being logged separately through Jaxer.Log.hasModule and reset the log level for all modules with Jaxer.Log.setAllModuleLevels.

Stack Traces

Finding out just where your code went wrong is simplified by Jaxer.Log.getStackTrace, which returns the current JavaScript stack trace as a string you can then log. You can specify a string to insert at the beginning of each line, such as whitespace to make the trace more readable, as well as the number of frames to skip before starting to trace the remaining frames.

Because the trace is a string you may also parse and examine it programmatically, enabling you to respond differently to specific errors.

Writing to the Log

Jaxer.Log includes convenience functions that write any information you send into a log file at any of the levels (rather than having one function called, say, log that requires a level parameter), e.g., Jaxer.Log.fatal() and Jaxer.Log.info().

Logging Configuration

Out of the box, when an error occurs, Jaxer will not reveal the error details in the HTML page. This behavior can be modified in the file at Aptana_Jaxer/local_jaxer/conf/config.js:

  • Uncomment Config.DEV_MODE = true; or
  • Set Config.DISPLAY_ERRORS = true;

Viewing the Log in Studio

If you're writing and testing code with Aptana Studio, you can view the Jaxer log by choosing Jaxer Internal Server Log from the Jaxer menu button in the Studio toolbar. This opens a TailView, which displays the tail view of the log file.