A super simple logger for the browser, written in 66 lines of CoffeeScript.
It's included in all Muffin apps by default. You can also use it without Muffin, as long as you have a way to load CommonJS modules.
The recommended approach is to create a
logging object in the global namespace.
Logger = require 'muffin/Logger' window.logging = new Logger()
Then you can use the logger from anywhere inside your app:
You can pass in a few options when creating the logger, including
window.logging = new Logger(logLevel='ERROR', writer='LocalStorageWriter', formatter='JSONFormatter', maxEntries=50)
In the case above, the logger will only output messages with a log level higher or equal to 'ERROR', the logs will be written to local storage, formatted in JSON, and no more than 50 entries are kept in the log history.
The log history can be accessed at
logging.history. You can specify the maximum of entries to be kept in the history (
maxEntries) when creating the logger. The default
20. When the log history is full, the oldest messages will be dropped to make space for the new ones.
The design of this logger loosely follows that of
Supported log levels:
- LocalStorageWriter: writes to
- SimpleFormatter (default):
Wed Jul 17 2013 20:06:16 GMT-0400 (EDT) [INFO]: test message
This logger has been tested under all major browsers including IE6+, Chrome, Firefox, Safari.
In older browers that don't support
console.log (e.g., IE6), a dummy
Released under the MIT license.