mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-06-10 15:13:32 -07:00
Fix Windows mpv logging and add log export (#88)
This commit is contained in:
+22
-2
@@ -1,5 +1,11 @@
|
||||
import {
|
||||
appendLogLine,
|
||||
applyLogFileTogglesToEnv,
|
||||
DEFAULT_LOG_ROTATION,
|
||||
isLogFileEnabled,
|
||||
normalizeLogRotation,
|
||||
type LogFileToggles,
|
||||
type LogRotation,
|
||||
resolveDefaultLogFilePath as resolveSharedDefaultLogFilePath,
|
||||
} from './shared/log-files';
|
||||
|
||||
@@ -24,10 +30,11 @@ const LEVEL_PRIORITY: Record<LogLevel, number> = {
|
||||
error: 40,
|
||||
};
|
||||
|
||||
const DEFAULT_LOG_LEVEL: LogLevel = 'info';
|
||||
const DEFAULT_LOG_LEVEL: LogLevel = 'warn';
|
||||
|
||||
let cliLogLevel: LogLevel | undefined;
|
||||
let configLogLevel: LogLevel | undefined;
|
||||
let configLogRotation: LogRotation = DEFAULT_LOG_ROTATION;
|
||||
|
||||
function pad(value: number): string {
|
||||
return String(value).padStart(2, '0');
|
||||
@@ -76,6 +83,15 @@ export function setLogLevel(level: string | undefined, source: LogLevelSource =
|
||||
}
|
||||
}
|
||||
|
||||
export function setLogRotation(rotation: unknown): void {
|
||||
configLogRotation = normalizeLogRotation(rotation) ?? DEFAULT_LOG_ROTATION;
|
||||
process.env.SUBMINER_LOG_ROTATION = String(configLogRotation);
|
||||
}
|
||||
|
||||
export function setLogFileToggles(files: Partial<LogFileToggles> | undefined): void {
|
||||
applyLogFileTogglesToEnv(files);
|
||||
}
|
||||
|
||||
function normalizeError(error: Error): { message: string; stack?: string } {
|
||||
return {
|
||||
message: error.message,
|
||||
@@ -124,12 +140,16 @@ export function resolveDefaultLogFilePath(options?: {
|
||||
platform?: NodeJS.Platform;
|
||||
homeDir?: string;
|
||||
appDataDir?: string;
|
||||
rotation?: unknown;
|
||||
}): string {
|
||||
return resolveSharedDefaultLogFilePath('app', options);
|
||||
}
|
||||
|
||||
function appendToLogFile(line: string): void {
|
||||
appendLogLine(resolveLogFilePath(), line);
|
||||
if (!isLogFileEnabled('app')) {
|
||||
return;
|
||||
}
|
||||
appendLogLine(resolveLogFilePath(), line, { rotation: configLogRotation });
|
||||
}
|
||||
|
||||
function emit(level: LogLevel, scope: string, message: string, meta: unknown[]): void {
|
||||
|
||||
Reference in New Issue
Block a user