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
+12-2
Original file line number
Diff line number
Diff line change
@@ -390,8 +390,9 @@ The error will be logged with default key name `error`, but you can also pass yo
390
390
391
391
### Using multiple Logger instances across your code
392
392
393
-
Logger supports quick instance cloning via the `createChild` method.
394
-
This can be useful for example if you want to enable multiple Loggers with different logging levels in the same Lambda invocation.
393
+
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.
394
+
395
+
The following example shows how to create multiple Loggers that share service name and persistent attributes while specifying different logging levels within a single Lambda invocation. As the result, only ERROR logs with all the inherited attributes will be displayed in CloudWatch Logs from the child logger, but all logs emitted will have the same service name and persistent attributes.
395
396
396
397
=== "handler.ts"
397
398
@@ -407,20 +408,26 @@ This can be useful for example if you want to enable multiple Loggers with diffe
407
408
"message": "This is an INFO log, from the parent logger",
@@ -598,6 +605,9 @@ This is how the printed log would look:
598
605
}
599
606
```
600
607
608
+
!!! tip "Custom Log formatter and Child loggers"
609
+
It is not necessary to pass the `LogFormatter` each time a [child logger](#using-multiple-logger-instances-across-your-code) is created. The parent's LogFormatter will be inherited by the child logger.
0 commit comments