1 Star 0 Fork 79

明天会更好/log.js

forked from Clark/log.js 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
index.js 2.33 KB
一键复制 编辑 原始数据 按行查看 历史
fanliang 提交于 2022-11-08 15:52 . fix: new code
import {version} from './package.json';
import capture from "./lib/capture";
import storage from './lib/storage';
import request from "./lib/request";
import queue from "./lib/queue";
import {defaultInfo} from './config/index';
import {deepCopy} from "./utils";
window.log = (function () {
//初始化
function log_init(params) {
if (JSON.stringify(storage.config_info) !== "{}") {
return console.error("【log.js】log has been initialized and cannot be reconfigured.");
}
let tempParams = parameter_correction(params);
storage.save("config_info", tempParams);
capture.start_all();
request.init_all();
queue.loop();
}
//配置项校正
function parameter_correction(params){
if(!params) return defaultInfo;
let tempObj = deepCopy(defaultInfo);
Object.assign(tempObj, storage.config_info);
Object.assign(tempObj, params);
//校正采集度
if(tempObj && typeof tempObj.degree === 'number'){
if(tempObj.degree > 1){
tempObj.degree = 1;
}
if(tempObj.degree < 0){
tempObj.degree = 0;
}
}
//校正进入类型
if(tempObj && tempObj.pattern){
tempObj.pattern = 'config';
}
return tempObj;
}
//重新调整初始化参数
function log_setOptions(params) {
if (!params) {
return console.error("【log.js】Please set options.");
}
if (JSON.stringify(storage.config_info) === "{}") {
return console.error("【log.js】Please use first log.init()");
}
let finalParams = parameter_correction(params);
storage.save("config_info", finalParams);
queue.shutdown();
capture.start_all();
request.init_all();
queue.loop();
}
//获取终端信息
function get_terminal_info() {
return deepCopy(storage.terminal_info);
}
//获取性能信息
function get_performance_info() {
return deepCopy(storage.performance_info);
}
return {
init: log_init,
setOptions: log_setOptions,
getTerminalInfo: get_terminal_info,
getPerformanceInfo: get_performance_info,
log: capture.diy_log,
version: version
};
})();
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/mahaijun/log.js.git
[email protected]:mahaijun/log.js.git
mahaijun
log.js
log.js
master

搜索帮助