web-logger
v0.0.5
Published
Real-time logger with a built-in web interface for command-line node apps.
Downloads
2
Maintainers
Readme
web-logger
Real-time logger with a built-in web interface for command-line node apps.
Features
- View your app's logs on stdout or in a local web interface.
- Callsite logging (file and line number that logged each line).
- Log arbitrary JSON metadata and inspect it in the browser.
- Streaming logs in the browser: you get live
tail -f
behavior. - You can run the program on one host and see logs on another via the web interface.
- You get basic system stats for free, which is useful if you are running the program on a different host.
- 100% cloud-free, all local, works without an Internet conenction.
- MIT-Licensed. Safe for use and modification in all types of projects, including commercial ones.
Usage
npm install --save web-logger
And then in any/all source files:
var lg = require('web-logger');
lg(lg.INFO, 'Hello!', {some: 'data'});
lg(lg.ERROR, 'A bad thing happened!');
lg(lg.STATUS, 'Starting a timer now.');
setInterval(function() {
lg(lg.INFO, 'The time is ' + (new Date()), {
rand: Math.random(),
});
if (Math.random() < 0.2) {
lg(lg.SUCCESS, 'Something good happened!', {
someId: 123
});
}
lg(lg.END); // terminates logserver process,
// lets your program die.
}, 3000);
When you run your program, you should see something like this on stdout:
Logserver listening at http://localhost:40270/index.html
Visit the URL for a pretty page of live, streaming logs.
When you're done looking at the logs, kill your program with a Ctrl-C or similar method. If you don't want to do this, you can disable the web interface entirely with the --disable-logserver
command-line flag.
If you don't feel like opening a web browser, run your program with the --stdlog
command-line option to additionally log to stdout as well as the internal memory buffer (i.e., the web interface).
If you don't like the random port that the system picks for the logserver to listen on, run your program with a --logport N
option, where N
is the port you'd rather have the logserver listen on.