-
Notifications
You must be signed in to change notification settings - Fork 136
app/vmui: add log level detection with disable option #1377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Loori-R
wants to merge
1
commit into
master
Choose a base branch
from
vmui/issue-1245/log-level-detection
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| export const LOG_LEVEL_UNKNOWN = "other"; | ||
|
|
||
| export const LOG_LEVEL_COLORS = { | ||
| trace: "#20BFC0", | ||
| debug: "#4771E2", | ||
| info: "#62A53B", | ||
| warn: "#F27800", | ||
| error: "#D2323B", | ||
| fatal: "#9C50D3", | ||
| [LOG_LEVEL_UNKNOWN]: "#A09F9F", | ||
| } as const; | ||
|
|
||
| export const LOG_LEVEL_FIELDS = [ | ||
| "level", | ||
|
hagen1778 marked this conversation as resolved.
|
||
| "lvl", | ||
| "log_level", | ||
| "log.level", | ||
| "loglevel", | ||
|
|
||
| "SeverityText", | ||
| "severityText", | ||
| "severity_text", | ||
| "severity", | ||
|
arturminchukov marked this conversation as resolved.
|
||
|
|
||
| "levelname", | ||
| "level_name", | ||
|
|
||
| "@l", | ||
| "@level", | ||
|
|
||
| "logLevel", | ||
| "logLevelName", | ||
|
|
||
| "detected_level", | ||
| "status", | ||
|
|
||
| "syslog.severity.name", | ||
| "log.syslog.severity.name", | ||
|
|
||
| "Level", | ||
| "severityLevel", | ||
| "log_severity", | ||
| "severityValue", | ||
| ] as const; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { LOG_LEVEL_COLORS, LOG_LEVEL_FIELDS, LOG_LEVEL_UNKNOWN } from "../constants/logLevel"; | ||
| import type { Logs } from "../api/types"; | ||
| import { getLogLevel, getLogLevelColor } from "./logLevel"; | ||
|
|
||
| type LogLevel = keyof typeof LOG_LEVEL_COLORS; | ||
|
|
||
| const log = (fields: Record<string, unknown>): Logs => fields as Logs; | ||
| const logLevels = Object.keys(LOG_LEVEL_COLORS) as LogLevel[]; | ||
|
|
||
| describe("logLevel utils", () => { | ||
| describe("getLogLevel", () => { | ||
| it("returns unknown for empty log", () => { | ||
| expect(getLogLevel(log({}))).toBe(LOG_LEVEL_UNKNOWN); | ||
| }); | ||
|
|
||
| it("returns unknown for unrecognized field and value", () => { | ||
| expect(getLogLevel(log({ foo: "bar" }))).toBe(LOG_LEVEL_UNKNOWN); | ||
| }); | ||
|
|
||
| it("returns unknown for numeric value", () => { | ||
| expect(getLogLevel(log({ level: 30 }))).toBe(LOG_LEVEL_UNKNOWN); | ||
| }); | ||
|
|
||
| it("returns unknown for null value", () => { | ||
| expect(getLogLevel(log({ level: null }))).toBe(LOG_LEVEL_UNKNOWN); | ||
| }); | ||
|
|
||
| it.each(LOG_LEVEL_FIELDS)("detects level from field \"%s\"", (field) => { | ||
| expect(getLogLevel(log({ [field]: "error" }))).toBe("error"); | ||
| }); | ||
|
|
||
| it("prefers 'level' over 'severity'", () => { | ||
| expect(getLogLevel(log({ level: "debug", severity: "error" }))).toBe("debug"); | ||
| }); | ||
|
|
||
| it("prefers 'severity' over 'status'", () => { | ||
| expect(getLogLevel(log({ severity: "warn", status: "error" }))).toBe("warn"); | ||
| }); | ||
|
|
||
| it("skips unknown value and continues checking next fields", () => { | ||
| expect(getLogLevel(log({ level: "custom", severity: "error" }))).toBe("error"); | ||
| }); | ||
|
|
||
| it("normalizes aliases", () => { | ||
| expect(getLogLevel(log({ level: "verbose" }))).toBe("debug"); | ||
| expect(getLogLevel(log({ level: "information" }))).toBe("info"); | ||
| expect(getLogLevel(log({ level: "informational" }))).toBe("info"); | ||
| expect(getLogLevel(log({ level: "warning" }))).toBe("warn"); | ||
| expect(getLogLevel(log({ level: "err" }))).toBe("error"); | ||
| expect(getLogLevel(log({ level: "severe" }))).toBe("error"); | ||
| expect(getLogLevel(log({ level: "critical" }))).toBe("fatal"); | ||
| expect(getLogLevel(log({ level: "crit" }))).toBe("fatal"); | ||
| expect(getLogLevel(log({ level: "alert" }))).toBe("fatal"); | ||
| expect(getLogLevel(log({ level: "emergency" }))).toBe("fatal"); | ||
| expect(getLogLevel(log({ level: "emerg" }))).toBe("fatal"); | ||
| expect(getLogLevel(log({ level: "panic" }))).toBe("fatal"); | ||
| }); | ||
|
|
||
| it("handles case-insensitive values", () => { | ||
| expect(getLogLevel(log({ level: "INFO" }))).toBe("info"); | ||
| expect(getLogLevel(log({ level: "Error" }))).toBe("error"); | ||
| expect(getLogLevel(log({ level: "Warn" }))).toBe("warn"); | ||
| }); | ||
|
|
||
| it("trims whitespace from value", () => { | ||
| expect(getLogLevel(log({ level: " info " }))).toBe("info"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("getLogLevelColor", () => { | ||
| it("returns neutral light color for unknown level", () => { | ||
| expect(getLogLevelColor(log({}))).toBe(LOG_LEVEL_COLORS[LOG_LEVEL_UNKNOWN]); | ||
| }); | ||
|
|
||
| it("returns neutral dark color for unknown level", () => { | ||
| expect(getLogLevelColor(log({}))).toBe(LOG_LEVEL_COLORS[LOG_LEVEL_UNKNOWN]); | ||
| }); | ||
|
|
||
| it.each(logLevels.filter((level) => level !== LOG_LEVEL_UNKNOWN))( | ||
| "returns correct light color for level \"%s\"", | ||
| (level) => { | ||
| expect(getLogLevelColor(log({ level }))).toBe(LOG_LEVEL_COLORS[level]); | ||
| }, | ||
| ); | ||
|
|
||
| it.each(logLevels.filter((level) => level !== LOG_LEVEL_UNKNOWN))( | ||
| "returns correct dark color for level \"%s\"", | ||
| (level) => { | ||
| expect(getLogLevelColor(log({ level }))).toBe(LOG_LEVEL_COLORS[level]); | ||
| }, | ||
| ); | ||
|
|
||
| it("returns normalized level color", () => { | ||
| expect(getLogLevelColor(log({ level: "warning" }))).toBe( | ||
| LOG_LEVEL_COLORS.warn, | ||
| ); | ||
| expect(getLogLevelColor(log({ level: "critical" }))).toBe( | ||
| LOG_LEVEL_COLORS.fatal, | ||
| ); | ||
| expect(getLogLevelColor(log({ level: "information" }))).toBe( | ||
| LOG_LEVEL_COLORS.info, | ||
| ); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.