You’re building a log-processing pipeline for a company’s internal analytics. Logs are generated using this template:
"timestamp=<timestamp> user=<username> action=<action> status=<status> message=<free text>"Each field-value pair is written in the format field=value, as shown. These pairs are separated by spaces.
Before these logs can be shared with an outside team for analysis, the username needs to be retrieved for internal records, and then redacted from the log line so no personally identifying information leaves the system.
Your task is to write two functions:
extract_field takes a log line and a field name, and returns that field’s value.redact_field takes a log line and a field name, and returns a new log line with that field’s value replaced by "[REDACTED]". The original log line must remain unchanged.Given the log line:
"timestamp=2027-01-05T14:32:07 user=ming action=export status=failed message=dashboard export timed out"extract_field(log, "user") should return:"ming"redact_field(log, "user") should return:"timestamp=2027-01-05T14:32:07 user=[REDACTED] action=export status=failed message=dashboard export timed out"