feat(backend): configurable log levels for troubleshooting
This commit is contained in:
parent
97a871f1a6
commit
e7689fb302
3 changed files with 17 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -89,6 +89,8 @@ export type Source = {
|
|||
deliverJobMaxAttempts?: number;
|
||||
inboxJobMaxAttempts?: number;
|
||||
|
||||
logLevel?: string[];
|
||||
|
||||
syslog: {
|
||||
host: string;
|
||||
port: number;
|
||||
|
|
|
@ -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<string, any> | 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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue