Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including lawgs with all npm packages installed. Try it out:

var lawgs = require("lawgs")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

lawgs v1.0.4

AWS CloudWatch Logs made easy

logo Lawgs

Nodejs logging to CloudWatch Logs made easy

Features

  • Creates Log Groups automatically
  • Creates Log Streams automatically
  • Periodic upload
  • Automatic log batching
  • JSON logging support
  • logger instances are shared across modules

Get it

npm install lawgs

How to use it

The only required configurations are the AWS configurations.

var lawgs = require('./index');

lawgs.config({
    aws: {
        accessKeyId: '********', /* Optional if credentials are set in ~/.aws/credentials */
        secretAccessKey: '******', /* Optional */
        region: 'us-east-1' /* Required */
    }
});

If you are using roles, you will need the following roles:

  • logs:DescribeLogGroups
  • logs:DescribeLogStreams
  • logs:CreateLogGroup
  • logs:CreateLogStream
  • logs:PutLogEvents

Simply create your logger and you are ready to go.

var logger  = lawgs.getOrCreate('SuperbowlLogs'); /* LogGroup */
logger.log('touchdown', { team: 'Patriots', weight: 7 });

Example

See example.js for a full working example.

Running the example, you get the following output:

Disposed subscription
Resubscribed
SuperbowlLogs >> uploadQueuedLogs triggered with  2  logs
Checking if log group exists: SuperbowlLogs
Creating log group: SuperbowlLogs
Checking if log stream exists: error
Checking if log stream exists: touchdown
Creating log stream: error
Creating log stream: touchdown
Uploading logs
Uploading logs
Logs uploaded
Logs uploaded

Roadmap

  • S3 logs archiving

Contributing

Feel free to open issues and open pull requests.

Related projects

Lambdaws (AWS Lambda Wrapper)

Superbowl Notifier (Used Lawgs to log high-volume tweets)

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free