forked from aws-powertools/powertools-lambda-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappendKeys.ts
41 lines (34 loc) · 1.21 KB
/
appendKeys.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { Logger } from '@aws-lambda-powertools/logger';
// Add persistent log keys via the constructor
const logger = new Logger({
persistentLogAttributes: {
aws_account_id: '123456789012',
aws_region: 'eu-west-1',
logger: {
name: '@aws-lambda-powertools/logger',
version: '0.0.1',
},
extra_key: "some-value"
}
});
// OR add persistent log keys to an existing Logger instance with the appendKeys method:
// logger.appendKeys({
// aws_account_id: '123456789012',
// aws_region: 'eu-west-1',
// logger: {
// name: '@aws-lambda-powertools/logger',
// version: '0.0.1',
// },
// extra_key: "some-value"
// });
export const handler = async (_event: any, _context: any): Promise<unknown> => {
// If you don't want to log the "extra_key" attribute in your logs, you can remove it
logger.removeKeys(["extra_key"])
// This info log will print all extra custom attributes added above
// Extra attributes: logger object with name and version of the logger library, awsAccountId, awsRegion
logger.info('This is an INFO log');
logger.info('This is another INFO log');
return {
foo: 'bar'
};
};