Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

An easy to use logging utility for JavaScript applications

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 docs
Octocat-spinner-32 min
Octocat-spinner-32 src
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .jshintrc
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 CHANGELOG.md
Octocat-spinner-32 Gruntfile.js
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 bower.json
Octocat-spinner-32 package.json
README.md

silog

Integration status Built with Grunt

Dependency Status Build Status Coverage Status GitHub Version NPM Version Bower Version

What?

silog (simple logger) is an easy to use JavaScript logging utility, especially useful during development. It aims for minimal boilerplate, modular design, and it takes inspiration from how logging is done on the Android platform.

How?

Installation:

npm install silog

or:

bower install silog

Note that a minified version of silog is included in the min/ directory.

Usage

The demo file shows how silog can be used; there is also a web demo.

API

  • silog.level: object containing the following logging levels, from highest to lowest:
    • ASSERT
    • ERROR
    • WARN
    • INFO
    • DEBUG
    • VERBOSE
  • silog.tsFormat: date/ time output formats:
    • DATE_TIME: will output 31/12/2014 09:54
    • DATE: will output 09:54
    • TIME: will output 31/12/2014
  • silog.consoleLogger(what, extra): function that prints the logged messages to standard output; parameters:
    • what: string to send to output;
    • extra: object containing miscellaneous information about the logged message:
      • object: JSON to output; the way in which it will be displayed depends on the platform capabilities (e.g., web browser JavaScript consoles usually show a nice explorable tree structure);
      • tag: the tag of the message;
      • message: the actual message;
      • level: the level of the logged message;
      • ts: UNIX timestamp of the message
  • silog.Logger: logging class:
    • Logger(p): constructor; p is an object using which various logging parameters can be specified:
      • level: the minimum level messages should have in order to be sent for output, defaults to silog.level.INFO;
      • tsFormat: date/ time format of logged messages, defaults to silog.tsFormat.DATE_TIME;
      • loggers: array of functions that will output the logged messages, defaults to [silog.consoleLogger];
    • log(messageLevel, tag, message, object): main logging function with the following parameters:
      • messageLevel: the level of the message; log() will not send to output messages for which messageLevel < Logger.level;
      • tag: tag of the message (e.g., filename, function name, code line number);
      • message: the actual message (string);
      • object: optional JSON to output, might be ignored by the output functions;
    • wtf(tag, message, object): shorthand for log(silog.level.ASSERT, tag, message, object);
    • e(tag, message, object): shorthand for log(silog.level.ERROR, tag, message, object);
    • w(tag, message, object): shorthand for log(silog.level.WARN, tag, message, object);
    • i(tag, message, object): shorthand for log(silog.level.INFO, tag, message, object);
    • d(tag, message, object): shorthand for log(silog.level.DEBUG, tag, message, object);
    • v(tag, message, object): shorthand for log(silog.level.VERBOSE, tag, message, object);

Custom output functions:

You are free to implement your own output functions, used by silog.Logger.log, using silog.consoleLogger as a model; you can, for example, write messages to a file, web service, or Redis. The minimum expectation for these functions is the output of the what argument (a plain string).

Who?

silog is developed by Adrian-Tudor Panescu. Please feel free to report bugs and submit pull request.

License

The MIT License (MIT)

Copyright (c) 2014 Adrian-Tudor Panescu <adrian [at] panescu [dot] com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/ or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Something went wrong with that request. Please try again.