-
Notifications
You must be signed in to change notification settings - Fork 154
/
Copy pathsample-rate.ts
37 lines (27 loc) · 1.26 KB
/
sample-rate.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
// Populate runtime
require('./../tests/helpers/populateEnvironmentVariables');
// Additional runtime variables
process.env.LOG_LEVEL = 'ERROR';
process.env.POWERTOOLS_SERVICE_NAME = 'hello-world';
process.env.POWERTOOLS_LOGGER_SAMPLE_RATE = '0.5';
import * as dummyEvent from '../../../tests/resources/events/custom/hello-world.json';
import { context as dummyContext } from '../../../tests/resources/contexts/hello-world';
import { Handler } from 'aws-lambda';
import { Logger } from '../src';
const logger = new Logger();
const lambdaHandler: Handler = async () => {
// 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();
return {
foo: 'bar'
};
};
lambdaHandler(dummyEvent, dummyContext, () => console.log('lambda invoked!'));