0f6297e25ea714f1f3c9798923adafdcf2cb43c0.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. System.register(["cc"], function (_export, _context) {
  2. "use strict";
  3. var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, log, Logger, _crd, LogType, names;
  4. _export("Logger", void 0);
  5. return {
  6. setters: [function (_cc) {
  7. _cclegacy = _cc.cclegacy;
  8. __checkObsolete__ = _cc.__checkObsolete__;
  9. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  10. log = _cc.log;
  11. }],
  12. execute: function () {
  13. _crd = true;
  14. _cclegacy._RF.push({}, "479cdJANP5KaJgU+8z0DdSE", "Logger", undefined);
  15. /** 日志类型 */
  16. __checkObsolete__(['log']);
  17. _export("LogType", LogType = /*#__PURE__*/function (LogType) {
  18. LogType[LogType["Net"] = 1] = "Net";
  19. LogType[LogType["Model"] = 2] = "Model";
  20. LogType[LogType["Business"] = 4] = "Business";
  21. LogType[LogType["View"] = 8] = "View";
  22. LogType[LogType["Config"] = 16] = "Config";
  23. LogType[LogType["Trace"] = 32] = "Trace";
  24. return LogType;
  25. }({}));
  26. names = {
  27. "1": "网络日志",
  28. "2": "数据日志",
  29. "4": "业务日志",
  30. "8": "视图日志",
  31. "16": "配置日志",
  32. "32": "标准日志"
  33. };
  34. /**
  35. * 日志管理
  36. * @help https://gitee.com/dgflash/oops-framework/wikis/pages?sort_id=12037904&doc_id=2873565
  37. * @example
  38. oops.log.trace("默认标准日志");
  39. oops.log.logConfig("灰色配置日志");
  40. oops.log.logNet("橙色网络日志");
  41. oops.log.logModel("紫色数据日志");
  42. oops.log.logBusiness("蓝色业务日志");
  43. oops.log.logView("绿色视图日志");
  44. */
  45. _export("Logger", Logger = class Logger {
  46. constructor() {
  47. this.tags = 0;
  48. this.lc = null;
  49. }
  50. static get instance() {
  51. if (this._instance == null) {
  52. this._instance = new Logger();
  53. this._instance.init();
  54. }
  55. return this._instance;
  56. }
  57. /** 设置界面日志控制台 */
  58. setLoggerConsole(lc) {
  59. this.lc = lc;
  60. }
  61. init() {
  62. this.tags = LogType.Net | LogType.Model | LogType.Business | LogType.View | LogType.Config | LogType.Trace;
  63. }
  64. /**
  65. * 设置显示的日志类型,默认值为不显示任何类型日志
  66. * @example
  67. oops.log.setTags(LogType.View|LogType.Business)
  68. */
  69. setTags(tag) {
  70. if (tag === void 0) {
  71. tag = null;
  72. }
  73. if (tag) {
  74. this.tags = tag;
  75. }
  76. }
  77. /**
  78. * 记录开始计时
  79. * @param describe 标题描述
  80. * @example
  81. oops.log.start();
  82. ...
  83. 省略N行代码
  84. ...
  85. oops.log.end();
  86. */
  87. start(describe) {
  88. if (describe === void 0) {
  89. describe = "Time";
  90. }
  91. console.time(describe);
  92. }
  93. /**
  94. * 打印范围内时间消耗
  95. * @param describe 标题描述
  96. * @example
  97. oops.log.start();
  98. ...
  99. 省略N行代码
  100. ...
  101. oops.log.end();
  102. */
  103. end(describe) {
  104. if (describe === void 0) {
  105. describe = "Time";
  106. }
  107. console.timeEnd(describe);
  108. }
  109. /**
  110. * 打印表格
  111. * @param msg 日志消息
  112. * @param describe 标题描述
  113. * @example
  114. var object:any = {uid:1000, name:"oops"};
  115. oops.log.table(object);
  116. */
  117. table(msg, describe) {
  118. if (!this.isOpen(LogType.Trace)) {
  119. return;
  120. }
  121. console.table(msg);
  122. }
  123. /**
  124. * 打印标准日志
  125. * @param msg 日志消息
  126. */
  127. trace(msg, color) {
  128. if (color === void 0) {
  129. color = "#000000";
  130. }
  131. this.print(LogType.Trace, msg, color);
  132. }
  133. /**
  134. * 打印网络层日志
  135. * @param msg 日志消息
  136. * @param describe 标题描述
  137. */
  138. logNet(msg, describe) {
  139. this.orange(LogType.Net, msg, describe);
  140. }
  141. /**
  142. * 打印数据层日志
  143. * @param msg 日志消息
  144. * @param describe 标题描述
  145. */
  146. logModel(msg, describe) {
  147. this.violet(LogType.Model, msg, describe);
  148. }
  149. /**
  150. * 打印业务层日志
  151. * @param msg 日志消息
  152. * @param describe 标题描述
  153. */
  154. logBusiness(msg, describe) {
  155. this.blue(LogType.Business, msg, describe);
  156. }
  157. /**
  158. * 打印视图日志
  159. * @param msg 日志消息
  160. * @param describe 标题描述
  161. */
  162. logView(msg, describe) {
  163. this.green(LogType.View, msg, describe);
  164. }
  165. /** 打印配置日志 */
  166. logConfig(msg, describe) {
  167. this.gray(LogType.Config, msg, describe);
  168. } // 橙色
  169. orange(tag, msg, describe) {
  170. this.print(tag, msg, "#ee7700", describe);
  171. } // 紫色
  172. violet(tag, msg, describe) {
  173. this.print(tag, msg, "#800080", describe);
  174. } // 蓝色
  175. blue(tag, msg, describe) {
  176. this.print(tag, msg, "#3a5fcd", describe);
  177. } // 绿色
  178. green(tag, msg, describe) {
  179. this.print(tag, msg, "#008000", describe);
  180. } // 灰色
  181. gray(tag, msg, describe) {
  182. this.print(tag, msg, "#808080", describe);
  183. }
  184. isOpen(tag) {
  185. return (this.tags & tag) != 0;
  186. }
  187. /**
  188. * 输出日志
  189. * @param tag 日志类型
  190. * @param msg 日志内容
  191. * @param color 日志文本颜色
  192. * @param describe 日志标题描述
  193. */
  194. print(tag, msg, color, describe) {
  195. // 标记没有打开,不打印该日志
  196. if (!this.isOpen(tag)) {
  197. return;
  198. }
  199. var type = names[tag];
  200. if (this.lc == null) {
  201. var backLog = console.log || log;
  202. color = "color:" + color + ";";
  203. if (describe) {
  204. backLog.call(null, "%c%s%s%s:%s%o", color, this.getDateString(), '[' + type + ']', this.stack(5), describe, msg);
  205. } else {
  206. backLog.call(null, "%c%s%s%s:%o", color, this.getDateString(), '[' + type + ']', this.stack(5), msg);
  207. }
  208. } else {
  209. this.lc.trace(this.getDateString() + "[" + type + "]" + msg, color);
  210. }
  211. }
  212. stack(index) {
  213. var e = new Error();
  214. var lines = e.stack.split("\n");
  215. var result = [];
  216. lines.forEach(line => {
  217. line = line.substring(7);
  218. var lineBreak = line.split(" ");
  219. if (lineBreak.length < 2) {
  220. result.push(lineBreak[0]);
  221. } else {
  222. result.push({
  223. [lineBreak[0]]: lineBreak[1]
  224. });
  225. }
  226. });
  227. var list = [];
  228. var splitList = [];
  229. if (index < result.length - 1) {
  230. var value;
  231. for (var a in result[index]) {
  232. splitList = a.split(".");
  233. if (splitList.length == 2) {
  234. list = splitList.concat();
  235. } else {
  236. value = result[index][a];
  237. var start = value.lastIndexOf("/");
  238. var end = value.lastIndexOf(".");
  239. if (start > -1 && end > -1) {
  240. var r = value.substring(start + 1, end);
  241. list.push(r);
  242. } else {
  243. list.push(value);
  244. }
  245. }
  246. }
  247. }
  248. if (list.length == 1) {
  249. return "[" + list[0] + ".ts]";
  250. } else if (list.length == 2) {
  251. return "[" + list[0] + ".ts->" + list[1] + "]";
  252. }
  253. return "";
  254. }
  255. getDateString() {
  256. var d = new Date();
  257. var str = d.getHours().toString();
  258. var timeStr = "";
  259. timeStr += (str.length == 1 ? "0" + str : str) + ":";
  260. str = d.getMinutes().toString();
  261. timeStr += (str.length == 1 ? "0" + str : str) + ":";
  262. str = d.getSeconds().toString();
  263. timeStr += (str.length == 1 ? "0" + str : str) + ":";
  264. str = d.getMilliseconds().toString();
  265. if (str.length == 1) str = "00" + str;
  266. if (str.length == 2) str = "0" + str;
  267. timeStr += str;
  268. timeStr = "[" + timeStr + "]";
  269. return timeStr;
  270. }
  271. });
  272. Logger._instance = void 0;
  273. _cclegacy._RF.pop();
  274. _crd = false;
  275. }
  276. };
  277. });
  278. //# sourceMappingURL=0f6297e25ea714f1f3c9798923adafdcf2cb43c0.js.map