Storage Logger (formerly "Persistent Log") is a a simple logging helper for JS client applications, providing a more persistent means of log entry storage than one would find with console
.
With the increasing complexity in javascript client apps, volatile logs like the one offered by console.log()
are often not enough to track down that elusive bug your users are finding.
Storage Logger allows your app to save log messages using localStorage
and read them whenever you need, event if they were logged in another session.
Get Storage Logger from https://raw.github.com/andregreeff/storage-logger/master/dist/storage-logger.js and include it in your page.
// Create a storage object
var storage = new slog.storages.LocalStorage({ maxSize: 200 });
// Initialize storage and level (DEBUG, INFO, WARN, ERROR or FATAL)
slog.useStorage(storage);
slog.setLevel(slog.level.INFO);
// Write messages to log
slog.debug("debug message");
slog.info("info message");
slog.warn("warn message");
slog.error("error message");
slog.fatal("fatal message");
// Retrieve stored events
var events = storage.getEvents();
Each logged message will be recorded as an event with the following shape:
{
level: 0, // 0 - DEBUG, ..., 3 - FATAL
message: 'some message',
date: '2013-12-31T12:04:32.283Z'
}
storage-logger uses grunt, browserify and karma. Building your own version of storage-logger is easy:
- Clone the repo
- Install grunt-cli globally:
npm install -g grunt-cli
- Install local dependencies:
npm install
- Build using the default grunt task (the result will be placed in './dist/storage-logger.js'):
grunt
There is also a very convenient task for development that watches source files and runs the build process (browserify, karma tests, etc.) after each change:
grunt dev
(c) Juan María Hernández Arroyo 2014