You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core/logger.md
+34-11
Original file line number
Diff line number
Diff line change
@@ -388,6 +388,40 @@ The error will be logged with default key name `error`, but you can also pass yo
388
388
389
389
## Advanced
390
390
391
+
### Log levels
392
+
393
+
The default log level is `INFO` and can be set using the `logLevel` constructor option or by using the `LOG_LEVEL` environment variable.
394
+
395
+
Logger supports the following log levels:
396
+
397
+
| Level | Numeric value |
398
+
| ---------- | ------------- |
399
+
|`DEBUG`| 8 |
400
+
|`INFO`| 12 |
401
+
|`WARN`| 16 |
402
+
|`ERROR`| 20 |
403
+
|`CRITICAL`| 24 |
404
+
|`SILENT`| 28 |
405
+
406
+
You can access the current log level by using the `getLevelName()` method. This method returns the name of the current log level as a string. If you want to change the log level at runtime, you can use the `setLogLevel()` method. This method accepts a string value that represents the log level you want to set, both lower and upper case values are supported.
407
+
408
+
```typescript
409
+
--8<--"docs/snippets/logger/logLevel.ts"
410
+
```
411
+
412
+
If you want to access the numeric value of the current log level, you can use the `level` property. For example, if the current log level is `INFO`, `logger.level` property will return `12`.
413
+
414
+
#### Silencing logs
415
+
416
+
The `SILENT` log level provides a simple and efficient way to suppress all log messages without the need to modify your code. When you set this log level, all log messages, regardless of their severity, will be silenced.
417
+
418
+
This feature is useful when you want to have your code instrumented to produce logs, but due to some requirement or business decision, you prefer to not emit them.
419
+
420
+
By setting the log level to `SILENT`, which can be done either through the `logLevel` constructor option or by using the `LOG_LEVEL` environment variable, you can easily suppress all logs as needed.
421
+
422
+
!!! note
423
+
Use the `SILENT` log level with care, as it can make it more challenging to monitor and debug your application. Therefore, we advise using this log level judiciously.
424
+
391
425
### Using multiple Logger instances across your code
392
426
393
427
The `createChild` method allows you to create a child instance of the Logger, which inherits all of the attributes from its parent. You have the option to override any of the settings and attributes from the parent logger, including [its settings](#utility-settings), any [persistent attributes](#appending-persistent-additional-log-keys-and-values), and [the log formatter](#custom-log-formatter-bring-your-own-formatter). Once a child logger is created, the logger and its parent will act as separate instances of the Logger class, and as such any change to one won't be applied to the other.
@@ -556,17 +590,6 @@ For example, by setting the "sample rate" to `0.5`, roughly 50% of your lambda i
556
590
}
557
591
```
558
592
559
-
### Silencing logs
560
-
561
-
The `SILENT` log level provides a simple and efficient way to suppress all log messages without the need to modify your code. When you set this log level, all log messages, regardless of their severity, will be silenced.
562
-
563
-
This feature is useful when you want to have your code instrumented to produce logs, but due to some requirement or business decision, you prefer to not emit them.
564
-
565
-
By setting the log level to `SILENT`, which can be done either through the `logLevel` constructor option or by using the `LOG_LEVEL` environment variable, you can easily suppress all logs as needed.
566
-
567
-
!!! note
568
-
Use the `SILENT` log level with care, as it can make it more challenging to monitor and debug your application. Therefore, we advise using this log level judiciously.
569
-
570
593
### Custom Log formatter (Bring Your Own Formatter)
571
594
572
595
You can customize the structure (keys and values) of your log items by passing a custom log formatter, an object that implements the `LogFormatter` abstract class.
0 commit comments