Custom Logger And Extra Input #1643
-
When using the logger I can add extra information like the following: That will add three new fields to my log statement with corresponding names:
However when logging with Context the message and additional fields, the data I most want at a glance, is pushed off of the screen and I must expand the log to see it.
To combat this I tried creating a custom logger (just used the example one)
And that makes the message the first field, but I can't find any way to add my custom fields so that the message and additional fields are printed first in the log, followed by everything else. I CAN just do:
But that gets me
Which isn't as useful for log insights. The main concern I have here is I want to see MY data first in the log statement so that I don't have to expand it unless I need more information. Does anyone have any suggestions for how to approach this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @bcolley, thank you for opening this discussion and for considering using Powertools! Your findings are correct. At the moment the This is a limitation of the current implementation and we have an issue (#1261) tracking it. As discussed in the issue giving access to these attributes will require a breaking change, which we are going to release in our next major release. As part of another work stream that also involves the Logger utility, we have completed an RFC #1500 for a feature that will allow full customizability of the format, including the attributes you specify. The feature was merged into the v2 branch in #1511 and we plan to release it between Q3 and early Q4 this year, according to our public roadmap. |
Beta Was this translation helpful? Give feedback.
Hi @bcolley, thank you for opening this discussion and for considering using Powertools!
Your findings are correct. At the moment the
LogFormatter.formatAttributes()
method only receives the standard attributes (aka the ones managed by Logger) but doesn't receive the ones you add afterwards. For reference, here you can see which fields are included in theUnformattedAttributes
type.This is a limitation of the current implementation and we have an issue (#1261) tracking it. As discussed in the issue giving access to these attributes will require a breaking change, which we are going to release in our next major release.
As part of another work stream that also involves the Logger utility,…