UNPKG

@lark-project/cli

Version:

飞书项目插件开发工具

73 lines (72 loc) 2.34 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.logger = exports.LogTrack = void 0; const log4js_1 = __importDefault(require("log4js")); const env_1 = require("./env"); const loggerConfig = { appenders: { console: { type: 'console', layout: { type: 'pattern', // [20:17:56][INFO][59596] custom message , 终端里带上颜色 [% %] pattern: '%[[%d{hh:mm:ss}][%p][%z] %m%]', }, }, file: { type: 'dateFile', layout: { type: 'pattern', // [11:39:34][SUCCESS][23998] custom message pattern: '[%d{hh:mm:ss}][%p][%z] %n%m', }, filename: './.log/lpm.log', pattern: 'yyyy-MM-dd', numBackups: 1, alwaysIncludePattern: true, keepFileExt: true, }, }, categories: { default: { appenders: ['console', 'file'], level: env_1.env.debug ? 'TRACE' : 'INFO', }, }, levels: { // 自定义日志级别 success,优先级:trace < debug < info < success < warn < error < fatal success: { value: log4js_1.default.levels.getLevel('info').level + 100, colour: 'green', }, }, }; class LogTrack { constructor() { this.shutdown = cb => { this.log4js.shutdown(cb); }; this.debug = (message, ...args) => { this.logger.debug(message, ...args); }; this.info = (message, ...args) => { this.logger.info(message, ...args); }; this.success = (message, ...args) => { this.logger.log('success', message, ...args); }; this.warn = (message, ...args) => { this.logger.warn(message, ...args); }; this.error = (message, ...args) => { this.logger.error(message, ...args); }; this.log4js = log4js_1.default.configure(loggerConfig); this.logger = this.log4js.getLogger('LPM'); } } exports.LogTrack = LogTrack; exports.logger = new LogTrack();