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
If you're migrating from other Loggers, there are few key points to be aware of: **Service parameter**, **Inheriting Loggers**, **Overriding Log records**, and **Logging exceptions**.
268
+
269
+
### The service parameter
270
+
271
+
Service is what defines what the function is responsible for, or part of (e.g payment service), and the name of the Logger.
272
+
273
+
For Logger, the `service` is the logging key customers can use to search log operations for one or more functions - For example, **search for all errors, or messages like X, where service is payment**.
274
+
275
+
### Inheriting Loggers
276
+
277
+
> Python Logging hierarchy happens via the dot notation: `service`, `service.child`, `service.child_2`.
278
+
279
+
For inheritance, Logger uses a `child=True` parameter along with `service` being the same value across Loggers.
280
+
281
+
For child Loggers, we introspect the name of your module where `Logger(child=True, service="name")` is called, and we name your Logger as **{service}.{filename}**.
282
+
283
+
A common issue when migrating from other Loggers is that `service` might be defined in the parent Logger (no child param), and not defined in the child Logger:
In this case, Logger will register a Logger named `payment`, and a Logger named `service_undefined`. The latter isn't inheriting from the parent, and will have no handler, thus no message being logged to standard output.
300
+
301
+
This can be fixed by either ensuring both has the `service` value as `payment`, or simply use the environment variable `POWERTOOLS_SERVICE_NAME` to ensure service value will be the same across all Loggers when not explicitly set.
302
+
303
+
### Overriding Log records
304
+
305
+
You might want to continue to use the same date formatting style, or override `location` to display the `package.function_name:line_number` as you previously had.
306
+
307
+
Logger allows you to either change the format or suppress the following keys altogether at the initialization: `location`, `timestamp`, `level`, and `datefmt`
308
+
309
+
```python
310
+
from aws_lambda_powertools import Logger
311
+
312
+
# override default values for location and timestamp format
Alternatively, you can also change the order of the following log record keys via the `log_record_order` parameter: `level`, location`, message`, and timestamp`
0 commit comments