Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 3 additions & 8 deletions packages/logger/src/Logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Console } from 'node:console';
import { randomInt } from 'node:crypto';
import { Utility, isNullOrUndefined } from '@aws-lambda-powertools/commons';
import { isNullOrUndefined, Utility } from '@aws-lambda-powertools/commons';
import type {
AsyncHandler,
HandlerMethodDecorator,
Expand All @@ -26,10 +26,10 @@ import type {
InjectLambdaContextOptions,
LogAttributes,
LogFunction,
LoggerInterface,
LogItemExtraInput,
LogItemMessage,
LogLevel,
LoggerInterface,
} from './types/Logger.js';
import type {
LogKeys,
Expand Down Expand Up @@ -545,12 +545,7 @@ class Logger extends Utility implements LoggerInterface {
options?: InjectLambdaContextOptions
): void {
logger.addContext(context);

let shouldLogEvent = undefined;
if (options && Object.hasOwn(options, 'logEvent')) {
shouldLogEvent = options.logEvent;
}
logger.logEventIfEnabled(event, shouldLogEvent);
logger.logEventIfEnabled(event, options?.logEvent);
} /* v8 ignore stop */

/**
Expand Down
7 changes: 2 additions & 5 deletions packages/logger/src/formatter/LogFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { EnvironmentVariablesService } from '../config/EnvironmentVariablesService.js';
import type { LogAttributes } from '../types/Logger.js';
import type { LogFormatterOptions } from '../types/formatters.js';
import type { LogAttributes } from '../types/Logger.js';
import type { UnformattedAttributes } from '../types/logKeys.js';
import type { LogItem } from './LogItem.js';

Expand Down Expand Up @@ -120,10 +120,7 @@ abstract class LogFormatter {
this.envVarsService?.isDevMode() && typeof stack === 'string'
? stack?.split('\n')
: stack,
cause:
error.cause instanceof Error
? this.formatError(error.cause)
: error.cause,
cause: cause instanceof Error ? this.formatError(cause) : cause,
};
for (const key in error) {
if (
Expand Down
2 changes: 1 addition & 1 deletion packages/logger/src/middleware/middy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type {
MiddlewareLikeObj,
MiddyLikeRequest,
} from '@aws-lambda-powertools/commons/types';
import { Logger } from '../Logger.js';
import { UncaughtErrorLogMessage } from '../constants.js';
import { Logger } from '../Logger.js';
import type { InjectLambdaContextOptions } from '../types/Logger.js';

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/logger/tests/e2e/advancedUses.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { join } from 'node:path';
import {
invokeFunction,
TestInvocationLogs,
TestStack,
invokeFunction,
} from '@aws-lambda-powertools/testing-utils';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { LoggerTestNodejsFunction } from '../helpers/resources.js';
Expand Down Expand Up @@ -104,7 +104,7 @@ describe('Logger E2E - Advanced uses', () => {
try {
JSON.parse(log);
return true;
} catch (error) {
} catch (_error) {
return false;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ const logger = new Logger({
},
});

const testFunction = async (event: TestEvent, context: Context): TestOutput => {
const testFunction = async (
_event: TestEvent,
context: Context
): TestOutput => {
// Test feature 1: Context data injection (all logs should have the same context data)
// Test feature 2: Event log (this log should have the event data)
// Test feature 3: Log level filtering (log level is set to INFO)
Expand Down
4 changes: 2 additions & 2 deletions packages/logger/tests/e2e/basicFeatures.middy.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { join } from 'node:path';
import {
invokeFunction,
TestInvocationLogs,
TestStack,
invokeFunction,
} from '@aws-lambda-powertools/testing-utils';
import type { APIGatewayAuthorizerResult } from 'aws-lambda';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { LoggerTestNodejsFunction } from '../helpers/resources.js';
import {
commonEnvironmentVars,
RESOURCE_NAME_PREFIX,
STACK_OUTPUT_LOG_GROUP,
XRAY_TRACE_ID_REGEX,
commonEnvironmentVars,
} from './constants.js';

describe('Logger E2E tests, basic functionalities middy usage', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/logger/tests/e2e/childLogger.manual.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { join } from 'node:path';
import {
invokeFunction,
TestInvocationLogs,
TestStack,
invokeFunction,
} from '@aws-lambda-powertools/testing-utils';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { LoggerTestNodejsFunction } from '../helpers/resources.js';
import {
commonEnvironmentVars,
RESOURCE_NAME_PREFIX,
STACK_OUTPUT_LOG_GROUP,
commonEnvironmentVars,
} from './constants.js';

describe('Logger E2E tests, child logger', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { join } from 'node:path';
import {
invokeFunction,
TestInvocationLogs,
TestStack,
invokeFunction,
} from '@aws-lambda-powertools/testing-utils';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { LoggerTestNodejsFunction } from '../helpers/resources.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/logger/tests/e2e/sampleRate.decorator.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { randomUUID } from 'node:crypto';
import { join } from 'node:path';
import {
invokeFunction,
TestInvocationLogs,
TestStack,
invokeFunction,
} from '@aws-lambda-powertools/testing-utils';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { LoggerTestNodejsFunction } from '../helpers/resources.js';
Expand Down
8 changes: 2 additions & 6 deletions packages/logger/tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,5 @@
"rootDir": "../../",
"noEmit": true
},
"include": [
"../../testing/src/setupEnv.ts",
"../src/**/*",
"./**/*"
]
}
"include": ["../../testing/src/setupEnv.ts", "../src/**/*", "./**/*"]
}
3 changes: 1 addition & 2 deletions packages/logger/tests/unit/formatters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { EnvironmentVariablesService } from '../../src/config/EnvironmentVariabl
import { PowertoolsLogFormatter } from '../../src/formatter/PowertoolsLogFormatter.js';
import {
LogFormatter,
Logger,
LogItem,
LogLevelThreshold,
Logger,
} from '../../src/index.js';
import type {
CustomJsonReplacerFn,
Expand All @@ -15,7 +15,6 @@ import type {
} from '../../src/types/Logger.js';
import type { LogKey, UnformattedAttributes } from '../../src/types/logKeys.js';

const fileNameRegexp = new RegExp(/index.js:\d+$/);
const fileNameRegexpWithLine = new RegExp(/formatters.test.ts:\d+:\d+/);
const formatter = new PowertoolsLogFormatter();
const formatterWithEnv = new PowertoolsLogFormatter({
Expand Down
4 changes: 2 additions & 2 deletions packages/logger/tests/unit/initializeLogger.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type Mock, beforeEach, describe, expect, it, vi } from 'vitest';
import { Logger } from '../../src/Logger.js';
import { beforeEach, describe, expect, it, type Mock, vi } from 'vitest';
import { LogJsonIndent, LogLevel } from '../../src/constants.js';
import { Logger } from '../../src/Logger.js';

describe('Log levels', () => {
const ENVIRONMENT_VARIABLES = process.env;
Expand Down
2 changes: 1 addition & 1 deletion packages/logger/tests/unit/injectLambdaContext.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import context from '@aws-lambda-powertools/testing-utils/context';
import middy from '@middy/core';
import type { Context } from 'aws-lambda';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { Logger } from '../../src/Logger.js';
import { search } from '../../src/correlationId.js';
import { Logger } from '../../src/Logger.js';
import { injectLambdaContext } from '../../src/middleware/middy.js';

const event = {
Expand Down
4 changes: 2 additions & 2 deletions packages/logger/tests/unit/logBuffer.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import context from '@aws-lambda-powertools/testing-utils/context';
import type { Context } from 'aws-lambda';
import middy from 'middy5';
import { type Mock, beforeEach, describe, expect, it, vi } from 'vitest';
import { Logger } from '../../src/Logger.js';
import { beforeEach, describe, expect, it, type Mock, vi } from 'vitest';
import { LogLevel, UncaughtErrorLogMessage } from '../../src/constants.js';
import { Logger } from '../../src/Logger.js';
import { injectLambdaContext } from '../../src/middleware/middy.js';

describe('Buffer logs', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/logger/tests/unit/logEvent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('Log event', () => {
const logger = new Logger();
class Test {
@logger.injectLambdaContext({ logEvent: true })
async handler(event: unknown, context: Context) {
async handler(event: unknown, _context: Context) {
return event;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/logger/tests/unit/logLevels.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { Logger } from '../../src/Logger.js';
import { LogLevel, LogLevelThreshold } from '../../src/constants.js';
import { Logger } from '../../src/Logger.js';
import type { ConfigServiceInterface } from '../../src/types/ConfigServiceInterface.js';
import type {
LogFunction,
Expand Down
2 changes: 1 addition & 1 deletion packages/logger/tests/unit/sampling.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { beforeEach, describe, expect, it } from 'vitest';
import { EnvironmentVariablesService } from '../../src/config/EnvironmentVariablesService.js';
import { LogLevel, LogLevelThreshold, Logger } from '../../src/index.js';
import { Logger, LogLevel, LogLevelThreshold } from '../../src/index.js';

class CustomConfigService extends EnvironmentVariablesService {
#sampleRateValue = 1;
Expand Down
2 changes: 1 addition & 1 deletion packages/logger/tests/unit/workingWithkeys.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ describe('Working with keys', () => {
});
class Test {
@logger.injectLambdaContext({ resetKeys: true })
async handler(addKey: boolean, context: Context) {
async handler(addKey: boolean, _context: Context) {
if (addKey) {
logger.appendKeys({
foo: 'baz',
Expand Down
6 changes: 2 additions & 4 deletions packages/logger/tsconfig.cjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@
"rootDir": "./src",
"tsBuildInfoFile": ".tsbuildinfo/cjs.json"
},
"include": [
"./src/**/*"
]
}
"include": ["./src/**/*"]
}
6 changes: 2 additions & 4 deletions packages/logger/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@
"composite": true,
"declaration": true
},
"include": [
"./src/**/*"
]
}
"include": ["./src/**/*"]
}