

Given a list of log entries as strings, write a function that extracts every error code and returns a formatted summary of code frequencies. A valid error code appears either as ERROR_<digits> anywhere in the line or inside a JSON fragment as "error_code":"ERROR_<digits>". Return a list of strings formatted as "ERROR_404: 3", sorted by descending frequency and then lexicographically by code.
Example 1:
Input: logs = [
"[12:00] ERROR_404 File missing",
"[12:01] INFO ok",
"{\"level\":\"error\",\"error_code\":\"ERROR_404\"}",
"[12:02] ERROR_500 Crash"
]
Output: ["ERROR_404: 2", "ERROR_500: 1"]
Explanation: ERROR_404 appears twice and ERROR_500 appears once.
Example 2:
Input: logs = [
"WARN retry",
"{\"error_code\":\"ERROR_401\"}",
"ERROR_401 unauthorized",
"ERROR_403 forbidden"
]
Output: ["ERROR_401: 2", "ERROR_403: 1"]
Explanation: The function counts matching codes across plain text and JSON-like lines.
1 <= len(logs) <= 10^40 <= len(logs[i]) <= 10^3ERROR_<digits>Given a list of log entries as strings, write a function that extracts every error code and returns a formatted summary of code frequencies. A valid error code appears either as ERROR_<digits> anywhere in the line or inside a JSON fragment as "error_code":"ERROR_<digits>". Return a list of strings formatted as "ERROR_404: 3", sorted by descending frequency and then lexicographically by code.
Example 1:
Input: logs = [
"[12:00] ERROR_404 File missing",
"[12:01] INFO ok",
"{\"level\":\"error\",\"error_code\":\"ERROR_404\"}",
"[12:02] ERROR_500 Crash"
]
Output: ["ERROR_404: 2", "ERROR_500: 1"]
Explanation: ERROR_404 appears twice and ERROR_500 appears once.
Example 2:
Input: logs = [
"WARN retry",
"{\"error_code\":\"ERROR_401\"}",
"ERROR_401 unauthorized",
"ERROR_403 forbidden"
]
Output: ["ERROR_401: 2", "ERROR_403: 1"]
Explanation: The function counts matching codes across plain text and JSON-like lines.
1 <= len(logs) <= 10^40 <= len(logs[i]) <= 10^3ERROR_<digits>