UNPKG

kdesign-ui

Version:

kd is from company of klx, it provide quickly genarator company inner business front structure

53 lines (51 loc) 1.51 kB
import log4js from 'log4js' import chalk from 'chalk' class Log { public name: Error | string = new Error('abstrct attribute') public type: Error | string = new Error('abstrct attribute') public level: Error | string = new Error('abstrct attribute') public silent: boolean = false public regist () { log4js.configure({ appenders: { [this.name as string]: { type: this.type as string, filename: `${this.name as string}.log` } }, categories: { default: { appenders: [this.name as string], level: this.level as string } } }) } public get logger () { if (this._logger) return this._logger return (this._logger = log4js.getLogger()) } private _logger: any public info (msg: string) { this.logger.info(msg) if (this.silent) return console.info(msg) } public error (msg: string) { this.logger.error(msg) if (this.silent) return console.error(chalk.red(msg)) } public warn (msg: string) { this.logger.warn(msg) if (this.silent) return console.warn(chalk.yellow(msg)) } public debug (msg: string) { this.logger.debug(msg) if (this.silent) return console.debug(msg) } public trace (msg: string) { this.logger.trace(msg) if (this.silent) return console.trace(msg) } } export class InterfaceLog extends Log { public name: string = 'interface' constructor(public type: string = 'file', public level: string = 'error', public silent: boolean = false) { super() this.regist() } }