Parse level option like adb logcat style. Levels (ascending severity): L (log) < W (warning) < E (error) < X (exception) Assert (A) is treated as same level as error. Examples: "E" -> ["error", "exception"] (error and above) "W" -> ["warning", "error", "assert", "ex
(level: str)
| 23 | |
| 24 | |
| 25 | def _parse_level(level: str) -> list[str]: |
| 26 | """Parse level option like adb logcat style. |
| 27 | |
| 28 | Levels (ascending severity): L (log) < W (warning) < E (error) < X (exception) |
| 29 | Assert (A) is treated as same level as error. |
| 30 | |
| 31 | Examples: |
| 32 | "E" -> ["error", "exception"] (error and above) |
| 33 | "W" -> ["warning", "error", "assert", "exception"] (warning and above) |
| 34 | "+W" -> ["warning"] (warning only) |
| 35 | "+E+X" -> ["error", "exception"] (specific types only) |
| 36 | """ |
| 37 | level = level.upper().strip() |
| 38 | |
| 39 | # Hierarchy mapping (level -> types at that level and above) |
| 40 | hierarchy = { |
| 41 | "L": ["log", "warning", "error", "assert", "exception"], |
| 42 | "W": ["warning", "error", "assert", "exception"], |
| 43 | "E": ["error", "assert", "exception"], |
| 44 | "A": ["error", "assert", "exception"], # Assert same as Error level |
| 45 | "X": ["exception"], |
| 46 | } |
| 47 | |
| 48 | # Type mapping for specific selection |
| 49 | type_map = { |
| 50 | "L": "log", |
| 51 | "W": "warning", |
| 52 | "E": "error", |
| 53 | "A": "assert", |
| 54 | "X": "exception", |
| 55 | } |
| 56 | |
| 57 | # Specific types mode: +E+W or +E |
| 58 | if level.startswith("+"): |
| 59 | types = [] |
| 60 | for char in level.replace("+", " ").split(): |
| 61 | if char in type_map: |
| 62 | types.append(type_map[char]) |
| 63 | return types if types else ["log", "warning", "error", "assert", "exception"] |
| 64 | |
| 65 | # Hierarchy mode: E -> error and above |
| 66 | if level in hierarchy: |
| 67 | return hierarchy[level] |
| 68 | |
| 69 | # Invalid level, return all |
| 70 | return ["log", "warning", "error", "assert", "exception"] |
| 71 | |
| 72 | |
| 73 | @console_app.command("get") |