Customized logger in javascript
IPFS
最近剛好工作上有需要,所以就來寫一個。
原本預設 javascript 有 console.log() 可以用,但是如果要將 log 資料分等級的話就得自己處理。
var LogLevel = { Debug: { value: 1, name: "Debug", code: "debug" }, Info: { value: 2, name: "Info", code: "info" }, Warning: { value: 3, name: "Warn", code: "warn"}, Error: { value: 4, name: "Err", code: "error"}, None: { value:99, name: "None", code: "none"} }; var logger = function() { var pub = {}; var _currentLogLevel = LogLevel.Info; pub.LogLevel = _currentLogLevel; pub.info = function(msg){ if (_currentLogLevel.value
Original link: Phanix's Blog
喜欢我的作品吗?别忘了给予支持与赞赏,让我知道在创作的路上有你陪伴,一起延续这份热忱!