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
+21-13
Original file line number
Diff line number
Diff line change
@@ -273,34 +273,37 @@ You can append additional persistent keys and values in the logs generated durin
273
273
274
274
!!! tip "Logger will automatically ignore any key with an `undefined` value"
275
275
276
-
### Appending additional log keys and values to a single log item
276
+
### Appending additional data to a single log item
277
277
278
-
You can append additional keys and values in a single log item passing them as parameters.
279
-
Pass a string for logging it with default key name `extra`. Alternatively, pass one or multiple objects with custom keys.
280
-
If you already have an object containing a `message` key and an additional property, you can pass this object directly.
278
+
You can append additional data to a single log item by passing objects as additional parameters.
279
+
280
+
* Pass a simple string for logging it with default key name `extra`
281
+
* Pass one or multiple objects containing arbitrary data to be logged. Each data object should be placed in an enclosing object as a single property value, you can name this property as you need: `{ myData: arbitraryObjectToLog }`
282
+
* If you already have an object containing a `message` key and an additional property, you can pass this object directly
281
283
282
284
=== "handler.ts"
283
285
284
-
```typescript hl_lines="14 18-19 23 31"
286
+
```typescript hl_lines="14 18-20 24 32"
285
287
import { Logger } from '@aws-lambda-powertools/logger';
logger[methodOfLogger]('A log item with a string as first parameter, and an error as second parameter',newError('Something happened!'));
290
298
logger[methodOfLogger]('A log item with a string as first parameter, and an error with custom key as second parameter',{myCustomErrorKey: newError('Something happened!')});
291
299
logger[methodOfLogger]('A log item with a string as first parameter, and a string as second parameter','parameter');
300
+
logger[methodOfLogger]('A log item with a string as first parameter, and an inline object as second parameter',{extra: {custom: mockDate}});
301
+
logger[methodOfLogger]('A log item with a string as first parameter, and an arbitrary object as second parameter',{extra: arbitraryObject});
0 commit comments