Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 62 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,77 @@
# @barchart/log4js-node-appenders
# log4js-node-appenders

[![AWS CodeBuild](https://codebuild.us-east-1.amazonaws.com/badges?uuid=eyJlbmNyeXB0ZWREYXRhIjoiWXVHSTFxZHNGYnJ1SVM0LzZsdHEvU0ZIRlpYUUhvN2FJWm1kUE01dStHeGtuTmJQVmQrY2hKUXQxTEl6RmQzOUZUdlZNaWtLNmNhNHhFM3drRkRFamVvPSIsIml2UGFyYW1ldGVyU3BlYyI6IkRsWndGZFVsTUNBd1BIS3AiLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D&branch=master)](https://github.com/barchart/log4js-node-appenders)
[![NPM](https://img.shields.io/npm/v/@barchart/log4js-node-appenders)](https://www.npmjs.com/package/@barchart/log4js-node-appenders)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![npm downloads](https://img.shields.io/npm/dm/@barchart/log4js-node-appenders)](https://www.npmjs.com/package/@barchart/log4js-node-appenders)

Assorted _appenders_ for use with the [log4js](https://github.com/log4js-node/log4js-node) library.
> Assorted _appenders_ for use with the [log4js](https://github.com/log4js-node/log4js-node) library.

---

## Table of Contents

- [Overview](#overview)
- [Installation](#installation)
- [Appenders](#appenders)
- [Console Appender (AWS Lambda)](#console-appender-for-aws-lambda)
- [Usage Example](#usage-example)
- [License](#license)

---

## Overview

This library provides additional appenders for the popular [log4js-node](https://github.com/log4js-node/log4js-node) logging library. It is especially useful for logging in **AWS Lambda** environments where standard console output needs to be routed correctly.

---

## Installation

Install via NPM:

```bash
npm install @barchart/log4js-node-appenders --save
```

---

## Appenders

### Console Appender (for AWS Lambda)

A console appender that routes output to the correct function of the ```console``` object. This appender is useful for logging within an AWS Lambda function (avoids writing all logs at the ```INFO``` level).
A console appender that routes output to the correct function of the `console` object. This appender is useful for logging within an AWS Lambda function (avoids writing all logs at the `INFO` level).

| Log Level | Console Method |
|-----------|---------------|
| `TRACE` | `console.trace` |
| `DEBUG` | `console.debug` |
| `INFO` | `console.log` |
| `WARN` | `console.warn` |
| `ERROR` | `console.error` |
| `FATAL` | `console.error` |

* ```TRACE``` -> ```console.trace```
* ```DEBUG``` -> ```console.debug```
* ```INFO``` -> ```console.log```
* ```WARN``` -> ```console.warn```
* ```ERROR``` -> ```console.error```
* ```FATAL``` -> ```console.error```
---

**Usage Example**
## Usage Example

```js
const log4js = require('log4js');

const appenders = require('@barchart/log4js-node-appenders');

log4js.configure({
categories: {
default: { appenders: [ 'lambda' ], level: 'trace' }
},
appenders: {
lambda: {
type: appenders.lambda,
layout: {
type: 'pattern',
pattern: '%c - %m%'
}
}
}
categories: {
default: { appenders: ['lambda'], level: 'trace' }
},
appenders: {
lambda: {
type: appenders.lambda,
layout: {
type: 'pattern',
pattern: '%c - %m%'
}
}
}
});

const logger = log4js.getLogger('Example');
Expand All @@ -48,17 +84,8 @@ logger.error('Error level log message');
logger.fatal('Fatal level log message');
```

### Package Managers

This library is available as a *public* module on NPM.

```shell
npm install @barchart/log4js-node-appenders -S
```

### License

This software is provided under the MIT license.

---

## License

This software is provided under the [MIT](https://opensource.org/licenses/MIT) license.