New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: How to include default / reserved attributes in the log message? #4
Comments
This functionality has been added by the latest 0.0.5 release. Thank you for using the library and providing this support! Please consider starring or sponsoring this project to help continue development! Default Keys You can request that the formatter always include certain attributes on the Notice, the import logging
from logfmter import Logfmter
formatter = Logfmter(keys=["at", "processName"])
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logging.basicConfig(handlers=[handler])
logging.error("hello") # at=ERROR processName=MainProceess msg=hello Utilizing a mapping to convert the Notice, the import logging
from logfmter import Logfmter
formatter = Logfmter(
keys=["at", "process"],
mapping={"at": "levelname", "process": "processName"}
)
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logging.basicConfig(handlers=[handler])
logging.error("hello") # at=ERROR process=MainProceess msg=hello Date Formatting If you request the import logging
from logfmter import Logfmter
formatter = Logfmter(
keys=["at", "when"],
mapping={"at": "levelname", "when": "asctime"},
datefmt="%Y-%m-%d"
)
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logging.basicConfig(handlers=[handler])
logging.error("hello") # at=ERROR when=2022-04-20 msg=hello |
@meitham Let me know if this resolves your question, then I will close this issue. |
@jteppinette Very kind of you to have this feature added at such a short notice, much appreciated. It does indeed solve my issue, thank you very much. |
Thank you for making this library available. I have been looking at the tests and docs but could not find out how I can include some of the keys you defined as "RESERVED" in my message, such as
asctime
. I would like to say::without having to pass
asctime
in as anextra
. I have tried the below in my dictconfig but did not work::Is this possible?
The text was updated successfully, but these errors were encountered: