diff --git a/.config/example.yml b/.config/example.yml index 46efda9142..02c0296172 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -167,6 +167,17 @@ reservedUsernames: [ # IP address family used for outgoing request (ipv4, ipv6 or dual) #outgoingAddressFamily: ipv4 +# Log Option +# Production env: ['error', 'success', 'warning', 'info'] +# Debug/Test env or Troubleshooting: ['error', 'success', 'warning', 'debug' ,'info'] +# Production env which storage space or IO is tight: ['error', 'warning'] +logLevel: [ + 'error', + 'success', + 'warning', + 'info' +] + # Syslog option #syslog: # host: localhost diff --git a/packages/backend/src/config/types.ts b/packages/backend/src/config/types.ts index 13d87fc19c..0389bf83fb 100644 --- a/packages/backend/src/config/types.ts +++ b/packages/backend/src/config/types.ts @@ -89,6 +89,8 @@ export type Source = { deliverJobMaxAttempts?: number; inboxJobMaxAttempts?: number; + logLevel?: string[]; + syslog: { host: string; port: number; diff --git a/packages/backend/src/services/logger.ts b/packages/backend/src/services/logger.ts index e8b6d915d0..b1f4fe05ed 100644 --- a/packages/backend/src/services/logger.ts +++ b/packages/backend/src/services/logger.ts @@ -57,6 +57,7 @@ export default class Logger { store = true, ): void { if (envOption.quiet) return; + if (!(typeof config.logLevel === "undefined") && !config.logLevel.includes(level)) return; if (!this.store) store = false; if (level === "debug") store = false; @@ -186,8 +187,9 @@ export default class Logger { data?: Record | null, important = false, ): void { - // デバッグ用に使う(開発者に必要だが利用者に不要な情報) - if (process.env.NODE_ENV !== "production" || envOption.verbose) { + // Used for debugging (information necessary for developers but unnecessary for users) + // Fixed if statement is ignored when logLevel includes debug + if (config.logLevel?.includes("debug") || process.env.NODE_ENV !== "production" || envOption.verbose) { this.log("debug", message, data, important); } }