zoukankan      html  css  js  c++  java
  • js日志组件封装

    js日志组件~~

    1
    function Logger(level) { 2 if (!(this instanceof Logger)) { 3 return new Logger(); 4 } 5 var ERROR = 1; 6 var INFO = 2; 7 var DEBUG = 3; 8 9 var logLevel = null; 10 11 var levels = { 12 "debug": 3, 13 "info": 2, 14 "error": 1, 15 "none": 0, 16 } 17 18 if (level === undefined) { 19 logLevel = ERROR; 20 } else { 21 logLevel = level; 22 } 23 24 this.getLevelName = function (level) { 25 26 for (var name in levels) { 27 if (levels[name] == level) { 28 return name; 29 } 30 } 31 } 32 33 this.setLevel = function (newLevel) { 34 35 logLevel = newLevel; 36 console.log("setting log level to: " + this.getLevelName(newLevel)); 37 } 38 39 var processMessage = function (msg, level) { 40 if (level <= logLevel) { 41 console.log(msg); 42 } 43 } 44 45 this.error = function (msg) { 46 processMessage(msg, ERROR); 47 }; 48 this.info = function (msg) { 49 processMessage(msg, INFO); 50 }; 51 this.debug = function (msg) { 52 processMessage(msg, DEBUG); 53 }; 54 55 var that = this; 56 }
    ----------------------------------------------------------- 58 var logger = Logger(); 59 logger.error("haha");
  • 相关阅读:
    FastAPI(5)- 查询参数 Query Parameters
    FastAPI(4)- 路径参数 Path Parameters
    FastAPI(3)- uvicorn.run()
    Python
    Python
    Python
    Python
    Python
    Python
    Python
  • 原文地址:https://www.cnblogs.com/fanfan-90/p/11921816.html
Copyright © 2011-2022 走看看