diff --git a/packages/backend/src/boot/master.ts b/packages/backend/src/boot/master.ts index 623cc964a..5ea54a1bd 100644 --- a/packages/backend/src/boot/master.ts +++ b/packages/backend/src/boot/master.ts @@ -28,7 +28,7 @@ const bootLogger = logger.createSubLogger('boot', 'magenta', false); const themeColor = chalk.hex('#86b300'); function greet() { - if (!envOption.quiet) { + if (!envOption.quiet && !envOption.logJson) { //#region Misskey logo const v = `v${meta.version}`; console.log(themeColor(' _____ _ _ ')); @@ -46,7 +46,7 @@ function greet() { } bootLogger.info('Welcome to Misskey!'); - bootLogger.info(`Misskey v${meta.version}`, null, true); + bootLogger.info(`Misskey v${meta.version}`, { version: meta.version, hostname: os.hostname(), pid: process.pid }, true); } /** diff --git a/packages/backend/src/env.ts b/packages/backend/src/env.ts index af1c3bdd3..e5a88a8f5 100644 --- a/packages/backend/src/env.ts +++ b/packages/backend/src/env.ts @@ -9,6 +9,7 @@ const envOption = { noDaemons: false, disableClustering: false, verbose: false, + logJson: false, withLogTime: false, quiet: false, }; diff --git a/packages/backend/src/logger.ts b/packages/backend/src/logger.ts index 5c10559ec..48d7afa48 100644 --- a/packages/backend/src/logger.ts +++ b/packages/backend/src/logger.ts @@ -41,7 +41,7 @@ export default class Logger { @bindThis private log(level: Level, message: string, data?: Record | null, important = false, subContexts: Context[] = [], store = true): void { - if (envOption.quiet) return; + if (envOption.quiet && !envOption.logJson) return; if (!this.store) store = false; if (level === 'debug') store = false; @@ -50,6 +50,19 @@ export default class Logger { return; } + if (envOption.logJson) { + console.log(JSON.stringify({ + time: new Date().toISOString(), + level: level, + message: message, + data: data, + important: important, + context: [this.context].concat(subContexts).join('.'), + cluster: cluster.isPrimary ? 'primary' : `worker-${cluster.worker!.id}`, + })); + return; + } + const time = dateFormat(new Date(), 'HH:mm:ss'); const worker = cluster.isPrimary ? '*' : cluster.worker!.id; const l =