forked from aws-powertools/powertools-lambda-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogSampling.ts
24 lines (18 loc) · 880 Bytes
/
logSampling.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
import { Logger } from '@aws-lambda-powertools/logger';
// Notice the log level set to 'ERROR'
const logger = new Logger({
logLevel: 'ERROR',
sampleRateValue: 0.5
});
export const handler = async (_event: any, _context: any): Promise<void> => {
// This log item (equal to log level 'ERROR') will be printed to standard output
// in all Lambda invocations
logger.error('This is an ERROR log');
// These log items (below the log level 'ERROR') have ~50% chance
// of being printed in a Lambda invocation
logger.debug('This is a DEBUG log that has 50% chance of being printed');
logger.info('This is an INFO log that has 50% chance of being printed');
logger.warn('This is a WARN log that has 50% chance of being printed');
// Optional: refresh sample rate calculation on runtime
// logger.refreshSampleRateCalculation();
};