#C216. Extracting Error Messages from Log Files
Extracting Error Messages from Log Files
Extracting Error Messages from Log Files
In this problem, you are given a log file which contains various log entries. Each log entry starts with one of the following prefixes: INFO:
, WARN:
, or ERROR:
. Your task is to extract and output every error message from the log. An error message is defined as a block of consecutive lines that begins with ERROR:
and may span multiple lines until a new log entry (starting with INFO:
, WARN:
, or ERROR:
) is encountered.
For example, if an error message spans multiple lines, the newline characters should be preserved exactly as in the input.
In mathematical notation, if you let denote an error message, then it can be expressed as: [ E = \texttt{ERROR:} ; {\text{line}_1, \text{line}_2, \ldots, \text{line}_k} ] where the block ends immediately before a line that starts with any of the log entry prefixes.
inputFormat
The input is provided via standard input (stdin) as multiple lines representing the contents of a log file. The input terminates at end-of-file (EOF).
outputFormat
Output the extracted error messages to standard output (stdout). If multiple error messages are extracted, they must be printed consecutively while preserving their internal multiline format. There should be no additional characters or delimiters between error messages beyond those present in the original log entries.## sample
INFO: Application started
ERROR: NullPointerException encountered
INFO: User logged in
WARN: Disk space running low
ERROR: ArrayIndexOutOfBoundsException
ERROR: NullPointerException encountered
ERROR: ArrayIndexOutOfBoundsException
</p>