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, each of which need to be completed to provide the necessary functionality.
Define a LogLevel enum that has six cases corresponding to the above log levels, plus an unknown case for levels with missing or non-standard log levels.
tracedebuginfowarningerrorfatalunknownNext, implement the LogLevel initializer to parse the log level of a log line:
LogLevel("[INF]: File deleted")
// Returns LogLevel.info
LogLevel("Something went wrong!")
// Returns 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 simple mapping of a log level to a number:
trace - 0debug - 1info - 4warning - 5error - 6fatal - 7unknown - 42Implement the shortFormat(message: String) -> String method that can output the shortened log line format as a String:
let overflow = LogLevel.error
overflow.shortFormat(message: "Stack overflow")
// Returns "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, each of which need to be completed to provide the necessary functionality.
Define a LogLevel enum that has six cases corresponding to the above log levels, plus an unknown case for levels with missing or non-standard log levels.
tracedebuginfowarningerrorfatalunknownNext, implement the LogLevel initializer to parse the log level of a log line:
LogLevel("[INF]: File deleted")
// Returns LogLevel.info
LogLevel("Something went wrong!")
// Returns 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 simple mapping of a log level to a number:
trace - 0debug - 1info - 4warning - 5error - 6fatal - 7unknown - 42Implement the shortFormat(message: String) -> String method that can output the shortened log line format as a String:
let overflow = LogLevel.error
overflow.shortFormat(message: "Stack overflow")
// Returns "6:Stack overflow"