Add test module

This commit is contained in:
2021-11-28 15:03:37 +08:00
parent 84b927a71b
commit 18b167266d
7 changed files with 254 additions and 25 deletions
+4 -4
View File
@@ -11,7 +11,7 @@ class InternalLogLabel {
* 堆栈路径样式
*/
public static readonly normalStyle:LogStyle = new LogStyle()
.setColor("#CCCCCC").setBorder("4px", "1px solid #979797").setBlank("0 5px");
.setColor("#979797").setBorder("4px", "1px solid #979797").setBlank("0 5px");
/**
* 一个回车
@@ -27,7 +27,7 @@ class InternalLogLabel {
// 获得调用堆栈
let stack = StackInfo.getFirstStack();
return new LogLabel(stack?.fileName ?? "Unknown file name",
return new LogLabel(stack?.calcFileName() ?? "Unknown file name",
InternalLogLabel.normalStyle, false, true, true);
}
@@ -39,7 +39,7 @@ class InternalLogLabel {
// 获得调用堆栈
let stack = StackInfo.getFirstStack();
return new LogLabel(stack?.url ?? "Unknown url",
return new LogLabel(stack?.calcPathName() ?? "Unknown url",
InternalLogLabel.normalStyle, false, true, true);
}
@@ -51,7 +51,7 @@ class InternalLogLabel {
// 获得调用堆栈
let stack = StackInfo.getFirstStack();
return new LogLabel(stack?.url ?? "Unknown url",
return new LogLabel(stack?.calcPathName() ?? "Unknown url",
InternalLogLabel.normalStyle, true, false, true);
}
+4 -4
View File
@@ -1,4 +1,4 @@
import {LOGGER_CONSOLE, LOGGER_FILTER} from "../Config";
import { LOGGER_FILTER, LOGGER_CONSOLE } from "../utils/Config";
import { InternalLogLabel } from "./InternalLogLabel";
import { LogLabel } from "./LogLabel";
import { MultipleLogContent } from "./MultipleLogContent";
@@ -147,12 +147,12 @@ class Logger {
public static logLine<T>(content:T, ...labels:LogLabel[]):T {
return Logger.logBase<Array<T>>(
new MultipleLogContent<Array<T>>(content), labels,
[InternalLogLabel.urlLabel, InternalLogLabel.blankLabel]
[InternalLogLabel.fileNameLabel, InternalLogLabel.blankLabel]
)[0];
}
/**
* 函数 Logger.logMultiple 的别名
* 函数 Logger.logLine 的别名
*/
public static ll:typeof Logger.logLine = Logger.logLine;
@@ -164,7 +164,7 @@ class Logger {
public static logLineMultiple<T extends Array<any>>(labels:LogLabel[], ...content:T):T {
return Logger.logBase<T>(
new MultipleLogContent<T>(...content), labels,
[InternalLogLabel.urlLabel, InternalLogLabel.blankLabel]
[InternalLogLabel.fileNameLabel, InternalLogLabel.blankLabel]
);
}
+38 -5
View File
@@ -19,13 +19,46 @@ class StackInfo {
*/
public url:string | undefined;
public setInfo(functionName:string, fileName:string, url:string):StackInfo {
/**
* 文件名和行号
*/
public fileNameLine: string | undefined;
/**
* 设置信息
* @param functionName 函数名
* @param fileName 文件名
* @param url 文件路径
*/
public setInfo(functionName:string, fileNameLine:string, url:string):StackInfo {
this.functionName = functionName;
this.fileName = fileName;
this.fileNameLine = fileNameLine;
this.url = url;
return this;
}
/**
* 计算文件名
*/
public calcFileName():string | undefined {
let replaceToTs = this.fileNameLine?.replace(".js", ".ts");
let matched = replaceToTs?.match(/^(.+\.(js|ts)):\d+:\d+$/);
return matched ? matched[1] : undefined;
}
/**
* 计算路径名
*/
public calcPathName():string | undefined {
let replaceToTs = this.url?.replace(".js", ".ts");
let matched = replaceToTs?.match(/^https?:\/\/(\d+\.){3}\d+:\d+\/(.+):\d+:\d+$/);
return matched ? matched[2] : undefined;
}
/**
* 获取函数调用栈列表
*/
@@ -65,7 +98,7 @@ class StackInfo {
/**
* 排除的
*/
public static readonly excludeFile:RegExp = /^Logger\.js:\d+:\d+/;
public static readonly excludeFile:RegExp = /^.*(\\|\/)logger(\\|\/).+\.js:\d+:\d+/;
/**
* 获取第一个调用栈
@@ -76,9 +109,9 @@ class StackInfo {
for(let i = 0; i < callStack.length; i++) {
if(!callStack[i].fileName) continue;
if(!callStack[i].url) continue;
if(!StackInfo.excludeFile.test(callStack[i].fileName ?? "")) {
if(!StackInfo.excludeFile.test(callStack[i].url ?? "")) {
return callStack[i];
}
}
-11
View File
@@ -1,11 +0,0 @@
import Logger from "./Logger";
export default Logger;
export { Logger };
export { InternalLogLabel } from "./InternalLogLabel";
export { MultipleLogContent } from "./MultipleLogContent";
export { LevelLogLabel } from "./LevelLogLabel";
export { LogLabel } from "./LogLabel";
export { LogStyle } from "./LogStyle";
export { StackInfo } from "./StackInfo";