- Does the world really need another logging library?
- Should I use this library instead of something else?
- What does this library offer?
- What size is it?
- How do I install it?
- How do I use it?
- How do I set up the build environment?
- What license is it released under?
Absolutely, definitely, resoundingly no, it does not.
Almost certainly no, you should use something else instead of this library.
It is fully supported by unit tests, is small of interface and implementation, and works in both node.js and the browser.
Furthermore, it behaves exactly how I want, which is quite important when you're me.
2.6 kb unminified with comments, 0.7 kb minified, 0.4 kb minified + gzipped
Any of the following will do:
npm install get-off-my-logjam install get-off-my-logbower install get-off-my-logcomponent install philbooth/get-off-my-loggit clone firstname.lastname@example.org:philbooth/get-off-my-log.git
If you are running in
or another CommonJS-style
get-off-my-log like so:
var log = require'get-off-my-log';
It also the supports the AMD-style format preferred by Require.js:
requireconfigpaths:log: 'get-off-my-log/src';require 'log';
If you are
with an HTML
or neither of the above environments
get-off-my-log will just export its interface globally
Before logging any data,
you must initialise the library
var fooLog = loginitialise'foo';
The benefit of this step is that it enables straightforward searching and filtering of log files if you are running a project where you wish to differentiate between the origins of different log messages:
var userLog systemLog;userLog = loginitialise'user';systemLog = loginitialise'system';
There is also a second, optional argument to
If it is undefined,
it defaults to
However, if you would like to, say,
log messages to a file
rather than the console,
providing a custom logger
enables you to do that:
var userLog systemLog;userLog = loginitialise'user' userLogger;systemLog = loginitialise'system' systemLogger;fswriteFileSynclogsuser message + '\n';fswriteFileSynclogssystem message + '\n';
Regardless of how
you choose to initialise your logger(s),
each one is returned from
as an object with three methods:
Each of these methods
takes one argument,
the message that you want to log.
The message will be sent to the appropriate
console.log if you used the default),
prefixed with a timestamp,
the log level of the method
and the origin
that you set in the call to
var resizeLog isFired isDrawing;// Initialise the window resize loggerresizeLog = loginitialise'resize';isFired = isDrawing = false;windowaddEventListener'resize' throttleResize false;if isDrawing === falseisFired = true;draw;else// Write warning-level message to the consoleresizeLog.warn'already drawing';if isFired === trueisFired = false;isDrawing = true;// Write info-level message to the consoleresizeLog.info'started drawing';// Draw...requestAnimationFramedraw;elseisDrawing = false;// Write info-level message to the consoleresizeLog.info'stopped drawing';
var log databaseLog;log = require'get-off-my-log';// Initialise the database loggerdatabaseLog = loginitialise'database' databaseLogger;fswriteFileSync'/var/log/foo/database.log' message;// Write info-level message to database log filedatabaseLog.info'updating ' + query + ' with ' + data;// Update datbase...if error// Write error-level message to database log filedatabaseLog.errorerrormessage;
The build environment relies on
Assuming that you already have Node.js and NPM set up,
you just need to run
npm install to
install all of the dependencies as listed in
The unit tests are in
You can run them with the command
To run the tests in a web browser,