1.0.7 • Published 4 months ago

aws-logger-adapter v1.0.7

Weekly downloads
-
License
-
Repository
-
Last release
4 months ago

AWS Logger Adapter

Adapter for @aws-lambda-powertools/logger with external configuration option and logger instance provider. How to use @aws-lambda-powertools/logger read here: https://www.npmjs.com/package/@aws-lambda-powertools/logger

Installation

To install the package, use npm:

npm install aws-logger-adapter

Usage

Importing the Logger

You can import the logger instance using the getLogger function:

import { getLogger } from "aws-logger-adapter";

const logger = getLogger();  // gets the instance of `@aws-lambda-powertools/logger` 
logger.info("This is an info message");  

You can provide optional attributes to include in the logger:

const logger = getLogger({"key": "value"});  
 

These attributes will be included in every log message of this logger instance. If no attributes provided, the single logger instance is reused across all modules.

Configuration

Create a logger.config.json file in the root of your project to configure the logger. Example:

The logger can be configured using a logger.config.json file. Create the file and place it in the root directory of your project. To completely exclude a key from the log output, set the value to null in maskedKeys object. To override a key's value in the log, set it to the desired value in maskedKeys object.

{
  "prettyPrint": false,
  "maskedKeys": {
    "sampling_rate": null,
    "service": null,
    "user": "*** hidden by logger ***",
    "password": "*** hidden by logger ***",
    "long_list_of_objects": "*** omitted by logger ***",
    "big_json_object": "*** omitted by logger ***"
  },
  "globalAttributes": {
    "project": "my-project",
    "foo": "bar"
  }
}

You can enable pretty format of json logs when working locally by setting "prettyPrint": true (it's not recomended to use pretty format in real environment)

Dependencies

  • @aws-lambda-powertools/logger: ^2.14.0

License

This project is licensed under the MIT License. See the LICENSE file for details.

Author

Alex Ivanov - alex.ivn@outlook.com

1.0.7

4 months ago

1.0.6

4 months ago

1.0.5

4 months ago

1.0.4

4 months ago

1.0.3

4 months ago

1.0.2

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago