Commit 3c6a7a51 by Emil Tullstedt Committed by GitHub

Logs: Improve log level guess (#22094)

Fixes #22075
parent 5166073f
...@@ -35,6 +35,7 @@ describe('getLoglevel()', () => { ...@@ -35,6 +35,7 @@ describe('getLoglevel()', () => {
it('returns first log level found', () => { it('returns first log level found', () => {
expect(getLogLevel('WARN this could be a debug message')).toBe(LogLevel.warn); expect(getLogLevel('WARN this could be a debug message')).toBe(LogLevel.warn);
expect(getLogLevel('WARN this is a non-critical message')).toBe(LogLevel.warn);
}); });
}); });
......
...@@ -20,16 +20,21 @@ export function getLogLevel(line: string): LogLevel { ...@@ -20,16 +20,21 @@ export function getLogLevel(line: string): LogLevel {
if (!line) { if (!line) {
return LogLevel.unknown; return LogLevel.unknown;
} }
let level = LogLevel.unknown;
let currentIndex: number | undefined = undefined;
for (const key of Object.keys(LogLevel)) { for (const key of Object.keys(LogLevel)) {
const regexp = new RegExp(`\\b${key}\\b`, 'i'); const regexp = new RegExp(`\\b${key}\\b`, 'i');
if (regexp.test(line)) { const result = regexp.exec(line);
const level = (LogLevel as any)[key];
if (level) { if (result) {
return level; if (currentIndex === undefined || result.index < currentIndex) {
level = (LogLevel as any)[key];
currentIndex = result.index;
} }
} }
} }
return LogLevel.unknown; return level;
} }
export function getLogLevelFromKey(key: string): LogLevel { export function getLogLevelFromKey(key: string): LogLevel {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment