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
and place the following line in the dependencies of your package.json file.
"le_node": "0.2.1"

Configure in your code

var logentries = require('le_node');
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 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