Log whatever you want in your JavaScript application to the console or to an url.
When logging to an url your backend could store it in a database, a file or anything you like. To have some management over your logs, you could write the log backend in Fluentd to collect your logs.
- jQuery
- Backbone.js
- Underscore.js
The plugin should be AMD to work with require.js, but this has never been tested yet.
To use the plugin without any options add this in your <head></head>
var easylogger = new easyLogger();To use the plugin with custom options add this in your <head></head>
var easylogger = new easyLogger({
upload: false,
console: true
});enabled-true|false- enable or disable the pluginconsole-true|false- output the log to the consoleupload-true|false- output the log to an urlprefix-string- prefix of the log messagesuffix-string- suffix of the log messageurl-string- the url to store the log (only works ifuploadis set to true)selector-string- listen to which data elementgroupRest-string|false- group the remaining items in an object or add them to the base objectremember-number- remember the last x logs in the DOMdateformat-string- format the date of the logdefaults-object- set some default values in the log
{
enabled: true,
console: false,
upload: true,
prefix: "",
suffix: "",
url: 'api/log',
selector: 'log',
groupRest: 'custom',
remember: 5,
dateformat: "YYYY-MM-DD HH:II:SS",
defaults: {},
}Some methods you can use in this logger plugin
When you want to log something else than DOM elements with the data-log attribute use:
var easylogger = new easyLogger(options);
easylogger.log({message: "your message here"});If you want to get the latest logs in your DOM use:
var easylogger = new easyLogger(options);
console.log(easylogger.prevLogs);