| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- import { Utils } from "./Utils";
- /**
- * 日志的时间显示设置
- */
- export enum TimeType {
- /**
- * 全部显示
- */
- FULL,
- /**
- * 不显示时间
- */
- NoTime,
- /**
- * 不显示毫秒
- */
- NoMilliseconds,
- /**
- * 不显示日期
- */
- NODate
- }
- /**
- * 日志工具
- * @author 袁浩
- */
- export class Log {
- public static greytring = '\x1B[90m' + '%s' + '\x1B[39m';
- public static black = '\x1B[30m' + '%s' + '\x1B[39m';
- public static blue = '\x1B[34m' + '%s' + '\x1B[39m';
- public static cyan = '\x1B[36m' + '%s' + '\x1B[39m';
- public static green = '\x1B[32m' + '%s' + '\x1B[39m';
- public static magenta = '\x1B[35m' + '%s' + '\x1B[39m';
- public static red = '\x1B[31m' + '%s' + '\x1B[39m';
- public static yellow = '\x1B[33m' + '%s' + '\x1B[39m';
- /**
- * 打印日志,控制台颜色是紫色
- * @param message 信息
- */
- public static info(message: string): void {
- console.log(this.blue + this.magenta, this.now, " " + message);
- }
- /**
- * 打印错误,控制台颜色是红色
- * @param message
- */
- public static error(message: string, stack: string = null): void {
- console.error(this.blue + this.red, this.now, " " + message + (stack ? "\n" + stack : ""));
- }
- /**
- * 警告,控制台颜色是橙色
- * @param message
- */
- public static warn(message: string): void {
- console.warn(this.now + " " + message);
- }
- public static trace(message: string): void {
- console.log(this.blue + this.yellow, this.now, " " + message);
- }
- public static log(message: string): void {
- console.log(this.blue + this.green, this.now, " " + message);
- }
- public static timeType = TimeType.NoMilliseconds;
- public static get now(): string {
- switch (this.timeType) {
- case TimeType.NODate:
- return "<" + Utils.formatDate(new Date(), "hh:mm:ss S") + ">";
- case TimeType.NoMilliseconds:
- return "<" + Utils.formatDate(new Date(), "yyyy-MM-dd hh:mm:ss") + ">";
- case TimeType.NoTime:
- return "";
- default:
- return "<" + Utils.formatDate(new Date(), "yyyy-MM-dd hh:mm:ss S") + ">";
- }
- }
- }
|