Skip to content

Commit fee6247

Browse files
committed
chore: docs
1 parent aa2ee45 commit fee6247

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

docs/core/logger.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ You can use values ranging from `0` to `1` (100%) when setting the `sampleRateVa
805805

806806
This feature takes into account transient issues where additional debugging information can be useful.
807807

808-
Sampling decision happens at the Logger initialization. When using the `injectLambdaContext` method either as a decorator or middleware, the sampling decision is refreshed at the beginning of each Lambda invocation for you, except for cold starts.
808+
Sampling decision happens at the Logger initialization. When using the `injectLambdaContext` method either as a decorator or Middy.js middleware, the sampling decision is refreshed at the beginning of each Lambda invocation for you, except for cold starts.
809809

810810
If you're not using either of these, you'll need to manually call the `refreshSamplingRate()` function at the start of your handler to refresh the sampling decision for each invocation.
811811

@@ -815,6 +815,9 @@ If you're not using either of these, you'll need to manually call the `refreshSa
815815
--8<-- "examples/snippets/logger/logSampling.ts"
816816
```
817817

818+
1. The log level must be set to a more verbose level than `DEBUG` for log sampling to kick in.
819+
2. You need to call `logger.refreshSamplingRate()` at the start of your handler if you're not using the `injectLambdaContext()` class method decorator or Middy.js middleware.
820+
818821
=== "Example CloudWatch Logs excerpt - Invocation #1"
819822

820823
```json
+7-18
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
11
import { Logger } from '@aws-lambda-powertools/logger';
22

3-
// Notice the log level set to 'ERROR'
43
const logger = new Logger({
5-
logLevel: 'ERROR',
4+
logLevel: 'ERROR', // (1)!
65
sampleRateValue: 0.5,
76
});
87

9-
export const handler = async (
10-
_event: unknown,
11-
_context: unknown
12-
): Promise<void> => {
13-
// Refresh sample rate calculation on runtime, only when not using injectLambdaContext
14-
logger.refreshSampleRateCalculation();
15-
// This log item (equal to log level 'ERROR') will be printed to standard output
16-
// in all Lambda invocations
17-
logger.error('This is an ERROR log');
8+
export const handler = async () => {
9+
logger.refreshSampleRateCalculation(); // (2)!
1810

19-
// These log items (below the log level 'ERROR') have ~50% chance
20-
// of being printed in a Lambda invocation
21-
logger.debug('This is a DEBUG log that has 50% chance of being printed');
22-
logger.info('This is an INFO log that has 50% chance of being printed');
23-
logger.warn('This is a WARN log that has 50% chance of being printed');
11+
logger.error('This log is always emitted');
2412

25-
// Optional: refresh sample rate calculation on runtime
26-
// logger.refreshSampleRateCalculation();
13+
logger.debug('This log has ~50% chance of being emitted');
14+
logger.info('This log has ~50% chance of being emitted');
15+
logger.warn('This log has ~50% chance of being emitted');
2716
};

0 commit comments

Comments
 (0)