-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathlog-config-defaults.ts
More file actions
36 lines (31 loc) · 1.08 KB
/
log-config-defaults.ts
File metadata and controls
36 lines (31 loc) · 1.08 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
import * as path from 'path';
import * as os from 'os';
export const LOG_CONFIG_DEFAULTS = {
LEVEL: 'info',
PATH: path.join(os.homedir(), '.contentstack', 'logs'),
SHOW_CONSOLE_LOGS: false,
} as const;
/**
* Resolves a log path to an absolute path
* @param logPath - The path to resolve
* @returns Absolute path
*/
export function resolveLogPath(logPath: string): string {
if (!logPath) return LOG_CONFIG_DEFAULTS.PATH;
return path.isAbsolute(logPath) ? logPath : path.resolve(process.cwd(), logPath);
}
/**
* Gets the effective log configuration with defaults applied
* @param currentConfig - Current configuration from config handler
* @returns Configuration with defaults applied
*/
export function getEffectiveLogConfig(currentConfig: any = {}) {
const logLevel = currentConfig?.level || LOG_CONFIG_DEFAULTS.LEVEL;
const logPath = resolveLogPath(currentConfig?.path || LOG_CONFIG_DEFAULTS.PATH);
const showConsoleLogs = currentConfig?.['showConsoleLogs'] ?? LOG_CONFIG_DEFAULTS.SHOW_CONSOLE_LOGS;
return {
level: logLevel,
path: logPath,
showConsoleLogs,
};
}