Skip to content

Commit e7b10e8

Browse files
authored
chore: Clean up path vars (#348)
1 parent 752cb2f commit e7b10e8

3 files changed

Lines changed: 27 additions & 5 deletions

File tree

src/lib/middleware/config.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ export function loadBenchmarkConfig(installDir: string): BenchmarkConfig {
6464
if (process.env.POSTHOG_WIZARD_BENCHMARK_FILE) {
6565
config.output.benchmarkPath = process.env.POSTHOG_WIZARD_BENCHMARK_FILE;
6666
}
67-
if (process.env.POSTHOG_WIZARD_LOG_FILE) {
68-
config.output.logPath = process.env.POSTHOG_WIZARD_LOG_FILE;
67+
if (process.env.POSTHOG_WIZARD_LOG_DIR) {
68+
config.output.logPath = path.join(
69+
process.env.POSTHOG_WIZARD_LOG_DIR,
70+
'posthog-wizard.log',
71+
);
6972
}
7073

7174
// If benchmark output is disabled, disable the jsonWriter plugin
@@ -83,8 +86,11 @@ export function loadBenchmarkConfig(installDir: string): BenchmarkConfig {
8386
if (process.env.POSTHOG_WIZARD_BENCHMARK_FILE) {
8487
config.output.benchmarkPath = process.env.POSTHOG_WIZARD_BENCHMARK_FILE;
8588
}
86-
if (process.env.POSTHOG_WIZARD_LOG_FILE) {
87-
config.output.logPath = process.env.POSTHOG_WIZARD_LOG_FILE;
89+
if (process.env.POSTHOG_WIZARD_LOG_DIR) {
90+
config.output.logPath = path.join(
91+
process.env.POSTHOG_WIZARD_LOG_DIR,
92+
'posthog-wizard.log',
93+
);
8894
}
8995

9096
return config;

src/run.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { FRAMEWORK_REGISTRY } from './lib/registry';
1414
import { analytics } from './utils/analytics';
1515
import { runAgentWizard } from './lib/agent-runner';
1616
import { EventEmitter } from 'events';
17-
import { logToFile } from './utils/debug';
17+
import { logToFile, configureLogFileFromEnvironment } from './utils/debug';
1818
import { wizardAbort } from './utils/wizard-abort';
1919
import { readApiKeyFromEnv } from './utils/env-api-key';
2020

@@ -38,6 +38,9 @@ type Args = {
3838
};
3939

4040
export async function runWizard(argv: Args, session?: WizardSession) {
41+
// Apply log file env overrides for all modes (CI, benchmark, and interactive).
42+
configureLogFileFromEnvironment();
43+
4144
const finalArgs = {
4245
...argv,
4346
...readEnvironment(),

src/utils/debug.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { appendFileSync } from 'fs';
2+
import path from 'path';
23
import { prepareMessage } from './logging';
34
import { getUI } from '../ui';
45

@@ -22,6 +23,18 @@ export function configureLogFile(opts: {
2223
if (opts.enabled !== undefined) logEnabled = opts.enabled;
2324
}
2425

26+
/**
27+
* Configure log path from environment variables.
28+
*
29+
* Uses POSTHOG_WIZARD_LOG_DIR when set, joined with posthog-wizard.log.
30+
*/
31+
export function configureLogFileFromEnvironment(): void {
32+
const envLogDir = process.env.POSTHOG_WIZARD_LOG_DIR;
33+
if (envLogDir) {
34+
configureLogFile({ path: path.join(envLogDir, 'posthog-wizard.log') });
35+
}
36+
}
37+
2538
/**
2639
* Initialize the log file with a run header.
2740
* Call this at the start of each wizard run.

0 commit comments

Comments
 (0)