Hide
Search Results

Logging

Mojito has its own logging system. When you call Y.log from within your mojits, your log messages are intercepted and processed by Mojito. This allows you to create your own log formatting, writing, and publishing functions for both your client and server runtimes. It also allows you to enable log buffering, so performance during crucial runtime periods is not adversely affected.

Log Levels

Mojito has the following five log levels:

  • DEBUG
  • INFO
  • WARN
  • ERROR
  • MOJITO

All of them should be familiar except the last, which are framework-level messages that indicate that an important framework event is occurring (one that users might want to track).

Setting a log level of WARN will filter out all DEBUG and INFO messages, while WARN, ERROR, and MOJITO log messages will be processed. To see all log messages, set the log level to DEBUG.

YUI Library Logs

By default, all log messages generated by the YUI library itself are processed. The log level filter is also applied to these messages, but within the Mojito log output, a “YUI-” identifier is added to them. So when YUI emits a WARN level log message, the Mojito logs will display a YUI-WARN log level. This helps differentiate between application messages and YUI framework messages.

YUI logs can be turned on and off for both server and client within an application’s log configuration (see below).

Log Defaults

The server and client log settings have the following default values:

  • level: DEBUG - log level filter.
  • yui: true - determines whether YUI library logs are displayed.
  • buffer: false - determines whether logs are buffered.
  • maxBufferSize: 1024 - the number of logs the buffer holds before auto-flushing.
  • timestamp: true - log statements are given a timestamp if value is true.
  • defaultLevel: 'info' - if Y.log is called without a log level, this is the default.

Log Configuration

All the values above are configurable through the log object in the application.json file. In the example application.json below, the log object has both client and server objects that override the defaults for level and yui.

[
  {
    "settings": [ "master" ],
    "log": {
      "client": {
        "level": "error",
        "yui": false
      },
      "server": {
        "level": "info",
        "yui": false
      }
    },
    ...
  }
]

Log Buffering

To avoid performance issues caused by logging, you can enable buffering, which will configure Mojito to cache all logs in memory. You can force Mojito to flush the logs with the Y.log function or setting the maximum buffer size. The following sections show you how to enable buffering and force Mojito to flush the cached logs.

Enable Buffering

To configure Mojito to buffer your logs, set the buffer property to true in the log object as shown in the example application.json below.

[
  {
    "settings": [ "master" ],
    "log": {
      "client": {
        "buffer": true
      },
      "server": {
        "buffer": true
      }
    },
    ...
  }
]

Flush Cached Logs

Mojito provides you with two ways to forcefully flush cached logs. When you have buffering enabled, you can force Mojito to flush the cached logs with Y.log(({flush: true}). You can also set the maximum buffer size, so that Mojito will flush cached logs after the cache has reached the maximum buffer size.

In the example application.json below, the maximum buffer size is set to be 4096 bytes. Once the log cache reaches this size, the logs are then flushed. The default size of the log cache is 1024 bytes.

[
  {
    "settings": [ "master" ],
    "log": {
      "client": {
        "buffer": true,
        "maxBufferSize": 4096
      },
      "server": {
        "buffer": true,
        "maxBufferSize": 4096
      }
    },
    ...
  }
]