Comparing exercism:main...AbhinavKRN:main · exercism/java
Commits on Nov 11, 2023
-
### Pull Request: Log Line Processing #### Introduction This pull request introduces enhancements to the LogLine processing in the form of a LogLevel enum, improved log level parsing, support for unknown log levels, and a short log format. #### Changes Made 1. **LogLevel Enum** - Added a `LogLevel` enum with elements corresponding to different log levels: - `UNKNOWN` - `TRACE` - `DEBUG` - `INFO` - `WARNING` - `ERROR` - `FATAL` 2. **Improved Log Level Parsing** - Implemented the `getLogLevel()` method in the `LogLine` class to extract and return the log level from a log line string. - The method uses a switch statement to map the log level string to the corresponding enum value. ```java var logLine = new LogLine("[INF]: File deleted"); logLine.getLogLevel(); // => LogLevel.INFO ``` 3. **Support for Unknown Log Levels** - Added an `UNKNOWN` element to the `LogLevel` enum to gracefully handle log lines with unknown log levels. - If the log level cannot be determined, the method returns `LogLevel.UNKNOWN`. ```java var logLine = new LogLine("[XYZ]: Overly specific, out of context message"); logLine.getLogLevel(); // => LogLevel.UNKNOWN ``` 4. **Short Log Format** - Implemented the `getOutputForShortLog()` method in the `LogLine` class to generate a shortened log line format. - The encoded log level is a simple mapping of log levels to numbers. - The method returns a string in the format: `"<ENCODED_LEVEL>:<MESSAGE>"`. ```java var logLine = new LogLine("[ERR]: Stack Overflow"); logLine.getOutputForShortLog(); // => "6:Stack Overflow" ``` #### How to Use 1. **Get Log Level** - To retrieve the log level of a log line, use the `getLogLevel()` method. ```java var logLine = new LogLine("[INF]: File deleted"); LogLevel level = logLine.getLogLevel(); ``` 2. **Handle Unknown Log Levels** - The `getLogLevel()` method gracefully handles unknown log levels by returning `LogLevel.UNKNOWN`. ```java var logLine = new LogLine("[XYZ]: Overly specific, out of context message"); LogLevel level = logLine.getLogLevel(); // level is LogLevel.UNKNOWN ``` 3. **Short Log Format** - To obtain a shortened log line format, use the `getOutputForShortLog()` method. ```java var logLine = new LogLine("[ERR]: Stack Overflow"); String shortLog = logLine.getOutputForShortLog(); // shortLog is "6:Stack Overflow" ``` #### Additional Notes - Ensure existing code that uses the `LogLine` class is updated to leverage the new functionalities introduced in this pull request. - Review and test the changes thoroughly to ensure compatibility and correctness. #### Checklist - [ ] Code has been tested locally. - [ ] Documentation has been updated to reflect the changes. - [ ] No breaking changes introduced.