node.js


Logentries supports Logging using node.js. Event-driven I/O server-side JavaScript environment based on V8.

Create Account

If you have not done so already, you will need to create a Logentries account. Just click the ‘Sign up’ button at the top of this page and register your email address.

Create Log

Log in to Logentries and create a new log by clicking the Add New Log button. Now click Manual Configuration button from the list of options. Give your log a name of your choice, select Token TCP and finally click the Register new log button. A token will be displayed in green. Please record it as we will use it later to configure the library.

Install

Run the following command to install node.js library:
npm install le_node --save

Configure in your code

var Logger = require('le_node');
var logger = new Logger({
  token:'LOGENTRIES_TOKEN'
});
The LOGENTRIES_TOKEN parameter needs to be replaced with the token for the log we created earlier. There are many other options available when instantiating the Logger, which you can read about on the GitHub project page.

Insert Logging Code

The module provides you with a set of logging methods that correspond to the standard syslog log levels. These are, in order of increasing severity: debug, info, notice, warning, err, crit, alert, emerg.

Example

// level specific methods like 'info', 'debug', etc.
log.info("I'm a Lumberjack and I'm OK")

// generic log method, also accepts JSON entries
log.log("debug", {sleep:"all night", work:"all day"})
For more details on using the node.js wrapper see our node.js Github Page. Note the module is also compatible with the Winston.

Watch Your Logs

After some log events were produced, you can log on to the Logentries web site and select the logs that you want to consult. Click the Live Tail button to see your incoming logs in real time.
Back to Top