-
Notifications
You must be signed in to change notification settings - Fork 47
feat(logging): tag logs with a per-session ID #1073
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
+76
−4
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
29cdab9
feat(logging): tag logs with a per-session ID
aqandrew f4967de
docs: remove waffle
aqandrew 615ea3b
refactor: rename inner to outputChannel
aqandrew 8e09196
chore: rm unused getSessionId function
aqandrew 94e9563
refactor: make SessionLogger's inner a Logger instead of a vscode.Log…
aqandrew 7786bcc
test: initialize SessionLoggers with createMockLogger
aqandrew e5dec0e
refactor(logging): convert SessionLogger to functional prefixLogger
aqandrew 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import type { Logger } from "./logger"; | ||
|
|
||
| /** | ||
| * Wraps a {@link Logger} so every message is prefixed, letting all lines that | ||
| * share a prefix (a session ID, a workspace name) be found with one search. | ||
| * Extra arguments are forwarded untouched. | ||
| */ | ||
| export function prefixLogger(inner: Logger, prefix: string): Logger { | ||
| const tag = (message: string) => `${prefix} ${message}`; | ||
| return { | ||
| trace: (message, ...args) => inner.trace(tag(message), ...args), | ||
| debug: (message, ...args) => inner.debug(tag(message), ...args), | ||
| info: (message, ...args) => inner.info(tag(message), ...args), | ||
| warn: (message, ...args) => inner.warn(tag(message), ...args), | ||
| error: (message, ...args) => inner.error(tag(message), ...args), | ||
| show: () => inner.show(), | ||
| }; | ||
| } |
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,45 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { prefixLogger } from "@/logging/prefixLogger"; | ||
|
|
||
| import { createMockLogger } from "../../mocks/testHelpers"; | ||
|
|
||
| const PREFIX = "[0123456789abcdef0123456789abcdef]"; | ||
|
|
||
| describe("prefixLogger", () => { | ||
| it("prefixes every level with the given prefix", () => { | ||
| const inner = createMockLogger(); | ||
| const logger = prefixLogger(inner, PREFIX); | ||
|
|
||
| logger.trace("trace msg"); | ||
| logger.debug("debug msg"); | ||
| logger.info("info msg"); | ||
| logger.warn("warn msg"); | ||
| logger.error("error msg"); | ||
|
|
||
| expect(inner.trace).toHaveBeenCalledWith(`${PREFIX} trace msg`); | ||
| expect(inner.debug).toHaveBeenCalledWith(`${PREFIX} debug msg`); | ||
| expect(inner.info).toHaveBeenCalledWith(`${PREFIX} info msg`); | ||
| expect(inner.warn).toHaveBeenCalledWith(`${PREFIX} warn msg`); | ||
| expect(inner.error).toHaveBeenCalledWith(`${PREFIX} error msg`); | ||
| }); | ||
|
|
||
| it("forwards additional arguments unchanged", () => { | ||
| const inner = createMockLogger(); | ||
| const logger = prefixLogger(inner, PREFIX); | ||
| const err = new Error("boom"); | ||
|
|
||
| logger.error("failed", err, 42); | ||
|
|
||
| expect(inner.error).toHaveBeenCalledWith(`${PREFIX} failed`, err, 42); | ||
| }); | ||
|
|
||
| it("delegates show() to the underlying logger", () => { | ||
| const inner = createMockLogger(); | ||
| const logger = prefixLogger(inner, PREFIX); | ||
|
|
||
| logger.show(); | ||
|
|
||
| expect(inner.show).toHaveBeenCalledOnce(); | ||
| }); | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this comment will go once we have a the file with a session ID defined at runtime