Add StatusBar Modular Fix some BUG Add LoggerText feature

This commit is contained in:
2021-12-01 21:13:15 +08:00
parent df10c22a8d
commit af2d88f651
10 changed files with 159 additions and 112 deletions
+7
View File
@@ -10,6 +10,13 @@
*/
export const LOGGER_CONSOLE:boolean = true;
/**
* 是否在控制台输出时启用标签样式
* 如果在手机上调试可以关闭此选项
* 因为手机上的控制台无法正确显示样式
*/
export const LOGGER_STYLE:boolean = true;
/**
* 调试过滤器
* 按照 LogLabel 进行过滤
+44 -14
View File
@@ -1,4 +1,4 @@
import { LOGGER_FILTER, LOGGER_CONSOLE } from "./Config";
import { LOGGER_FILTER, LOGGER_CONSOLE, LOGGER_STYLE } from "./Config";
import { StackLogLabel } from "./PresetLogLabel";
import { LogLabel } from "./LogLabel";
@@ -82,30 +82,41 @@ class Logger {
*/
public static calcStyle(...labels:LogLabel[]):[string[], string[]] {
// 过滤出需要显示的 Labels
let labelsNeedRender:LogLabel[] = labels.filter((label:LogLabel)=>{
return label.display
});
let consoleLabels:string[] = [];
let consoleStyles:string[] = [];
// 放置标签
for(let i = 0; i < labelsNeedRender.length; i++) {
for(let i = 0; i < labels.length; i++) {
consoleLabels.push(labels[i].getLoggerOutput());
if (i !== ( labelsNeedRender.length - 1))
if (i !== ( labels.length - 1))
consoleLabels.push("%c ");
consoleStyles.push(labelsNeedRender[i].getStyleOutput());
consoleStyles.push(labels[i].getStyleOutput());
if (i !== ( labelsNeedRender.length - 1))
if (i !== ( labels.length - 1))
consoleStyles.push("");
}
return [consoleLabels, consoleStyles];
}
/**
* 收集计算标签没有样式
* @param labels 标签
*/
public static calcLabel(...labels:LogLabel[]):string[] {
let consoleLabels:string[] = [];
// 放置标签
for(let i = 0; i < labels.length; i++) {
consoleLabels.push(labels[i].getTextOutput());
}
return consoleLabels
}
/**
* 基础调试输出
* 其他的 Log 函数都是基于此封装
@@ -122,11 +133,30 @@ class Logger {
if(!Logger.testLog(...labels, ...attachLabel, StackLogLabel.filterUrlLabel))
return content.getContent();
// 计算收集样式
let [consoleLabels, consoleStyles]= Logger.calcStyle(...labels, ...attachLabel);
// 过滤出需要渲染的 Labels
let labelsNeedRender:LogLabel[] = [...labels, ...attachLabel].filter((label:LogLabel)=>{
return true
});
// 调试输出
console.log(consoleLabels.join(""), ...consoleStyles, ...content.getContent());
// 使用样式输出
if(LOGGER_STYLE) {
// 计算收集样式
let [consoleLabels, consoleStyles]= Logger.calcStyle(...labelsNeedRender);
// 调试输出
console.log(consoleLabels.join(""), ...consoleStyles, ...content.getContent());
} else {
// 计算收集标签
let consoleLabels= Logger.calcLabel(...labelsNeedRender);
// 输出
console.log(consoleLabels.join(" "), ...content.getContent());
}
return content.getContent();
}
+2 -2
View File
@@ -400,7 +400,7 @@ class Manager<WXC extends AnyWXContext = AnyWXContext> {
if(this.modules[i].data !== void 0) {
this.context.data[`${ this.modules[i].nameSpace }$${ key }`] =
( this.modules[i].data as IAnyTypeObject )[key];
// this.modules[i]
this.modules[i].paramList.add(key);
}
}
}
@@ -425,7 +425,7 @@ class Manager<WXC extends AnyWXContext = AnyWXContext> {
func.push(`[${ key }]`);
}
let log:string = `模块 [${ this.modules[i].nameSpace }] 加载完成...\n`;
let log:string = `模块 [${ this.modules[i].nameSpace }] 完成绑定...\n`;
if(data.length > 0) log += `Using Props: ${ data.join(", ") }\n`;
if(func.length > 0) log += `Using Function: ${ func.join(", ") }\n`;
+4 -4
View File
@@ -99,7 +99,7 @@ class StackInfo {
/**
* 排除的
*/
public static readonly excludeFile:RegExp = /^.*(\\|\/)logger(\\|\/).+\.js:\d+:\d+/;
public static readonly excludeFile:RegExp = /^.*(\\|\/)core(\\|\/)(.*Log.*).js:\d+:\d+/;
/**
* 获取第一个调用栈
@@ -179,7 +179,7 @@ class StackLogLabel {
/**
* 生成圆角颜色标签样式
*/
const normalLevelStyleGen = (color:string):LogStyle => {
const normalLevelStyleGen = (color:string):LogStyle => {
return new LogStyle().setBorder("4px", `1px solid ${color}`)
.setColor(color).setBlank("0 5px");
}
@@ -235,7 +235,7 @@ class LevelLogLabel {
/**
* 生成圆角颜色标签样式
*/
const normalLifeStyleGen = (r:number, g:number, b:number):LogStyle => {
const normalLifeStyleGen = (r:number, g:number, b:number):LogStyle => {
return new LogStyle().setBorder("4px", `1px solid rgb(${ r }, ${ g }, ${ b })`)
.setColor(`rgb(${ r }, ${ g }, ${ b })`, `rgba(${ r }, ${ g }, ${ b }, .1)`)
.setBlank("0 5px");
@@ -310,4 +310,4 @@ class LifeCycleLogLabel {
);
}
export { StackInfo, StackLogLabel, LevelLogLabel, LifeCycleLogLabel };
export { StackInfo, StackLogLabel, LevelLogLabel, LifeCycleLogLabel, normalLifeStyleGen as colorRadio };