In this exercise you'll be processing log-lines.
Each log line is a string formatted as follows: "[<LVL>]: <MESSAGE>".
These are the different log levels:
TRC (trace)DBG (debug)INF (info)WRN (warning)ERR (error)FTL (fatal)You have three tasks.
Define a LogLevel enum that has six elements corresponding to the above log levels.
TRACEDEBUGINFOWARNINGERRORFATALNext, implement the LogLine.getLogLevel() method that returns the parsed log level of a log line:
var logLine = new LogLine("[INF]: File deleted");
logLine.getLogLevel();
// => LogLevel.INFOUnfortunately, occasionally some log lines have an unknown log level.
To gracefully handle these log lines, add an UNKNOWN element to the LogLevel enum which should be returned when parsing an unknown log level:
var logLine = new LogLine("[XYZ]: Overly specific, out of context message");
logLine.getLogLevel();
// => LogLevel.UNKNOWNThe log level of a log line is quite verbose.
To reduce the disk space needed to store the log lines, a short format is developed: "[<ENCODED_LEVEL>]:<MESSAGE>".
The encoded log level is a simple mapping of a log level to a number:
UNKNOWN - 0TRACE - 1DEBUG - 2INFO - 4WARNING - 5ERROR - 6FATAL - 42Implement the LogLine.getOutputForShortLog() method that can output the shortened log line format:
var logLine = new LogLine("[ERR]: Stack Overflow");
logLine.getOutputForShortLog();
// => "6:Stack Overflow"In this exercise you'll be processing log-lines.
Each log line is a string formatted as follows: "[<LVL>]: <MESSAGE>".
These are the different log levels:
TRC (trace)DBG (debug)INF (info)WRN (warning)ERR (error)FTL (fatal)You have three tasks.
Define a LogLevel enum that has six elements corresponding to the above log levels.
TRACEDEBUGINFOWARNINGERRORFATALNext, implement the LogLine.getLogLevel() method that returns the parsed log level of a log line:
var logLine = new LogLine("[INF]: File deleted");
logLine.getLogLevel();
// => LogLevel.INFOUnfortunately, occasionally some log lines have an unknown log level.
To gracefully handle these log lines, add an UNKNOWN element to the LogLevel enum which should be returned when parsing an unknown log level:
var logLine = new LogLine("[XYZ]: Overly specific, out of context message");
logLine.getLogLevel();
// => LogLevel.UNKNOWNThe log level of a log line is quite verbose.
To reduce the disk space needed to store the log lines, a short format is developed: "[<ENCODED_LEVEL>]:<MESSAGE>".
The encoded log level is a simple mapping of a log level to a number:
UNKNOWN - 0TRACE - 1DEBUG - 2INFO - 4WARNING - 5ERROR - 6FATAL - 42Implement the LogLine.getOutputForShortLog() method that can output the shortened log line format:
var logLine = new LogLine("[ERR]: Stack Overflow");
logLine.getOutputForShortLog();
// => "6:Stack Overflow"