Skip to content

Commit 6ee70e1

Browse files
authored
style(logger): apply stricter linting (#4569)
1 parent 734426b commit 6ee70e1

16 files changed

+57
-83
lines changed

packages/logger/src/formatter/LogFormatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ abstract class LogFormatter {
139139
/**
140140
* If a specific timezone is configured and it's not the default `UTC`,
141141
* format the timestamp with the appropriate timezone offset.
142-
**/
142+
*/
143143
const configuredTimezone = getStringFromEnv({
144144
key: 'TZ',
145145
defaultValue: '',

packages/logger/src/middleware/middy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const injectLambdaContext = (
8181
};
8282
};
8383

84-
const before = async (request: MiddyLikeRequest): Promise<void> => {
84+
const before = (request: MiddyLikeRequest) => {
8585
for (const logger of loggers) {
8686
if (isResetStateEnabled) {
8787
setCleanupFunction(request);
@@ -102,7 +102,7 @@ const injectLambdaContext = (
102102
}
103103
};
104104

105-
const after = async (): Promise<void> => {
105+
const after = () => {
106106
for (const logger of loggers) {
107107
logger.clearBuffer();
108108

@@ -112,7 +112,7 @@ const injectLambdaContext = (
112112
}
113113
};
114114

115-
const onError = async ({ error }: { error: unknown }): Promise<void> => {
115+
const onError = ({ error }: { error: unknown }) => {
116116
for (const logger of loggers) {
117117
if (options?.flushBufferOnUncaughtError) {
118118
logger.flushBuffer();

packages/logger/tests/e2e/advancedUses.test.FunctionCode.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { setTimeout } from 'node:timers/promises';
12
import { Logger } from '@aws-lambda-powertools/logger';
23
import {
34
correlationPaths,
@@ -18,7 +19,7 @@ const logger = new Logger({
1819

1920
logger.debug('a never buffered debug log');
2021

21-
export const handlerManual = async (event: unknown) => {
22+
export const handlerManual = (event: unknown) => {
2223
logger.addContext({} as Context); // we want only the cold start value
2324
logger.setCorrelationId(event, correlationPaths.EVENT_BRIDGE);
2425

@@ -42,7 +43,7 @@ export const handlerMiddy = middy()
4243
flushBufferOnUncaughtError: true,
4344
})
4445
)
45-
.handler(async () => {
46+
.handler(() => {
4647
logger.debug('a buffered debug log');
4748
logger.info('an info log');
4849
throw new Error('ops');
@@ -56,6 +57,7 @@ class Lambda {
5657
public async handler(_event: unknown, _context: Context) {
5758
logger.debug('a buffered debug log');
5859
logger.info('an info log');
60+
await setTimeout(1); // simulate async work
5961
throw new Error('ops');
6062
}
6163
}

packages/logger/tests/e2e/basicFeatures.middy.test.FunctionCode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ const logger = new Logger({
2626
},
2727
});
2828

29-
const testFunction = async (
29+
const testFunction = (
3030
_event: TestEvent,
3131
context: Context
32-
): TestOutput => {
32+
): Awaited<TestOutput> => {
3333
// Test feature 1: Context data injection (all logs should have the same context data)
3434
// Test feature 2: Event log (this log should have the event data)
3535
// Test feature 3: Log level filtering (log level is set to INFO)

packages/logger/tests/e2e/basicFeatures.middy.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('Logger E2E tests, basic functionalities middy usage', () => {
6565
});
6666

6767
describe('Log level filtering', () => {
68-
it('should filter log based on POWERTOOLS_LOG_LEVEL (INFO) environment variable in Lambda', async () => {
68+
it('should filter log based on POWERTOOLS_LOG_LEVEL (INFO) environment variable in Lambda', () => {
6969
for (let i = 0; i < invocationCount; i++) {
7070
// Get log messages of the invocation and filter by level
7171
const debugLogs = invocationLogs[i].getFunctionLogs('DEBUG');
@@ -76,7 +76,7 @@ describe('Logger E2E tests, basic functionalities middy usage', () => {
7676
});
7777

7878
describe('Context data', () => {
79-
it('should inject context info in each log', async () => {
79+
it('should inject context info in each log', () => {
8080
for (let i = 0; i < invocationCount; i++) {
8181
// Get log messages of the invocation
8282
const logMessages = invocationLogs[i].getFunctionLogs();
@@ -92,7 +92,7 @@ describe('Logger E2E tests, basic functionalities middy usage', () => {
9292
}
9393
});
9494

95-
it('should include coldStart equal to TRUE only on the first invocation, FALSE otherwise', async () => {
95+
it('should include coldStart equal to TRUE only on the first invocation, FALSE otherwise', () => {
9696
for (let i = 0; i < invocationCount; i++) {
9797
// Get log messages of the invocation
9898
const logMessages = invocationLogs[i].getFunctionLogs();
@@ -109,7 +109,7 @@ describe('Logger E2E tests, basic functionalities middy usage', () => {
109109
});
110110
});
111111

112-
it('logs the event for every invocation, only once, and without keys from previous invocations', async () => {
112+
it('logs the event for every invocation, only once, and without keys from previous invocations', () => {
113113
const { RUNTIME_ADDED_KEY: runtimeAddedKey } = commonEnvironmentVars;
114114

115115
for (let i = 0; i < invocationCount; i++) {
@@ -132,7 +132,7 @@ describe('Logger E2E tests, basic functionalities middy usage', () => {
132132
});
133133

134134
describe('Persistent additional log keys and values', () => {
135-
it('should contain persistent value in every log', async () => {
135+
it('should contain persistent value in every log', () => {
136136
const {
137137
PERSISTENT_KEY: persistentKey,
138138
PERSISTENT_VALUE: persistentValue,
@@ -151,7 +151,7 @@ describe('Logger E2E tests, basic functionalities middy usage', () => {
151151
}
152152
});
153153

154-
it('should not contain persistent keys that were removed on runtime', async () => {
154+
it('should not contain persistent keys that were removed on runtime', () => {
155155
const { REMOVABLE_KEY: removableKey, REMOVABLE_VALUE: removableValue } =
156156
commonEnvironmentVars;
157157

@@ -176,7 +176,7 @@ describe('Logger E2E tests, basic functionalities middy usage', () => {
176176
});
177177

178178
describe('One-time additional log keys and values', () => {
179-
it('should log additional keys and value only once', async () => {
179+
it('should log additional keys and value only once', () => {
180180
const {
181181
SINGLE_LOG_ITEM_KEY: singleLogItemKey,
182182
SINGLE_LOG_ITEM_VALUE: singleLogItemValue,
@@ -200,7 +200,7 @@ describe('Logger E2E tests, basic functionalities middy usage', () => {
200200
});
201201

202202
describe('Error logging', () => {
203-
it('should log error only once', async () => {
203+
it('should log error only once', () => {
204204
const { ERROR_MSG: errorMsg } = commonEnvironmentVars;
205205

206206
for (let i = 0; i < invocationCount; i++) {
@@ -226,7 +226,7 @@ describe('Logger E2E tests, basic functionalities middy usage', () => {
226226
});
227227

228228
describe('Arbitrary object logging', () => {
229-
it('should log additional arbitrary object only once', async () => {
229+
it('should log additional arbitrary object only once', () => {
230230
const {
231231
ARBITRARY_OBJECT_KEY: objectKey,
232232
ARBITRARY_OBJECT_DATA: objectData,
@@ -263,7 +263,7 @@ describe('Logger E2E tests, basic functionalities middy usage', () => {
263263
});
264264

265265
describe('X-Ray Trace ID injection', () => {
266-
it('should inject & parse the X-Ray Trace ID of the current invocation into every log', async () => {
266+
it('should inject & parse the X-Ray Trace ID of the current invocation into every log', () => {
267267
for (let i = 0; i < invocationCount; i++) {
268268
// Get log messages of the invocation
269269
const logMessages = invocationLogs[i].getFunctionLogs();

packages/logger/tests/e2e/childLogger.manual.test.FunctionCode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ const childLogger = parentLogger.createChild({
2020
logLevel: CHILD_LOG_LEVEL,
2121
});
2222

23-
export const handler = async (
23+
export const handler = (
2424
_event: TestEvent,
2525
context: Context
26-
): TestOutput => {
26+
): Awaited<TestOutput> => {
2727
parentLogger.addContext(context);
2828

2929
childLogger.info(CHILD_LOG_MSG);

packages/logger/tests/e2e/childLogger.manual.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('Logger E2E tests, child logger', () => {
5757
});
5858

5959
describe('Child logger', () => {
60-
it('should not log at same level of parent because of its own logLevel', async () => {
60+
it('should not log at same level of parent because of its own logLevel', () => {
6161
const { PARENT_LOG_MSG: parentLogMsg, CHILD_LOG_MSG: childLogMsg } =
6262
commonEnvironmentVars;
6363

@@ -77,7 +77,7 @@ describe('Logger E2E tests, child logger', () => {
7777
}
7878
});
7979

80-
it('should log only level passed to a child', async () => {
80+
it('should log only level passed to a child', () => {
8181
const { CHILD_LOG_MSG: childLogMsg } = commonEnvironmentVars;
8282
for (let i = 0; i < invocationCount; i++) {
8383
// Get log messages of the invocation
@@ -95,7 +95,7 @@ describe('Logger E2E tests, child logger', () => {
9595
}
9696
});
9797

98-
it('should NOT inject context into the child logger', async () => {
98+
it('should NOT inject context into the child logger', () => {
9999
const { CHILD_LOG_MSG: childLogMsg } = commonEnvironmentVars;
100100

101101
for (let i = 0; i < invocationCount; i++) {
@@ -118,7 +118,7 @@ describe('Logger E2E tests, child logger', () => {
118118
}
119119
});
120120

121-
it('both logger instances should have the same persistent key/value', async () => {
121+
it('both logger instances should have the same persistent key/value', () => {
122122
const { PERSISTENT_KEY: persistentKey } = commonEnvironmentVars;
123123

124124
for (let i = 0; i < invocationCount; i++) {

packages/logger/tests/e2e/logEventEnvVarSetting.middy.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('Logger E2E tests, log event via env var setting with middy', () => {
6060
});
6161

6262
describe('Log event', () => {
63-
it('should log the event as the first log of each invocation only', async () => {
63+
it('should log the event as the first log of each invocation only', () => {
6464
for (let i = 0; i < invocationCount; i++) {
6565
// Get log messages of the invocation
6666
const logMessages = invocationLogs[i].getFunctionLogs();

packages/logger/tests/e2e/sampleRate.decorator.test.FunctionCode.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { setTimeout } from 'node:timers/promises';
12
import type { LambdaInterface } from '@aws-lambda-powertools/commons/types';
23
import type { Context } from 'aws-lambda';
34
import { Logger } from '../../src/index.js';
@@ -16,6 +17,7 @@ class Lambda implements LambdaInterface {
1617
@logger.injectLambdaContext()
1718
public async handler(_event: TestEvent, context: Context): TestOutput {
1819
this.printLogInAllLevels();
20+
await setTimeout(1); // simulate some async work
1921

2022
return {
2123
requestId: context.awsRequestId,

packages/logger/tests/e2e/sampleRate.decorator.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('Logger E2E tests, sample rate and injectLambdaContext()', () => {
5959
});
6060

6161
describe('Enabling sample rate', () => {
62-
it('should log all levels based on given sample rate, not just ERROR', async () => {
62+
it('should log all levels based on given sample rate, not just ERROR', () => {
6363
// Fetch log streams from all invocations
6464
let countSampled = 0;
6565
let countNotSampled = 0;
@@ -94,7 +94,7 @@ describe('Logger E2E tests, sample rate and injectLambdaContext()', () => {
9494
});
9595

9696
describe('Decorator injectLambdaContext()', () => {
97-
it('should inject Lambda context into every log emitted', async () => {
97+
it('should inject Lambda context into every log emitted', () => {
9898
for (let i = 0; i < invocationCount; i++) {
9999
// Get log messages of the invocation
100100
const logMessages = invocationLogs[i].getFunctionLogs('ERROR');

0 commit comments

Comments
 (0)