diff --git a/docs/core/logger.md b/docs/core/logger.md index 8b182edc18..431142e96e 100644 --- a/docs/core/logger.md +++ b/docs/core/logger.md @@ -45,11 +45,11 @@ The library has three optional settings, which can be set via environment variab These settings will be used across all logs emitted: -| Setting | Description | Environment variable | Default Value | Allowed Values | Example Value | Constructor parameter | -| ---------------------- | ---------------------------------------------------------------------------------------------------------------- | ------------------------------- | ------------------- | ------------------------------------------------------ | ------------------- | --------------------- | -| **Service name** | Sets the name of service of which the Lambda function is part of, that will be present across all log statements | `POWERTOOLS_SERVICE_NAME` | `service_undefined` | Any string | `serverlessAirline` | `serviceName` | -| **Logging level** | Sets how verbose Logger should be, from the most verbose to the least verbose (no logs) | `POWERTOOLS_LOG_LEVEL` | `INFO` | `DEBUG`, `INFO`, `WARN`, `ERROR`, `CRITICAL`, `SILENT` | `ERROR` | `logLevel` | -| **Sample rate** | Probability that a Lambda invocation will print all the log items regardless of the log level setting | `POWERTOOLS_LOGGER_SAMPLE_RATE` | `0` | `0.0` to `1.0` | `0.1` | `sampleRateValue` | +| Setting | Description | Environment variable | Default Value | Allowed Values | Example Value | Constructor parameter | +| ----------------- | ---------------------------------------------------------------------------------------------------------------- | ------------------------------- | ------------------- | ------------------------------------------------------ | ------------------- | --------------------- | +| **Service name** | Sets the name of service of which the Lambda function is part of, that will be present across all log statements | `POWERTOOLS_SERVICE_NAME` | `service_undefined` | Any string | `serverlessAirline` | `serviceName` | +| **Logging level** | Sets how verbose Logger should be, from the most verbose to the least verbose (no logs) | `POWERTOOLS_LOG_LEVEL` | `INFO` | `DEBUG`, `INFO`, `WARN`, `ERROR`, `CRITICAL`, `SILENT` | `ERROR` | `logLevel` | +| **Sample rate** | Probability that a Lambda invocation will print all the log items regardless of the log level setting | `POWERTOOLS_LOGGER_SAMPLE_RATE` | `0` | `0.0` to `1.0` | `0.1` | `sampleRateValue` | See all environment variables in the [Environment variables](../index.md/#environment-variables) section. Check API docs to learn more about [Logger constructor options](https://docs.powertools.aws.dev/lambda/typescript/latest/api/types/_aws_lambda_powertools_logger.types.ConstructorOptions.html){target="_blank"}. diff --git a/packages/logger/src/Logger.ts b/packages/logger/src/Logger.ts index 5c9a4711d8..60a17f6609 100644 --- a/packages/logger/src/Logger.ts +++ b/packages/logger/src/Logger.ts @@ -2,6 +2,7 @@ import { Utility } from '@aws-lambda-powertools/commons'; import type { HandlerMethodDecorator } from '@aws-lambda-powertools/commons/types'; import type { Context, Handler } from 'aws-lambda'; import merge from 'lodash.merge'; +import { format } from 'node:util'; import { Console } from 'node:console'; import { format } from 'node:util'; import { randomInt } from 'node:crypto'; diff --git a/packages/logger/tests/unit/Logger.test.ts b/packages/logger/tests/unit/Logger.test.ts index ebba0533dd..b5f8ae462a 100644 --- a/packages/logger/tests/unit/Logger.test.ts +++ b/packages/logger/tests/unit/Logger.test.ts @@ -136,7 +136,7 @@ describe('Class: Logger', () => { // Prepare const loggerOptions = undefined; delete process.env.POWERTOOLS_SERVICE_NAME; - delete process.env.LOG_LEVEL; + delete process.env.POWERTOOLS_LOG_LEVEL; // Act const logger = new Logger(loggerOptions); @@ -286,7 +286,7 @@ describe('Class: Logger', () => { test('when no log level is set, returns a Logger instance with INFO level', () => { // Prepare const loggerOptions: ConstructorOptions = {}; - delete process.env.LOG_LEVEL; + delete process.env.POWERTOOLS_LOG_LEVEL; // Act const logger = new Logger(loggerOptions); @@ -354,6 +354,9 @@ describe('Class: Logger', () => { get(name: string): string { return `a-string-from-${name}`; }, + getAwsLogLevel() { + return 'INFO'; + }, getCurrentEnvironment(): string { return 'dev'; },