feat(backend): configurable log levels for troubleshooting

This commit is contained in:
laozhoubuluo 2024-03-01 00:50:53 +00:00 committed by naskya
parent 97a871f1a6
commit e7689fb302
3 changed files with 17 additions and 2 deletions

View file

@ -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

View file

@ -89,6 +89,8 @@ export type Source = {
deliverJobMaxAttempts?: number;
inboxJobMaxAttempts?: number;
logLevel?: string[];
syslog: {
host: string;
port: number;

View file

@ -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);
}
}