Repository navigation
Expand file tree
/
Copy pathlogger.ts
More file actions
50 lines (45 loc) · 1.53 KB
/
Copy pathlogger.ts
File metadata and controls
50 lines (45 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { HttpClientLogLevel } from "../logging/types";
import type { WorkspaceConfiguration } from "vscode";
export const CONNECTION_LOG_BUFFER_SIZE_SETTING =
"coder.connectionLogBuffer.size";
export const DEFAULT_CONNECTION_LOG_BUFFER_SIZE = 1000;
/**
* Largest configurable capacity, in entries.
*/
export const MAX_CONNECTION_LOG_BUFFER_SIZE = 10_000;
const HTTP_CLIENT_LOG_LEVEL_SETTING = "coder.httpClientLogLevel";
/**
* Buffer size in entries, clamped to the maximum; invalid values fall back
* to the default.
*/
export function readConnectionLogBufferSize(
cfg: Pick<WorkspaceConfiguration, "get">,
): number {
const value = cfg.get(
CONNECTION_LOG_BUFFER_SIZE_SETTING,
DEFAULT_CONNECTION_LOG_BUFFER_SIZE,
);
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
return DEFAULT_CONNECTION_LOG_BUFFER_SIZE;
}
return Math.min(Math.floor(value), MAX_CONNECTION_LOG_BUFFER_SIZE);
}
/** HTTP client logging verbosity. Falls back to `BASIC` for unknown values. */
export function readHttpClientLogLevel(
cfg: Pick<WorkspaceConfiguration, "get">,
): HttpClientLogLevel {
const value = cfg.get(
HTTP_CLIENT_LOG_LEVEL_SETTING,
HttpClientLogLevel[HttpClientLogLevel.BASIC],
);
// settings.json can hold a non-string (e.g. 2 or null) despite the schema;
// guard so the axios interceptors never throw on .toUpperCase().
if (typeof value !== "string") {
return HttpClientLogLevel.BASIC;
}
return (
HttpClientLogLevel[
value.toUpperCase() as keyof typeof HttpClientLogLevel
] ?? HttpClientLogLevel.BASIC
);
}