Skip to content

Commit 4f3967f

Browse files
committed
feat: order attributes if logRecordOrder is available
1 parent a8dde6b commit 4f3967f

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

packages/logger/src/formatter/PowertoolsLogFormatter.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,25 @@ class PowertoolsLogFormatter extends LogFormatter {
3535
timestamp: this.formatTimestamp(attributes.timestamp),
3636
xray_trace_id: attributes.xRayTraceId,
3737
};
38-
const powertoolsLogItem = new LogItem({ attributes: baseAttributes });
38+
39+
const orderedAttributes = {} as PowertoolsLog;
40+
41+
// If logRecordOrder is set, order the attributes in the log item
42+
this.logRecordOrder?.forEach((key) => {
43+
if (key in baseAttributes) {
44+
orderedAttributes[key] = baseAttributes[key];
45+
delete baseAttributes[key];
46+
}
47+
});
48+
49+
// Merge the ordered attributes with the rest of the attributes
50+
const powertoolsLogItem = new LogItem({
51+
attributes: {
52+
...orderedAttributes,
53+
...baseAttributes,
54+
},
55+
});
56+
3957
powertoolsLogItem.addAttributes(additionalLogAttributes);
4058

4159
return powertoolsLogItem;

0 commit comments

Comments
 (0)