Created
March 20, 2025 02:16
-
-
Save yunfan/3d4c5f128475a6dc411f8bf92594777d to your computer and use it in GitHub Desktop.
my logger for tsrpc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as winston from 'winston'; | |
import DailyRotateFile from 'winston-daily-rotate-file'; | |
import { Config } from '../config'; | |
class MyLogger { | |
logger: winston.Logger; | |
defaultLogLevel: string; | |
constructor(logger: winston.Logger, defaultLogLevel: string) { | |
this.logger = logger; | |
this.defaultLogLevel = defaultLogLevel; | |
} | |
log(msg: string, ...meta: any[]) { | |
this.logger.log(this.defaultLogLevel, msg, ...meta); | |
} | |
debug(msg: string, ...meta: any[]) { | |
this.logger.debug(msg, ...meta); | |
} | |
warn(msg: string, ...meta: any[]) { | |
this.logger.warn(msg, ...meta); | |
} | |
info(msg: string, ...meta: any[]) { | |
this.logger.info(msg, ...meta); | |
} | |
error(msg: string, ...meta: any[]) { | |
this.logger.error(msg, ...meta); | |
} | |
} | |
export function initLogger(logLevel: string = 'debug') { | |
const mine = winston.createLogger({ | |
transports: [new DailyRotateFile(Config.rotatedLogOptions), new winston.transports.Console()], | |
}); | |
return new MyLogger(mine, logLevel); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment