0.0.5 • Published 2 years ago

@imohuan/log v0.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

日志输出

声明

/** 框架默认配置 */
let defaultOption: LogOption = {
  /** 输出的名称 */
  label: "Name",
  /** 输出数据的前缀 */
  prefix: "$",
  /** 是否加载Console插件 */
  console: true,
  /** 对象最先显示长度, 如果大于该长度会显示[Object Len:{length}] */
  objectLen: 100,
  /** 打印输出格式 */
  format: "{prefix} {date} {label} {level} {msg}",
  /** 日志保存地址 */
  dirname: resolve(process.cwd(), "logs"),
  /** 日期格式化 */
  dateFormat: "YYYY-MM-DD hh:ss:mm"
};

日志函数

以下函数都不会保存日志数据

  • info Info 日志
  • error Error 日志
  • debug Debug 日志
  • warn Warn 日志
  • setOption(option: LogOption) 设置基础配置

日志类

Logger

const logger = new Logger({} as LogOption);
/** 以下函数会存储到本地文件 */
console.log(logger.path());
console.log(logger.info());
console.log(logger.error());
console.log(logger.debug());
console.log(logger.warn());

/** 类的静态方法 不会保存本地日志 */
console.log(Logger.info());
console.log(Logger.error());
console.log(Logger.debug());
console.log(Logger.warn());