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
Currently the formats are declared using JSON or YAML, but I need to pass a variable, specifically the MAC of the machine. How could I insert a variable into the formatter?
The text was updated successfully, but these errors were encountered:
Assume that you add %(MAC)s into the format fields of formatters in either JSON or YAML.
Then at runtime, you simply add the same attribute name into the logging record by adding a filter to a handler.
The set_context_injector below is a shortcut to add a filter to every handler of the root logger.
my_mac='AA:BB:CC:DD:EE:FF'defmac_filter(record):
# Add a MAC property to the recordrecord.MAC=my_mac# return False will discard this recordreturnTruelog_config=setup_logging()
log_config.set_context_injector(mac_filter)
Not tested yet, but hope it works well for you.
Have a good day!
Currently the formats are declared using JSON or YAML, but I need to pass a variable, specifically the MAC of the machine. How could I insert a variable into the formatter?
The text was updated successfully, but these errors were encountered: