@hydranium/cli 1.0.0-next.189 → 1.0.0-next.192

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/lib/commands/ast-ground-truth-args.js +5 -5
  2. package/lib/commands/ast-ground-truth-args.js.map +1 -1
  3. package/lib/commands/harness-args.d.ts +19 -35
  4. package/lib/commands/harness-args.d.ts.map +1 -1
  5. package/lib/commands/harness-args.js +38 -16
  6. package/lib/commands/harness-args.js.map +1 -1
  7. package/lib/commands/headless-harness.d.ts +14 -15
  8. package/lib/commands/headless-harness.d.ts.map +1 -1
  9. package/lib/commands/headless-harness.js +8 -8
  10. package/lib/commands/headless-harness.js.map +1 -1
  11. package/lib/commands/lint-grammar-args.js +5 -5
  12. package/lib/commands/lint-grammar-args.js.map +1 -1
  13. package/lib/commands/measure-memory-args.d.ts.map +1 -1
  14. package/lib/commands/measure-memory-args.js +11 -4
  15. package/lib/commands/measure-memory-args.js.map +1 -1
  16. package/lib/commands/model-docs-args.js +5 -5
  17. package/lib/commands/model-docs-args.js.map +1 -1
  18. package/lib/commands/projects-args.d.ts.map +1 -1
  19. package/lib/commands/projects-args.js +5 -5
  20. package/lib/commands/projects-args.js.map +1 -1
  21. package/lib/commands/projects.d.ts +3 -4
  22. package/lib/commands/projects.d.ts.map +1 -1
  23. package/lib/commands/projects.js +2 -2
  24. package/lib/commands/projects.js.map +1 -1
  25. package/lib/commands/query-args.d.ts.map +1 -1
  26. package/lib/commands/query-args.js +5 -5
  27. package/lib/commands/query-args.js.map +1 -1
  28. package/lib/commands/query.d.ts +3 -4
  29. package/lib/commands/query.d.ts.map +1 -1
  30. package/lib/commands/query.js +2 -2
  31. package/lib/commands/query.js.map +1 -1
  32. package/lib/commands/reflect-args.js +5 -5
  33. package/lib/commands/reflect-args.js.map +1 -1
  34. package/lib/commands/save-args.d.ts.map +1 -1
  35. package/lib/commands/save-args.js +6 -4
  36. package/lib/commands/save-args.js.map +1 -1
  37. package/lib/commands/save.d.ts +3 -4
  38. package/lib/commands/save.d.ts.map +1 -1
  39. package/lib/commands/save.js +2 -2
  40. package/lib/commands/save.js.map +1 -1
  41. package/lib/commands/validate-args.js +5 -5
  42. package/lib/commands/validate-args.js.map +1 -1
  43. package/lib/commands/watch-args.d.ts.map +1 -1
  44. package/lib/commands/watch-args.js +6 -4
  45. package/lib/commands/watch-args.js.map +1 -1
  46. package/lib/commands/watch.d.ts +3 -4
  47. package/lib/commands/watch.d.ts.map +1 -1
  48. package/lib/commands/watch.js +2 -2
  49. package/lib/commands/watch.js.map +1 -1
  50. package/lib/log-level.d.ts +21 -11
  51. package/lib/log-level.d.ts.map +1 -1
  52. package/lib/log-level.js +25 -14
  53. package/lib/log-level.js.map +1 -1
  54. package/package.json +9 -9
  55. package/src/commands/ast-ground-truth-args.ts +7 -7
  56. package/src/commands/harness-args.ts +42 -19
  57. package/src/commands/headless-harness.ts +15 -20
  58. package/src/commands/lint-grammar-args.ts +7 -7
  59. package/src/commands/measure-memory-args.ts +14 -6
  60. package/src/commands/model-docs-args.ts +7 -7
  61. package/src/commands/projects-args.ts +5 -4
  62. package/src/commands/projects.ts +4 -6
  63. package/src/commands/query-args.ts +5 -4
  64. package/src/commands/query.ts +4 -6
  65. package/src/commands/reflect-args.ts +7 -7
  66. package/src/commands/save-args.ts +6 -3
  67. package/src/commands/save.ts +4 -6
  68. package/src/commands/validate-args.ts +7 -7
  69. package/src/commands/watch-args.ts +6 -3
  70. package/src/commands/watch.ts +4 -6
  71. package/src/log-level.ts +42 -14
@@ -11,6 +11,7 @@ import {
11
11
  assertRequired,
12
12
  exitWithUsage,
13
13
  helpRequested,
14
+ logHelpLines,
14
15
  parseFlagOptions,
15
16
  parseServerSpawnOptions,
16
17
  printHelp,
@@ -35,7 +36,7 @@ export const QUERY_VALUE_FLAGS: readonly string[] = QUERY_FLAGS;
35
36
 
36
37
  /** The `--help` text, as data, held to {@link QUERY_FLAGS} by a test. */
37
38
  export const QUERY_HELP: readonly string[] = [
38
- 'Usage: hydranium-cli query --server "<cmd> [args...]" --uri <uri> [--cwd <dir>] [--log-level <level>]',
39
+ 'Usage: hydranium-cli query --server "<cmd> [args...]" --uri <uri> [--cwd <dir>] [--log-level <lvl>] [--log-file <file>] [--log-file-level <lvl>]',
39
40
  '',
40
41
  'Print the data-server document envelope for `<uri>` as a single JSON line.',
41
42
  '',
@@ -43,13 +44,13 @@ export const QUERY_HELP: readonly string[] = [
43
44
  ' --server "<cmd>" Command-line for the data-server subprocess (required).',
44
45
  ' --uri <uri> Document URI (required).',
45
46
  ' --cwd <dir> Working directory for the spawned child. Default: cwd.',
46
- ' --log-level <lvl> Log threshold for the spawned server (off|error|warn|info|debug|trace).'
47
+ ...logHelpLines(19, 'the spawned server')
47
48
  ];
48
49
 
49
50
  export function parseQueryArgs(args: string[], onError: UsageError = exitWithUsage): QueryCommandOptions {
50
- const { serverCommand, serverArgs, cwd, logLevel, extra } = parseServerSpawnOptions(args, 'query', onError);
51
+ const { serverCommand, serverArgs, cwd, logLevel, logFile, logFileLevel, extra } = parseServerSpawnOptions(args, 'query', onError);
51
52
  const { uri } = parseFlagOptions(extra, 'query', OWN_FLAGS, onError);
52
- return { serverCommand, serverArgs, cwd, logLevel, uri: assertRequired(uri, '--uri', 'query', onError) };
53
+ return { serverCommand, serverArgs, cwd, logLevel, logFile, logFileLevel, uri: assertRequired(uri, '--uri', 'query', onError) };
53
54
  }
54
55
 
55
56
  export function runQueryCommand(args: string[]): Promise<void> {
@@ -7,9 +7,9 @@
7
7
  * SPDX-License-Identifier: MIT
8
8
  ********************************************************************************/
9
9
 
10
- import type { LogThreshold, TransferElement } from '@hydranium/protocol';
10
+ import type { TransferElement } from '@hydranium/protocol';
11
11
  import type { DataServerProtocol } from '@hydranium/protocol/data';
12
- import { logLevelEnv } from '../log-level.js';
12
+ import { logEnv, type LogOptions } from '../log-level.js';
13
13
  import { withDataServer } from '../spawn-data-server.js';
14
14
 
15
15
  /**
@@ -22,12 +22,10 @@ import { withDataServer } from '../spawn-data-server.js';
22
22
  * Test-only `__proxyForTest` bypasses the spawn for unit tests; the
23
23
  * production CLI never passes it.
24
24
  */
25
- export interface QueryCommandOptions {
25
+ export interface QueryCommandOptions extends LogOptions {
26
26
  readonly serverCommand: string;
27
27
  readonly serverArgs?: readonly string[];
28
28
  readonly cwd?: string;
29
- /** Log threshold for the spawned server, set on its `HYDRANIUM_LOG_LEVEL` env. */
30
- readonly logLevel?: LogThreshold;
31
29
  readonly uri: string;
32
30
  readonly write?: (line: string) => void;
33
31
  readonly __proxyForTest?: DataServerProtocol<TransferElement>;
@@ -48,7 +46,7 @@ export async function runQuery(options: QueryCommandOptions): Promise<void> {
48
46
  command: options.serverCommand,
49
47
  args: options.serverArgs,
50
48
  cwd: options.cwd,
51
- env: options.logLevel ? logLevelEnv(options.logLevel) : undefined
49
+ env: logEnv(options)
52
50
  },
53
51
  async server => {
54
52
  const doc = await server.getModelDocument({ uri: options.uri, includeDiagnostics: true });
@@ -10,9 +10,9 @@
10
10
  import {
11
11
  exitWithUsage,
12
12
  helpRequested,
13
- LOG_LEVEL_FLAG,
14
- logLevelHelpLine,
15
- logLevelOption,
13
+ LOG_VALUE_FLAGS,
14
+ logHelpLines,
15
+ logOptions,
16
16
  parseHarnessArgs,
17
17
  printHelp,
18
18
  SERVICES_FLAG,
@@ -21,7 +21,7 @@ import {
21
21
  import { OUT_FILE_FLAG } from './headless-harness.js';
22
22
  import { runReflect, type ReflectCommandOptions } from './reflect.js';
23
23
 
24
- const VALUE_FLAGS = [OUT_FILE_FLAG, LOG_LEVEL_FLAG] as const;
24
+ const VALUE_FLAGS = [OUT_FILE_FLAG, ...LOG_VALUE_FLAGS] as const;
25
25
  const BOOL_FLAGS = ['--json'] as const;
26
26
 
27
27
  /**
@@ -36,7 +36,7 @@ export const REFLECT_VALUE_FLAGS: readonly string[] = [SERVICES_FLAG, ...VALUE_F
36
36
 
37
37
  /** The `--help` text, as data, held to {@link REFLECT_FLAGS} by a test. */
38
38
  export const REFLECT_HELP: readonly string[] = [
39
- 'Usage: hydranium-cli reflect --services <module> [--json] [--out-file <file>] [--log-level <lvl>]',
39
+ 'Usage: hydranium-cli reflect --services <module> [--json] [--out-file <file>] [--log-level <lvl>] [--log-file <file>] [--log-file-level <lvl>]',
40
40
  '',
41
41
  "Dump a head's grammar/AST reflection — the type hierarchy, each language's",
42
42
  'terminals and entry rule, and every cross-reference target. Read-only: no',
@@ -50,7 +50,7 @@ export const REFLECT_HELP: readonly string[] = [
50
50
  ' --out-file <file> Write the report to this file instead of stdout. Written',
51
51
  ' only once the report exists, unlike a shell redirection,',
52
52
  ' which truncates the file before the head is even booted.',
53
- logLevelHelpLine(22)
53
+ ...logHelpLines(22)
54
54
  ];
55
55
 
56
56
  export function parseReflectArgs(args: string[], onError: UsageError = exitWithUsage): ReflectCommandOptions {
@@ -62,7 +62,7 @@ export function parseReflectArgs(args: string[], onError: UsageError = exitWithU
62
62
  servicesModule,
63
63
  json: options['--json'] === 'true',
64
64
  outFile: options[OUT_FILE_FLAG],
65
- logLevel: logLevelOption(options[LOG_LEVEL_FLAG])
65
+ ...logOptions(options)
66
66
  };
67
67
  }
68
68
 
@@ -11,6 +11,7 @@ import {
11
11
  assertRequired,
12
12
  exitWithUsage,
13
13
  helpRequested,
14
+ logHelpLines,
14
15
  parseFlagOptions,
15
16
  parseServerSpawnOptions,
16
17
  printHelp,
@@ -36,7 +37,7 @@ export const SAVE_VALUE_FLAGS: readonly string[] = SAVE_FLAGS;
36
37
 
37
38
  /** The `--help` text, as data, held to {@link SAVE_FLAGS} by a test. */
38
39
  export const SAVE_HELP: readonly string[] = [
39
- 'Usage: hydranium-cli save --server "<cmd>..." --uri <uri> --content <text|@file> [--client-id <id>] [--cwd <dir>] [--log-level <level>]',
40
+ 'Usage: hydranium-cli save --server "<cmd>..." --uri <uri> --content <text|@file> [--client-id <id>] [--cwd <dir>] [--log-level <lvl>] [--log-file <file>] [--log-file-level <lvl>]',
40
41
  '',
41
42
  'Update the document at `<uri>` with `<content>` and persist via saveModelDocument.',
42
43
  'Output is the post-save envelope as a single JSON line.',
@@ -48,17 +49,19 @@ export const SAVE_HELP: readonly string[] = [
48
49
  ' (escape with `\\@` for literal `@`-leading content).',
49
50
  ' --client-id <id> clientId for authorship attribution. Default: hydranium-cli.',
50
51
  ' --cwd <dir> Working directory for the spawned child. Default: cwd.',
51
- ' --log-level <lvl> Log threshold for the spawned server (off|error|warn|info|debug|trace).'
52
+ ...logHelpLines(22, 'the spawned server')
52
53
  ];
53
54
 
54
55
  export function parseSaveArgs(args: string[], onError: UsageError = exitWithUsage): SaveCommandOptions {
55
- const { serverCommand, serverArgs, cwd, logLevel, extra } = parseServerSpawnOptions(args, 'save', onError);
56
+ const { serverCommand, serverArgs, cwd, logLevel, logFile, logFileLevel, extra } = parseServerSpawnOptions(args, 'save', onError);
56
57
  const { uri, content, clientId } = parseFlagOptions(extra, 'save', OWN_FLAGS, onError);
57
58
  return {
58
59
  serverCommand,
59
60
  serverArgs,
60
61
  cwd,
61
62
  logLevel,
63
+ logFile,
64
+ logFileLevel,
62
65
  uri: assertRequired(uri, '--uri', 'save', onError),
63
66
  content: assertRequired(content, '--content', 'save', onError),
64
67
  clientId
@@ -7,10 +7,10 @@
7
7
  * SPDX-License-Identifier: MIT
8
8
  ********************************************************************************/
9
9
 
10
- import type { LogThreshold, TransferElement } from '@hydranium/protocol';
10
+ import type { TransferElement } from '@hydranium/protocol';
11
11
  import type { DataServerProtocol } from '@hydranium/protocol/data';
12
12
  import * as fs from 'node:fs/promises';
13
- import { logLevelEnv } from '../log-level.js';
13
+ import { logEnv, type LogOptions } from '../log-level.js';
14
14
  import { withDataServer } from '../spawn-data-server.js';
15
15
 
16
16
  /**
@@ -29,12 +29,10 @@ import { withDataServer } from '../spawn-data-server.js';
29
29
  * opens it otherwise, saves, and ends the session, which leaves nothing open
30
30
  * behind it.
31
31
  */
32
- export interface SaveCommandOptions {
32
+ export interface SaveCommandOptions extends LogOptions {
33
33
  readonly serverCommand: string;
34
34
  readonly serverArgs?: readonly string[];
35
35
  readonly cwd?: string;
36
- /** Log threshold for the spawned server, set on its `HYDRANIUM_LOG_LEVEL` env. */
37
- readonly logLevel?: LogThreshold;
38
36
  readonly uri: string;
39
37
  /** Literal content text, or `@<path>` to read from a file. */
40
38
  readonly content: string;
@@ -60,7 +58,7 @@ export async function runSave(options: SaveCommandOptions): Promise<void> {
60
58
  command: options.serverCommand,
61
59
  args: options.serverArgs,
62
60
  cwd: options.cwd,
63
- env: options.logLevel ? logLevelEnv(options.logLevel) : undefined
61
+ env: logEnv(options)
64
62
  },
65
63
  async server => {
66
64
  write(`${JSON.stringify(await saveOpened(server, options.uri, clientId, model))}\n`);
@@ -10,9 +10,9 @@
10
10
  import {
11
11
  exitWithUsage,
12
12
  helpRequested,
13
- LOG_LEVEL_FLAG,
14
- logLevelHelpLine,
15
- logLevelOption,
13
+ LOG_VALUE_FLAGS,
14
+ logHelpLines,
15
+ logOptions,
16
16
  parseHarnessArgs,
17
17
  printHelp,
18
18
  SERVICES_FLAG,
@@ -21,7 +21,7 @@ import {
21
21
  import { OUT_FILE_FLAG } from './headless-harness.js';
22
22
  import { runValidate, type ValidateCommandOptions } from './validate.js';
23
23
 
24
- const VALUE_FLAGS = [OUT_FILE_FLAG, LOG_LEVEL_FLAG] as const;
24
+ const VALUE_FLAGS = [OUT_FILE_FLAG, ...LOG_VALUE_FLAGS] as const;
25
25
  const BOOL_FLAGS = ['--strict', '--json'] as const;
26
26
 
27
27
  /**
@@ -36,7 +36,7 @@ export const VALIDATE_VALUE_FLAGS: readonly string[] = [SERVICES_FLAG, ...VALUE_
36
36
 
37
37
  /** The `--help` text, as data, held to {@link VALIDATE_FLAGS} by a test. */
38
38
  export const VALIDATE_HELP: readonly string[] = [
39
- 'Usage: hydranium-cli validate --services <module> <workspace> [--strict] [--json] [--out-file <file>] [--log-level <lvl>]',
39
+ 'Usage: hydranium-cli validate --services <module> <workspace> [--strict] [--json] [--out-file <file>] [--log-level <lvl>] [--log-file <file>] [--log-file-level <lvl>]',
40
40
  '',
41
41
  'Build a workspace headlessly and report its validation diagnostics — a CI gate:',
42
42
  'the process exits non-zero when any error is found. `<module>` is an ESM module',
@@ -52,7 +52,7 @@ export const VALIDATE_HELP: readonly string[] = [
52
52
  ' still decides the exit code, and the file is written only',
53
53
  ' once the report exists, unlike a shell redirection, which',
54
54
  ' truncates the file before the workspace is even built.',
55
- logLevelHelpLine(22)
55
+ ...logHelpLines(22)
56
56
  ];
57
57
 
58
58
  export function parseValidateArgs(args: string[], onError: UsageError = exitWithUsage): ValidateCommandOptions {
@@ -63,7 +63,7 @@ export function parseValidateArgs(args: string[], onError: UsageError = exitWith
63
63
  strict: options['--strict'] === 'true',
64
64
  json: options['--json'] === 'true',
65
65
  outFile: options[OUT_FILE_FLAG],
66
- logLevel: logLevelOption(options[LOG_LEVEL_FLAG])
66
+ ...logOptions(options)
67
67
  };
68
68
  }
69
69
 
@@ -11,6 +11,7 @@ import {
11
11
  assertRequired,
12
12
  exitWithUsage,
13
13
  helpRequested,
14
+ logHelpLines,
14
15
  parseFlagOptions,
15
16
  parseServerSpawnOptions,
16
17
  printHelp,
@@ -35,7 +36,7 @@ export const WATCH_VALUE_FLAGS: readonly string[] = WATCH_FLAGS;
35
36
 
36
37
  /** The `--help` text, as data, held to {@link WATCH_FLAGS} by a test. */
37
38
  export const WATCH_HELP: readonly string[] = [
38
- 'Usage: hydranium-cli watch --server "<cmd>..." --uri <uri> [--client-id <id>] [--cwd <dir>] [--log-level <level>]',
39
+ 'Usage: hydranium-cli watch --server "<cmd>..." --uri <uri> [--client-id <id>] [--cwd <dir>] [--log-level <lvl>] [--log-file <file>] [--log-file-level <lvl>]',
39
40
  '',
40
41
  'Subscribe to document updates at `<uri>` and print events as newline-delimited',
41
42
  'JSON. Long-running — exits cleanly on SIGINT (Ctrl-C).',
@@ -45,18 +46,20 @@ export const WATCH_HELP: readonly string[] = [
45
46
  ' --uri <uri> Document URI (required).',
46
47
  ' --client-id <id> Subscriber identity. Default: hydranium-cli.',
47
48
  ' --cwd <dir> Working directory for the spawned child. Default: cwd.',
48
- ' --log-level <lvl> Log threshold for the spawned server (off|error|warn|info|debug|trace).'
49
+ ...logHelpLines(22, 'the spawned server')
49
50
  ];
50
51
 
51
52
  /** Parse the argv; the abort signal is the entry point's to supply, not the command line's. */
52
53
  export function parseWatchArgs(args: string[], onError: UsageError = exitWithUsage): WatchCommandOptions {
53
- const { serverCommand, serverArgs, cwd, logLevel, extra } = parseServerSpawnOptions(args, 'watch', onError);
54
+ const { serverCommand, serverArgs, cwd, logLevel, logFile, logFileLevel, extra } = parseServerSpawnOptions(args, 'watch', onError);
54
55
  const { uri, clientId } = parseFlagOptions(extra, 'watch', OWN_FLAGS, onError);
55
56
  return {
56
57
  serverCommand,
57
58
  serverArgs,
58
59
  cwd,
59
60
  logLevel,
61
+ logFile,
62
+ logFileLevel,
60
63
  uri: assertRequired(uri, '--uri', 'watch', onError),
61
64
  clientId
62
65
  };
@@ -7,14 +7,14 @@
7
7
  * SPDX-License-Identifier: MIT
8
8
  ********************************************************************************/
9
9
 
10
- import type { LogThreshold, TransferElement } from '@hydranium/protocol';
10
+ import type { TransferElement } from '@hydranium/protocol';
11
11
  import type {
12
12
  DataClientProtocol,
13
13
  DataServerProtocol,
14
14
  TransferDocumentDeletedEvent,
15
15
  TransferDocumentUpdatedEvent
16
16
  } from '@hydranium/protocol/data';
17
- import { logLevelEnv } from '../log-level.js';
17
+ import { logEnv, type LogOptions } from '../log-level.js';
18
18
  import { spawnDataServer } from '../spawn-data-server.js';
19
19
 
20
20
  /**
@@ -27,12 +27,10 @@ import { spawnDataServer } from '../spawn-data-server.js';
27
27
  * — production CLI wires SIGINT directly. `__handleForTest` bypasses
28
28
  * the spawn step for unit tests.
29
29
  */
30
- export interface WatchCommandOptions {
30
+ export interface WatchCommandOptions extends LogOptions {
31
31
  readonly serverCommand: string;
32
32
  readonly serverArgs?: readonly string[];
33
33
  readonly cwd?: string;
34
- /** Log threshold for the spawned server, set on its `HYDRANIUM_LOG_LEVEL` env. */
35
- readonly logLevel?: LogThreshold;
36
34
  readonly uri: string;
37
35
  readonly clientId?: string;
38
36
  readonly write?: (line: string) => void;
@@ -169,7 +167,7 @@ export async function runWatch(options: WatchCommandOptions): Promise<void> {
169
167
  command: options.serverCommand,
170
168
  args: options.serverArgs,
171
169
  cwd: options.cwd,
172
- env: options.logLevel ? logLevelEnv(options.logLevel) : undefined
170
+ env: logEnv(options)
173
171
  },
174
172
  localClient
175
173
  );
package/src/log-level.ts CHANGED
@@ -7,29 +7,47 @@
7
7
  * SPDX-License-Identifier: MIT
8
8
  ********************************************************************************/
9
9
 
10
- import { DEFAULT_LOG_LEVEL_ENV, LEVEL_ORDER, parseLogLevel, type LogThreshold } from '@hydranium/protocol';
10
+ import {
11
+ DEFAULT_LOG_FILE_ENV,
12
+ DEFAULT_LOG_FILE_LEVEL_ENV,
13
+ DEFAULT_LOG_LEVEL_ENV,
14
+ LEVEL_ORDER,
15
+ parseLogLevel,
16
+ type LogThreshold
17
+ } from '@hydranium/protocol';
18
+
19
+ /** The log flags every subcommand takes, as the env {@link logEnv} hands its child. */
20
+ export interface LogOptions {
21
+ /** Threshold for the client sink; the server's log-level setting replaces it. */
22
+ readonly logLevel?: LogThreshold;
23
+ /** File the server tees its log to; `{workspace}` expands once it is known. */
24
+ readonly logFile?: string;
25
+ /** The file's own threshold, which the log-level setting does not change. */
26
+ readonly logFileLevel?: LogThreshold;
27
+ }
11
28
 
12
29
  /**
13
- * Validate a raw `--log-level` argument into a {@link LogThreshold}. Throws on
14
- * an unrecognised value so the CLI's top-level `catch` surfaces a clean error
15
- * and exits non-zero (mirroring how the other option parsers fail fast). Use
16
- * for the argv-supplied value; the resolved threshold is handed to
17
- * {@link logLevelEnv} to target the spawned server.
30
+ * Validate a raw `--log-level` / `--log-file-level` argument into a
31
+ * {@link LogThreshold}. Throws on an unrecognised value so the CLI's top-level
32
+ * `catch` surfaces a clean error and exits non-zero (mirroring how the other
33
+ * option parsers fail fast). Use for the argv-supplied value; the resolved
34
+ * threshold is handed to {@link logEnv} to target the spawned server.
18
35
  */
19
- export function parseLogLevelOption(raw: string): LogThreshold {
36
+ export function parseLogLevelOption(raw: string, flag = '--log-level'): LogThreshold {
20
37
  const level = parseLogLevel(raw);
21
38
  if (!level) {
22
- throw new Error(`Invalid --log-level: ${raw} (expected one of: ${Object.keys(LEVEL_ORDER).join(', ')})`);
39
+ throw new Error(`Invalid ${flag}: ${raw} (expected one of: ${Object.keys(LEVEL_ORDER).join(', ')})`);
23
40
  }
24
41
  return level;
25
42
  }
26
43
 
27
44
  /**
28
45
  * Build the environment override that targets *only the spawned server's* log
29
- * threshold. Passed to `spawnDataServer` as `env`, it sets the same
30
- * `HYDRANIUM_LOG_LEVEL` variable the server reads at startup — the CLI's own
31
- * logging is unaffected, unlike an ambient `HYDRANIUM_LOG_LEVEL=…` that the
32
- * child would inherit alongside the parent. The server owns *how* log level
46
+ * configuration, or `undefined` when no log flag was given. Passed to
47
+ * `spawnDataServer` as `env`, it sets the same `HYDRANIUM_LOG_LEVEL` /
48
+ * `HYDRANIUM_LOG_FILE` / `HYDRANIUM_LOG_FILE_LEVEL` variables the server reads
49
+ * at startup — the CLI's own logging is unaffected, unlike ambient variables
50
+ * that the child would inherit alongside the parent. The server owns *how* log level
33
51
  * works; this only routes the CLI's request onto the channel it already reads.
34
52
  *
35
53
  * **The variable is read by `LspLogger`'s constructor**, which is bound on the
@@ -44,6 +62,16 @@ export function parseLogLevelOption(raw: string): LogThreshold {
44
62
  * not go to stdout: that is the JSON-RPC channel, so a log line there would
45
63
  * corrupt the very request this flag was set to diagnose.
46
64
  */
47
- export function logLevelEnv(level: LogThreshold): Record<string, string> {
48
- return { [DEFAULT_LOG_LEVEL_ENV]: level };
65
+ export function logEnv(options: LogOptions): Record<string, string> | undefined {
66
+ const env: Record<string, string> = {};
67
+ if (options.logLevel !== undefined) {
68
+ env[DEFAULT_LOG_LEVEL_ENV] = options.logLevel;
69
+ }
70
+ if (options.logFile !== undefined) {
71
+ env[DEFAULT_LOG_FILE_ENV] = options.logFile;
72
+ }
73
+ if (options.logFileLevel !== undefined) {
74
+ env[DEFAULT_LOG_FILE_LEVEL_ENV] = options.logFileLevel;
75
+ }
76
+ return Object.keys(env).length > 0 ? env : undefined;
49
77
  }