#C13356. Log File Error Counter
Log File Error Counter
Log File Error Counter
You are given a series of log entries. The first line of the input contains a filter log level (for example, ERROR
). Each subsequent line represents a log entry in the format timestamp|log_level|message
. Your task is to count the occurrences of each unique error message that matches the provided log level. The output should be a JSON-formatted dictionary where the keys are the error messages and the values are their corresponding counts.
For example, consider the following input:
ERROR 2023-10-01 12:01:00|ERROR|Failed to connect to database 2023-10-01 12:02:00|ERROR|Failed to connect to database 2023-10-01 12:03:00|ERROR|Service unavailable
The expected output would be:
{"Failed to connect to database": 2, "Service unavailable": 1}
Make sure to read from stdin and write your output to stdout.
inputFormat
The input begins with a single line containing the log level to filter (e.g., ERROR
). Following this, each line represents a log entry in the format:
timestamp|log_level|message
Read until the end of input.
outputFormat
Output a single line: a JSON-formatted dictionary where each key is a distinct error message (from log entries that match the given log level) and its value is the number of times that message occurred.
## sampleERROR
2023-10-01 12:01:00|ERROR|Failed to connect to database
{"Failed to connect to database": 1}