Skip to main content.

InstallationLearn how to integrate LambdaLog into your project.

To get started, install LambdaLog using NPM or Yarn to your project:

NPM:

1npm install lambda-log

Yarn:

1yarn add lambda-log

Usage

In the most simplest form:

1const log = require('lambda-log');
2 
3log.info('Hello from LambdaLog!');

or for a more in-depth example in a Lambda Function:

1const log = require('lambda-log');
2 
3exports.handler = function(event, context, callback) {
4 // set some optional metadata to be included in all logs (this is an overkill example)
5 log.options.meta.event = event;
6 // add additional tags to all logs
7 log.options.tags.push(event.env);
8 
9 // Log info message
10 log.info('my lambda function is running!');
11 //=> { _logLevel: 'info' msg: 'my lambda function is running!', event:..., _tags: ['log', 'info', ...] }
12 
13 if(somethingHappenedButNotFatal) {
14 log.warn('something is missing, but it is OK');
15 //=> { _logLevel: 'warn', msg: 'something is missing, but it is OK', event:..., _tags: ['log', 'warn', ...] }
16 }
17 
18 // Debug messages are not generated or displayed unless enabled in the config
19 log.debug('some debug message');
20 //=> false
21 
22 // Enable debug messages
23 log.options.debug = true;
24 log.debug('some debug message again');
25 //=> { _logLevel: 'debug', msg: 'some debug message again', event:..., _tags: ['log', 'debug', ...] }
26 
27 someAsyncTask(function(err, results) {
28 if(err) {
29 log.error(err);
30 //=> { _logLevel: 'error', msg: 'Error from someAsyncTask', stack: ..., event: ..., _tags: ['log', 'error', ...]}
31 } else {
32 log.info('someAsyncTask completed successfully!', { results });
33 //=> { _logLevel: 'info', msg: 'someAsyncTask completed successfully!', results:..., event: ..., _tags: ['log', 'info', ...]}
34 }
35 });
36 
37 // New in version 1.4.0 - assert
38 someAsyncTask(function(err, results) {
39 if(err) {
40 log.error(err);
41 //=> { _logLevel: 'error', msg: 'Error from someAsyncTask', stack: ..., event: ..., _tags: ['log', 'error', ...]}
42 } else {
43 // Will only log if no results are returned
44 log.assert(results, 'No results returned from someAsyncTask');
45 }
46 });
47};

Check out the API Reference for more examples.