Logentries Docs

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. An email with instructions on how to complete your account creation will be sent to you.

Create Destination

newhostLog in to Logentries and create a new log by clicking theCreate Log button as shown in the figure on the right. 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 node-logentries

and place the following line in the dependencies of your package.json file.

"node-logentries": "0.0.2"

Configure in your code

var logentries = require('node-logentries');
var log = logentries.logger({
  token:'LOGENTRIES_TOKEN'
});

The LOGENTRIES_TOKEN parameter needs to be replaced with the token for the logfile we created earlier. If you haven’t taken note of the token when creating your log, you can retrieve it by logging in to Logentries. Once logged in, select the host containing the log for which you want to retrieve the token (e.g. from the side bar on the left hand side of the page). All the token-based logs of this host are then displayed with a Token icon on the right hand side. Click this icon to display the token.


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 Richard Rodger’s 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.

refreshHit the refresh button at the top right corner of the Logentries UI to see your latest log events. It can take a few seconds before log events appear.

Back to Top