-
Notifications
You must be signed in to change notification settings - Fork 154
/
Copy pathlogSampling.ts
27 lines (23 loc) · 995 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
25
26
27
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: unknown,
_context: unknown
): Promise<void> => {
// Refresh sample rate calculation on runtime, only when not using injectLambdaContext
logger.refreshSampleRateCalculation();
// 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();
};