@liquicode/lib-logger
Advanced tools
Comparing version 0.1.4 to 0.2.0
@@ -1,1 +0,1 @@ | ||
!function(e,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define([],o):"object"==typeof exports?exports.lib_logger=o():e.lib_logger=o()}("undefined"!=typeof self?self:this,(function(){return function(e){var o={};function t(n){if(o[n])return o[n].exports;var r=o[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,t),r.l=!0,r.exports}return t.m=e,t.c=o,t.d=function(e,o,n){t.o(e,o)||Object.defineProperty(e,o,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,o){if(1&o&&(e=t(e)),8&o)return e;if(4&o&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&o&&"string"!=typeof e)for(var r in e)t.d(n,r,function(o){return e[o]}.bind(null,r));return n},t.n=function(e){var o=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(o,"a",o),o},t.o=function(e,o){return Object.prototype.hasOwnProperty.call(e,o)},t.p="",t(t.s=2)}([function(e,o){e.exports=require("path")},function(e,o){e.exports=require("fs")},function(e,o,t){"use strict";var n=function(e,o,n){var r="";r="undefined"!=typeof phantom?"phantomjs":void 0!==t(0)?"nodejs":"browser";var i=null,s=null;var g={Config:{group:"",always_use_utc:!1,targets:[]},AddLogTarget:function(e,o){var t={log_device:e,log_levels:o=o||"TDIWEF",output_group:!0,output_date:!0,output_time:!0,output_milliseconds:!0,output_timezone:!0,output_severity:!0,output_severity_words:!0,log_path:"",log_filename:"logger",log_extension:"log",use_hourly_logfiles:!1,use_daily_logfiles:!1};return g.Config.targets.push(t),t}};return g.SendTextToLogTarget=function(e,o,n){if(n.log_device=n.log_device.toLowerCase(),"console"==n.log_device||"stdout"==n.log_device)console.log(o);else if("stderr"==n.log_device)console.error(o);else if("file"==n.log_device){var g=n.log_filename;n.use_hourly_logfiles?g+="-"+e.toISOString().slice(0,13).replace(/T/g,"-"):n.use_daily_logfiles&&(g+="-"+e.toISOString().slice(0,10)),n.log_extension&&(g+="."+n.log_extension),function(e,o,n){if("browser"!=r){if("nodejs"!=r)return"phantomjs"==r?(i||(i=t(1)),(g=e)&&(g+=i.separator),g+=o,void i.write(g,n+"\n","a")):void 0;i||(i=t(1)),s||(s=t(0));var g=s.join(e,o);i.appendFileSync(g,n+"\n")}}(n.log_path,g,o)}},g.LogMessage=function(e,o,t){var n=new Date,r={};r.group=g.Config.group,r.date=n.getFullYear()+"-"+("0"+(n.getMonth()+1)).slice(-2)+"-"+("0"+n.getDate()).slice(-2),r.time=("0"+n.getHours()).slice(-2)+":"+("0"+n.getMinutes()).slice(-2)+":"+("0"+n.getSeconds()).slice(-2),r.milliseconds=("000"+n.getMilliseconds()).slice(-4);var i=n.getTimezoneOffset()%60,s=(n.getTimezoneOffset()-i)/60;return r.timezone=("0"+s).slice(-2)+("0"+i).slice(-2),o=o||"INFO",r.severity=o.substr(0,1).toUpperCase(),"T"==r.severity?r.severity_word="TRACE":"D"==r.severity?r.severity_word="DEBUG":"I"==r.severity?r.severity_word="INFO ":"W"==r.severity?r.severity_word="WARN ":"E"==r.severity?r.severity_word="ERROR":"F"==r.severity?r.severity_word="FATAL":r.severity_word=o,r.message=e,g.Config.targets.forEach((function(e){if(e.log_levels=e.log_levels.toUpperCase(),e.log_levels.indexOf(r.severity)>=0){var o="";e.output_group&&r.group&&(o+="| "+r.group+" "),e.output_date&&r.date&&(o+="| "+r.date+" "),e.output_time&&r.time&&(o+="| "+r.time+" "),e.output_milliseconds&&r.milliseconds&&(o+="| "+r.milliseconds+" "),e.output_timezone&&r.timezone&&(o+="| "+r.timezone+" "),e.output_severity_words?o+="| "+r.severity_word+" ":e.output_severity&&(o+="| "+r.severity+" "),o+="| "+r.message,t&&(o+="\n"+JSON.stringify(t,void 0," ")),g.SendTextToLogTarget(n,o,e)}})),r},g.LogTrace=function(e,o){g.LogMessage(e,"TRACE",o)},g.LogDebug=function(e,o){g.LogMessage(e,"DEBUG",o)},g.LogInfo=function(e,o){g.LogMessage(e,"INFO",o)},g.LogWarn=function(e,o){g.LogMessage(e,"WARN",o)},g.LogWarning=function(e,o){g.LogMessage(e,"WARN",o)},g.LogError=function(e,o){g.LogMessage(e,"ERROR",o)},g.LogFatal=function(e,o){g.LogMessage(e,"FATAL",o)},g.trace=function(e,o){g.LogMessage(e,"TRACE",o)},g.debug=function(e,o){g.LogMessage(e,"DEBUG",o)},g.info=function(e,o){g.LogMessage(e,"INFO",o)},g.log=function(e,o){g.LogMessage(e,"INFO",o)},g.warn=function(e,o){g.LogMessage(e,"WARN",o)},g.warning=function(e,o){g.LogMessage(e,"WARN",o)},g.error=function(e,o){g.LogMessage(e,"ERROR",o)},g.fatal=function(e,o){g.LogMessage(e,"FATAL",o)},g.LogBlankLine=function(){var e=new Date;g.Config.targets.forEach((function(o){g.SendTextToLogTarget(e,"",o)}))},g.LogSeparatorLine=function(){var e=new Date;g.Config.targets.forEach((function(o){g.SendTextToLogTarget(e,"==========================================",o)}))},g.Config.group=e||"",void 0!==o&&g.AddLogTarget(o,n),g};"undefined"!=typeof window&&(window.Logger=n),o.Logger=n}])})); | ||
!function(e,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define([],o):"object"==typeof exports?exports.lib_logger=o():e.lib_logger=o()}("undefined"!=typeof self?self:this,(function(){return function(e){var o={};function t(n){if(o[n])return o[n].exports;var r=o[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,t),r.l=!0,r.exports}return t.m=e,t.c=o,t.d=function(e,o,n){t.o(e,o)||Object.defineProperty(e,o,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,o){if(1&o&&(e=t(e)),8&o)return e;if(4&o&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&o&&"string"!=typeof e)for(var r in e)t.d(n,r,function(o){return e[o]}.bind(null,r));return n},t.n=function(e){var o=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(o,"a",o),o},t.o=function(e,o){return Object.prototype.hasOwnProperty.call(e,o)},t.p="",t(t.s=4)}([function(e,o){e.exports=require("path")},function(e,o){e.exports=require("fs")},function(e,o,t){"use strict";o.NewLogTarget=function(){let e={Config:{}};return e.Config.DeviceName="",e.Config.LogLevels="",e.Config.OutputGroup=!0,e.Config.OutputDate=!0,e.Config.OutputTime=!0,e.Config.OutputMilliseconds=!0,e.Config.OutputTimezone=!0,e.Config.OutputSeverity=!0,e.Config.OutputSeverityWord=!0,e.OnPrepareLogEntry=e=>{throw new Error("Function [OnPrepareLogEntry] not implemented by LogTarget!")},e.OnRenderLogText=(e,o,t)=>{throw new Error("Function [OnRenderLogText] not implemented by LogTarget!")},e}},function(e,o){const t={UnsetAll:0,Bold:1,Dim:2,Underlined:4,Blink:5,Invert:7,Hidden:8,UnsetBold:21,UnsetDim:22,UnsetUnderlined:24,UnsetBlink:25,UnsetInvert:27,UnsetHidden:28};o.ShellBackcolor={Default:49,Black:40,Red:41,Green:42,Yellow:43,Blue:44,Magenta:45,Cyan:46,LightGray:47,DarkGray:100,LightRed:101,LightGreen:102,LightYellow:103,LightBlue:104,LightMagenta:105,LightCyan:106,White:107},o.ShellForecolor={Default:39,Black:30,Red:31,Green:32,Yellow:33,Blue:34,Magenta:35,Cyan:36,LightGray:37,DarkGray:90,LightRed:91,LightGreen:92,LightYellow:93,LightBlue:94,LightMagenta:95,LightCyan:96,White:97},o.ShellEffect=t,o.ShellText=function(e,o,n,r){if(!o&&!n&&!r)return e;let i="[";return o&&(i+=o+";"),n&&(i+=n+";"),r&&(i+=r+";"),i=i.substr(0,i.length-1)+"m",i+=e,i+=`[${t.UnsetAll}m`,i}},function(e,o,t){"use strict";let n=t(5).Logger,r=t(6).NewLogger,i=t(7).NewConsoleLogTarget,l=t(8).NewShellLogTarget,g=t(9).NewFileLogTarget,s=e=>r(i(e)),u=e=>r(l(e)),a=e=>r(g(e));const c=t(3);"undefined"!=typeof window&&(window.Logger=n,window.NewLogger=r,window.NewConsoleLogTarget=i,window.NewShellLogTarget=l,window.NewFileLogTarget=g,window.NewConsoleLogger=s,window.NewShellLogger=u,window.NewFileLogger=a,window.ShellBackcolor=c.ShellBackcolor,window.ShellForecolor=c.ShellForecolor,window.ShellEffect=c.ShellEffect,window.ShellText=c.ShellText),o.Logger=n,o.NewLogger=r,o.NewConsoleLogTarget=i,o.NewShellLogTarget=l,o.NewFileLogTarget=g,o.NewConsoleLogger=s,o.NewShellLogger=u,o.NewFileLogger=a,o.ShellBackcolor=c.ShellBackcolor,o.ShellForecolor=c.ShellForecolor,o.ShellEffect=c.ShellEffect,o.ShellText=c.ShellText},function(e,o,t){"use strict";o.Logger=function(e,o,n){var r="";r="undefined"!=typeof phantom?"phantomjs":void 0!==t(0)?"nodejs":"browser";var i=null,l=null;var g={Config:{group:"",always_use_utc:!1,targets:[]},AddLogTarget:function(e,o){var t={log_device:e,log_levels:o=o||"TDIWEF",output_group:!0,output_date:!0,output_time:!0,output_milliseconds:!0,output_timezone:!0,output_severity:!0,output_severity_words:!0,log_path:"",log_filename:"logger",log_extension:"log",use_hourly_logfiles:!1,use_daily_logfiles:!1};return g.Config.targets.push(t),t}};return g.SendTextToLogTarget=function(e,o,n){if(n.log_device=n.log_device.toLowerCase(),"console"==n.log_device||"stdout"==n.log_device)console.log(o);else if("stderr"==n.log_device)console.error(o);else if("file"==n.log_device){var g=n.log_filename;n.use_hourly_logfiles?g+="-"+e.toISOString().slice(0,13).replace(/T/g,"-"):n.use_daily_logfiles&&(g+="-"+e.toISOString().slice(0,10)),n.log_extension&&(g+="."+n.log_extension),function(e,o,n){if("browser"!=r){if("nodejs"!=r)return"phantomjs"==r?(i||(i=t(1)),(g=e)&&(g+=i.separator),g+=o,void i.write(g,n+"\n","a")):void 0;i||(i=t(1)),l||(l=t(0));var g=l.join(e,o);i.appendFileSync(g,n+"\n")}}(n.log_path,g,o)}},g.LogMessage=function(e,o,t){var n=new Date,r={};r.group=g.Config.group,r.date=n.getFullYear()+"-"+("0"+(n.getMonth()+1)).slice(-2)+"-"+("0"+n.getDate()).slice(-2),r.time=("0"+n.getHours()).slice(-2)+":"+("0"+n.getMinutes()).slice(-2)+":"+("0"+n.getSeconds()).slice(-2),r.milliseconds=("000"+n.getMilliseconds()).slice(-4);var i=n.getTimezoneOffset()%60,l=(n.getTimezoneOffset()-i)/60;return r.timezone=("0"+l).slice(-2)+("0"+i).slice(-2),o=o||"INFO",r.severity=o.substr(0,1).toUpperCase(),"T"==r.severity?r.severity_word="TRACE":"D"==r.severity?r.severity_word="DEBUG":"I"==r.severity?r.severity_word="INFO ":"W"==r.severity?r.severity_word="WARN ":"E"==r.severity?r.severity_word="ERROR":"F"==r.severity?r.severity_word="FATAL":r.severity_word=o,r.message=e,g.Config.targets.forEach((function(e){if(e.log_levels=e.log_levels.toUpperCase(),e.log_levels.indexOf(r.severity)>=0){var o="";e.output_group&&r.group&&(o+="| "+r.group+" "),e.output_date&&r.date&&(o+="| "+r.date+" "),e.output_time&&r.time&&(o+="| "+r.time+" "),e.output_milliseconds&&r.milliseconds&&(o+="| "+r.milliseconds+" "),e.output_timezone&&r.timezone&&(o+="| "+r.timezone+" "),e.output_severity_words?o+="| "+r.severity_word+" ":e.output_severity&&(o+="| "+r.severity+" "),o+="| "+r.message,t&&(o+="\n"+JSON.stringify(t,void 0," ")),g.SendTextToLogTarget(n,o,e)}})),r},g.LogTrace=function(e,o){g.LogMessage(e,"TRACE",o)},g.LogDebug=function(e,o){g.LogMessage(e,"DEBUG",o)},g.LogInfo=function(e,o){g.LogMessage(e,"INFO",o)},g.LogWarn=function(e,o){g.LogMessage(e,"WARN",o)},g.LogWarning=function(e,o){g.LogMessage(e,"WARN",o)},g.LogError=function(e,o){g.LogMessage(e,"ERROR",o)},g.LogFatal=function(e,o){g.LogMessage(e,"FATAL",o)},g.trace=function(e,o){g.LogMessage(e,"TRACE",o)},g.debug=function(e,o){g.LogMessage(e,"DEBUG",o)},g.info=function(e,o){g.LogMessage(e,"INFO",o)},g.log=function(e,o){g.LogMessage(e,"INFO",o)},g.warn=function(e,o){g.LogMessage(e,"WARN",o)},g.warning=function(e,o){g.LogMessage(e,"WARN",o)},g.error=function(e,o){g.LogMessage(e,"ERROR",o)},g.fatal=function(e,o){g.LogMessage(e,"FATAL",o)},g.LogBlankLine=function(){var e=new Date;g.Config.targets.forEach((function(o){g.SendTextToLogTarget(e,"",o)}))},g.LogSeparatorLine=function(){var e=new Date;g.Config.targets.forEach((function(o){g.SendTextToLogTarget(e,"==========================================",o)}))},g.Config.group=e||"",void 0!==o&&g.AddLogTarget(o,n),g}},function(e,o,t){"use strict";o.NewLogger=function(e){let o={};return o.Group=e,o.LogTargets=[],o.AddLogTarget=function(e){return o.LogTargets.push(e),e},o.LogMessageRaw=function(e){var t=new Date;o.LogTargets.forEach((function(o){o.OnRenderLogText(t,{},e)}))},o.LogMessage=function(e,t,n){var r=new Date,i={};i.group=o.Group,i.date=r.getFullYear()+"-"+("0"+(r.getMonth()+1)).slice(-2)+"-"+("0"+r.getDate()).slice(-2),i.time=("0"+r.getHours()).slice(-2)+":"+("0"+r.getMinutes()).slice(-2)+":"+("0"+r.getSeconds()).slice(-2),i.milliseconds=("000"+r.getMilliseconds()).slice(-4);var l=r.getTimezoneOffset()%60,g=(r.getTimezoneOffset()-l)/60;return i.timezone=("0"+g).slice(-2)+("0"+l).slice(-2),t=t||"INFO",i.severity=t.substr(0,1).toUpperCase(),"T"==i.severity?i.severity_word="TRACE":"D"==i.severity?i.severity_word="DEBUG":"I"==i.severity?i.severity_word="INFO ":"W"==i.severity?i.severity_word="WARN ":"E"==i.severity?i.severity_word="ERROR":"F"==i.severity?i.severity_word="FATAL":i.severity_word=t,i.message=e,o.LogTargets.forEach((function(e){if(e.Config.LogLevels.toUpperCase().indexOf(i.severity)>=0){let t=JSON.parse(JSON.stringify(i));e.OnPrepareLogEntry(t);var o="";e.Config.OutputGroup&&t.group&&(o+="| "+t.group+" "),e.Config.OutputDate&&t.date&&(o+="| "+t.date+" "),e.Config.OutputTime&&t.time&&(o+="| "+t.time+" "),e.Config.OutputMilliseconds&&t.milliseconds&&(o+="| "+t.milliseconds+" "),e.Config.OutputTimezone&&t.timezone&&(o+="| "+t.timezone+" "),e.Config.OutputSeverityWord?o+="| "+t.severity_word+" ":e.Config.OutputSeverity&&(o+="| "+t.severity+" "),o+="| "+t.message,n&&(o+="\n"+JSON.stringify(n,void 0," ")),e.OnRenderLogText(r,t,o)}})),i},o.LogTrace=function(e,t){o.LogMessage(e,"TRACE",t)},o.LogDebug=function(e,t){o.LogMessage(e,"DEBUG",t)},o.LogInfo=function(e,t){o.LogMessage(e,"INFO",t)},o.LogWarn=function(e,t){o.LogMessage(e,"WARN",t)},o.LogWarning=function(e,t){o.LogMessage(e,"WARN",t)},o.LogError=function(e,t){o.LogMessage(e,"ERROR",t)},o.LogFatal=function(e,t){o.LogMessage(e,"FATAL",t)},o.trace=function(e,t){o.LogMessage(e,"TRACE",t)},o.debug=function(e,t){o.LogMessage(e,"DEBUG",t)},o.info=function(e,t){o.LogMessage(e,"INFO",t)},o.log=function(e,t){o.LogMessage(e,"INFO",t)},o.warn=function(e,t){o.LogMessage(e,"WARN",t)},o.warning=function(e,t){o.LogMessage(e,"WARN",t)},o.error=function(e,t){o.LogMessage(e,"ERROR",t)},o.fatal=function(e,t){o.LogMessage(e,"FATAL",t)},o.LogBlankLine=()=>o.LogMessageRaw(""),o.LogSeparatorLine=()=>o.LogMessageRaw("=========================================="),o}},function(e,o,t){"use strict";const n=t(2);o.NewConsoleLogTarget=function(e){let o=n.NewLogTarget();return o.Config.DeviceName="console",o.Config.LogLevels=e||"TDIWEF",o.Config.Console={},o.OnPrepareLogEntry=e=>{},o.OnRenderLogText=(e,o,t)=>{console.log(t)},o}},function(e,o,t){"use strict";const n=t(2),r=t(3);o.NewShellLogTarget=function(e){let o=n.NewLogTarget();function t(e,o){return"T"===o?e.TraceColors:"D"===o?e.DebugColors:"I"===o?e.InfoColors:"W"===o?e.WarnColors:"E"===o?e.ErrorColors:"F"===o?e.FatalColors:null}return o.Config.DeviceName="shell",o.Config.LogLevels=e||"TDIWEF",o.Config.Shell={ColorizeEntireLine:!1,ColorizeSeverity:!1,ColorizeMessage:!1,TraceColors:{Backcolor:null,Forecolor:null,Effect:null},DebugColors:{Backcolor:null,Forecolor:null,Effect:null},InfoColors:{Backcolor:null,Forecolor:null,Effect:null},WarnColors:{Backcolor:null,Forecolor:null,Effect:null},ErrorColors:{Backcolor:null,Forecolor:null,Effect:null},FatalColors:{Backcolor:null,Forecolor:null,Effect:null}},o.OnPrepareLogEntry=e=>{if(o.Config.Shell.ColorizeEntireLine)return;let n=t(o.Config.Shell,e.severity);n&&(o.Config.Shell.ColorizeSeverity&&(e.severity=r.ShellText(e.severity,n.Backcolor,n.Forecolor,n.Effect),e.severity_word=r.ShellText(e.severity,n.Backcolor,n.Forecolor,n.Effect)),o.Config.Shell.ColorizeMessage&&(e.message=r.ShellText(e.message,n.Backcolor,n.Forecolor,n.Effect)))},o.OnRenderLogText=(e,n,i)=>{if(o.Config.Shell.ColorizeEntireLine){let e=t(o.Config.Shell,n.severity);e&&(i=r.ShellText(i,e.Backcolor,e.Forecolor,e.Effect))}console.log(i)},o}},function(e,o,t){"use strict";const n=t(2);var r=null;try{r=t(0)}catch(e){}var i=null;try{i=t(1)}catch(e){}o.NewFileLogTarget=function(e){let o=n.NewLogTarget();function t(e,o,t){let n=null;(r||i)&&(r?(n=r.join(e,o),i.appendFile(n,t+"\n",()=>{})):(n=`${e}${i.separator}${o}`,i.write(filename,t+"\n","a")))}return o.Config.DeviceName="file",o.Config.LogLevels=e||"TDIWEF",o.Config.File={LogPath:"",LogFilename:"logger",LogExtension:"log",UseHourlyLogFiles:!1,UseDailyLogFiles:!1},o.OnPrepareLogEntry=e=>{},o.OnRenderLogText=(e,n,r)=>{let i=o.Config.File.LogFilename;o.Config.File.UseHourlyLogFiles?i+="-"+e.toISOString().slice(0,13).replace(/T/g,"-"):o.Config.File.UseDailyLogFiles&&(i+="-"+e.toISOString().slice(0,10)),o.Config.File.LogExtension&&(i+="."+o.Config.File.LogExtension),t(o.Config.File.LogPath,i,r)},o}}])})); |
<!-- _coverpage.md --> | ||
![logo](media/lib-logger.png) | ||
![logo](media/lib-logger-banner.png) | ||
# lib-logger <small>(v0.1.4)</small> | ||
# lib-logger <small>(v0.2.0)</small> | ||
@@ -15,2 +15,4 @@ <hr> | ||
- 100% JavaScript - No dependencies | ||
- Shell Colorized Output | ||
- Log to Files, Output to Console | ||
@@ -17,0 +19,0 @@ [GitHub](https://github.com/agbowlin/lib-logger/) |
@@ -7,15 +7,43 @@ <!-- _sidebar.md --> | ||
- [About](guides/readme.md) | ||
- [About](external/readme.md) | ||
- [Log Severity Levels](guides/LogSeverityLevels.md) | ||
- [Logging Techniques](guides/LoggingTechniques.md) | ||
<hr> | ||
- References | ||
- Library API | ||
- [Library Reference](guides/template-lib.md) | ||
- Loggers | ||
- [Logger](api/Logger.md) | ||
- [ConsoleLogger](api/ConsoleLogger.md) | ||
- [ShellLogger](api/ShellLogger.md) | ||
- [FileLogger](api/FileLogger.md) | ||
- Log Targets | ||
- [LogTarget](api/LogTarget.md) | ||
- [ConsoleLogTarget](api/ConsoleLogTarget.md) | ||
- [ShellLogTarget](api/ShellLogTarget.md) | ||
- [FileLogTarget](api/FileLogTarget.md) | ||
- Other Modules | ||
- [Shell Colorization](guides/Shell-Colorization.md) | ||
<hr> | ||
- Previous Library API | ||
- [Logger 0.1.x](api/Logger.0.1.x.md) | ||
<hr> | ||
- Information | ||
- [Testing Output](testing-output.md) | ||
- [Testing Output](external/testing-output.md) | ||
- [Software License](external/license.md) | ||
{ | ||
"name": "@liquicode/lib-logger", | ||
"version": "0.1.4", | ||
"description": "An easy logging system implemented for JavaScript and PHP.", | ||
"license": "MIT", | ||
"homepage": "http://lib-logger.liquicode.com", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/agbowlin/lib-logger.git" | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Andre G. Bowlin", | ||
"email": "agbowlin@gmail.com", | ||
"homepage": "http://liquicode.com" | ||
} | ||
], | ||
"main": "src/lib-logger.js", | ||
"files": [ | ||
"bower.json", | ||
"name": "@liquicode/lib-logger", | ||
"version": "0.2.0", | ||
"description": "An easy and flexible logging system. Log to console, files, etc. Now with colors!", | ||
"license": "MIT", | ||
"homepage": "http://lib-logger.liquicode.com", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/agbowlin/lib-logger.git" | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Andre G. Bowlin", | ||
"email": "agbowlin@gmail.com", | ||
"homepage": "http://liquicode.com" | ||
} | ||
], | ||
"main": "src/lib-logger.js", | ||
"files": [ | ||
"bower.json", | ||
"readme.md", | ||
@@ -27,6 +27,5 @@ "LICENSE", | ||
"src/*", | ||
"tests/*", | ||
"samples/*" | ||
], | ||
"ignore": [ | ||
"tests/*" | ||
], | ||
"ignore": [ | ||
".*", | ||
@@ -37,25 +36,24 @@ "~*", | ||
"build", | ||
"samples/logger.log", | ||
"*.log" | ||
], | ||
"keywords": [ | ||
"util", | ||
"functional", | ||
"server", | ||
"client", | ||
"browser", | ||
"nodejs", | ||
"log", | ||
"logger", | ||
"logging" | ||
], | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"bower": "^1.7.9", | ||
"mocha": "^7.1.2", | ||
"webpack": "^4.43.0", | ||
"webpack-cli": "^3.3.11", | ||
"webpack-node-externals": "^1.7.2" | ||
}, | ||
"scripts": { | ||
"*.log" | ||
], | ||
"keywords": [ | ||
"util", | ||
"functional", | ||
"server", | ||
"client", | ||
"browser", | ||
"nodejs", | ||
"log", | ||
"logger", | ||
"logging" | ||
], | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"bower": "^1.7.9", | ||
"mocha": "^7.1.2", | ||
"webpack": "^4.43.0", | ||
"webpack-cli": "^3.3.11", | ||
"webpack-node-externals": "^1.7.2" | ||
}, | ||
"scripts": { | ||
"run-tests": "mocha -u bdd tests/*.js --timeout 0 --slow 10 --colors", | ||
@@ -66,3 +64,3 @@ "run-docs-web-server": "npx here --directory docs --port 4200 --watch 1 --silent", | ||
"910-release-version": "node build/custom/910-release-version.js" | ||
} | ||
} | ||
} |
322
readme.md
lib-logger (v0.1.4) | ||
========================================== | ||
# lib-logger (v0.2.0) | ||
An easy logging system implemented for various platforms. | ||
An easy and flexible logging system. Log to console, files, etc. Now with colors! | ||
Installation | ||
------------------------------------------ | ||
--------------------------------------------------------------------- | ||
## Getting Started | ||
### Installation | ||
Traditional installation for server-side platforms (nodejs/phantomjs) | ||
``` | ||
```bash | ||
npm install @liquicode/lib-logger | ||
``` | ||
or: Traditional installation for client-side platforms (browser) | ||
``` | ||
```bash | ||
<bower install not yet supported> | ||
``` | ||
or: Clone the source code | ||
``` | ||
```bash | ||
git clone https://github.com/agbowlin/lib-logger.git | ||
``` | ||
or: Download the source code | ||
``` | ||
https://github.com/agbowlin/lib-logger/archive/master.zip | ||
``` | ||
Logger source files will be located within the platform specific subfolders | ||
of the installation (e.g. js/, php/). | ||
Samples for each platform can also be found underneath these subfolders. | ||
or: Download the latest source code | ||
Getting Started | ||
------------------------------------------ | ||
### Javascript: Browser (client) | ||
```bash | ||
https://github.com/agbowlin/lib-logger/archive/master.zip | ||
``` | ||
// logger.js in installed via 'bower install liqui-logger' | ||
var Logger = require('bower_components/liqui-logger/js/logger').Logger(); | ||
Logger.AddLogTarget( 'console' ); | ||
Logger.LogMessage( 'Hello, World!' ); | ||
``` | ||
### Javascript: NodeJS and PhantomJS | ||
``` | ||
// logger.js in installed via 'npm install liqui-logger' | ||
var Logger = require( 'liqui-logger/js/logger' ).Logger(); | ||
Logger.AddLogTarget( 'console' ); | ||
Logger.LogMessage( 'Hello, World!' ); | ||
``` | ||
In javascript you can create a new Log Target by providing a Log Group, Log Target, | ||
and message severity flags within the constructor: | ||
``` | ||
var Logger = require( 'liqui-logger/js/logger' ).Logger( 'My Group', 'console', 'TDIWEF' ); | ||
Logger.LogMessage( 'Hello, My Logs!' ); | ||
``` | ||
### PHP | ||
``` | ||
// logger.php is copied manually into the project folder. | ||
require_once( 'logger.php' ); | ||
$Logger->AddLogTarget( 'console' ); | ||
$Logger->LogMessage( 'Hello, World!' ); | ||
``` | ||
In PHP you can create a new Log Target by providing a Log Group, Log Target, | ||
and message severity flags within the constructor: | ||
``` | ||
require_once( 'logger.php' ); | ||
$MyLogger = new Logger( 'My Group', 'console', 'TDIWEF' ); | ||
$MyLogger->LogMessage( 'Hello, My Logs!' ); | ||
``` | ||
### Referencing the Library | ||
Sample Output | ||
------------------------------------------ | ||
```javascript | ||
const LIB_LOGGER = require( '@liquicode/lib-logger' ); | ||
``` | ||
group date time ms severity message | ||
| | | | | | | ||
v v v v v v | ||
========================================== | ||
| Test Group | 2017-01-12 | 03:42:37 | 1547 | TRACE | This is a Trace message. | ||
| Test Group | 2017-01-12 | 03:42:37 | 1548 | DEBUG | This is a Debug message. | ||
| Test Group | 2017-01-12 | 03:42:37 | 1549 | INFO | This is an Info message. | ||
| Test Group | 2017-01-12 | 03:42:37 | 1551 | WARN | This is a Warn message. | ||
| Test Group | 2017-01-12 | 03:42:37 | 1552 | ERROR | This is an Error message. | ||
========================================== | ||
| Test Group | 2017-01-12 | 03:42:37 | 1559 | INFO | Here is some extra data: | ||
{ | ||
"Field1": "Foo", <--- extra data | ||
"Field2": "Bar" | ||
} | ||
========================================== <--- separator line | ||
``` | ||
From the library reference `LIB_LOGGER`, you can create specific loggers for | ||
different output devices or a generalized logger to render log messages on | ||
multiple devices. | ||
Supported Platforms | ||
------------------------------------------ | ||
Logger is available for several platforms. | ||
Pains have been taken to make the api consistent between platform implementations. | ||
### Supported Platforms | ||
Supported platforms: | ||
- PHP | ||
- Javascipt | ||
- Browser | ||
- NodeJS | ||
- PhantomJS | ||
`lib-logger` works with several platforms. | ||
- Browser | ||
- NodeJS | ||
- PhantomJS | ||
Logger Configuration | ||
------------------------------------------ | ||
Logger configuration is stored in the Logger.Config object. | ||
This object has the following properties: | ||
--------------------------------------------------------------------- | ||
- `group` : Text to display in the Group column of log output. | ||
- `always_use_utc` : (not yet implemented) | ||
- `targets` : An array of log targets. All messages sent to the Logger are | ||
sent to all log targets. See the ***Log Devices*** section for more information. | ||
## Simple Usage | ||
Logger Functions | ||
------------------------------------------ | ||
### In NodeJS | ||
### Configuration | ||
- `AddLogTarget(LogDevice, LogLevels)` : Adds a new log target to the `Logger.Config.targets` array. | ||
See the ***Log Targets*** section for more information. | ||
- `LogDevice` (required) : The log device to be added (e.g. console, file). | ||
See the ***Log Devices*** section for more information. | ||
- `LogLevels` (optional) : A severity filter to be appplied to this log target. | ||
The default value is 'TDIWEF' which will output messages of any severity. | ||
See the ***Log Levels and Message Severity*** section for more information. | ||
```javascript | ||
// Reference the library. | ||
const LIB_LOGGER = require( '@liquicode/lib-logger' ); | ||
### Logging Functions | ||
- `LogMessage(Message, Severity, ExtraData)` : This function formats and routes | ||
the message to each eligible log target in the `Logger.Config.targets` array. | ||
- `Message` (required) : The text message to send to the log targets. | ||
This will be formatted according to each log target's configuration. | ||
- `Severity` (optional) : The severity of the message. | ||
This defaults to 'INFO'. | ||
- `ExtraData` (optional) : If present, this parameter will be JSON encoded and | ||
output into subsequent lines of the log. | ||
- `LogBlankLine()` : Outputs a blank line to the log. Sometimes you just need a blank line. | ||
- `LogSeparatorLine()` : Outputs a separator line to the log. A separator line is | ||
a series of equal '=' signs on the same line. This can help visually group | ||
together related log lines. | ||
// Call NewShellLogger() to get a logger object that prints message to the console. | ||
let Logger = LIB_LOGGER.NewShellLogger( 'My Optional Log Group Name' ); | ||
### Convenience Functions | ||
- `LogTrace(Message, ExtraData)` : Calls `LogMessage` with a `Severity` of 'TRACE'. | ||
- `LogDebug(Message, ExtraData)` : Calls `LogMessage` with a `Severity` of 'DEBUG'. | ||
- `LogInfo(Message, ExtraData)` : Calls `LogMessage` with a `Severity` of 'INFO'. | ||
- `LogWarn(Message, ExtraData)` : Calls `LogMessage` with a `Severity` of 'WARN'. | ||
- `LogWarning(Message, ExtraData)` : Calls `LogMessage` with a `Severity` of 'WARN'. | ||
- `LogError(Message, ExtraData)` : Calls `LogMessage` with a `Severity` of 'ERROR'. | ||
- `LogFatal(Message, ExtraData)` : Calls `LogMessage` with a `Severity` of 'FATAL'. | ||
Log Levels and Message Severity | ||
------------------------------------------ | ||
Log messages have a severity associated with them which range from the most | ||
verbose 'TRACE' messages to the most urgent 'ERROR' and 'FATAL' messages. | ||
Each log target in `Logger.Config.targets` has its own `log_levels` field | ||
which contains one or more of the characters 'TDIWEF' and serves as a message | ||
filter for that log target. | ||
If the first letter of a message severity (e.g. I for INFO), does not occur within | ||
`log_levels`, then that message will be ignored by that log target. | ||
The following message severities are supported: | ||
- TRACE : Used for tracing the flow of logic within software. | ||
Trace messages are inserted at function entry and exit points (e.g. 'Starting FooBar() ...''). | ||
Trace messages are also used to report on the execution of significant logic milestones (e.g. 'Calc completed'). | ||
- DEBUG : Used to output diagnostic data and program state information to the log. | ||
This type information is useful for validating and debugging software processes. | ||
Debug messages will often contain data dumps of some program variables. | ||
Use the `ExtraData` parameter in any of the Log functions to dump the JSON representation | ||
of a data object to the log with your `Message`. | ||
- INFO : Informational messages regarding the health and processing activity of software. | ||
This will typically be the minimum severity set for log messages within a production environment. | ||
Typical INFO messages might be: | ||
'Authenticated user' or 'Completed Item 3 of 61'. | ||
INFO messages can be used to help analyze and determine the health of a system. | ||
- WARN : A warning message indicates an adverse condition exists, yet it does not prevent | ||
the completion of the task at hand. | ||
Examples: | ||
- 'Found multiple contacts for phone number 555-1212.' | ||
- 'Connection is unavailable, retrying ...' | ||
- 'Available storage is less than 5%' | ||
- ERROR : Errors prevent the software from completing certain tasks successfuly. | ||
The software may continue to run after an error, however it may be likely to | ||
continue generating those errors. | ||
- FATAL : Fatal errors prevent the software from executing at all. After a fatal | ||
error, the software should shut down immediately. | ||
### Logging Strategies | ||
During development, you may want to have only informational message sent to the | ||
console while maintaining a log file containing all log messages. You would | ||
add two log devices and configure the console device to limit the severity of | ||
log messages displayed on it. | ||
// Log something | ||
Logger.LogInfo( 'Hello, World!' ); | ||
``` | ||
var console_log_target = Logger.AddLogTarget('console', 'IWEF'); // Only IWEF messages for the console. | ||
var file_log_target = Logger.AddLogTarget('file', 'TDIWEF'); // All messages for the file. | ||
Logger.LogMessage( 'Hello, World!', 'INFO' ); // console and file. | ||
Logger.LogMessage( 'Hello, File!', 'DEBUG' ); // file only, no console! | ||
``` | ||
You may want to have log files which contain only error messages. Changes to the | ||
size of this file could be monitored to provide an easy early warning system. | ||
``` | ||
var file_log_target = Logger.AddLogTarget('file', 'TDIWEF'); // All messages for this file. | ||
var error_log_target = Logger.AddLogTarget('file', 'EF'); // Only the bad stuff for this file. | ||
Logger.LogMessage( 'Hello, World!', 'INFO' ); // Everything is fine here, no errors. | ||
Logger.LogMessage( 'My Bad!', 'ERROR' ); // The error log file is updated! | ||
``` | ||
### In the Browser (client) | ||
To assist in troubleshooting, you may have a daily production log (IWEF) and | ||
more verbose hourly logs (TDIWEF). Given a timestamp of an error or warning from | ||
the production log, you could quickly navigate to the correct hourly log for | ||
further investigation. | ||
``` | ||
var production_log_target = Logger.AddLogTarget('file', 'IWEF'); | ||
production_log_target.use_daily_logfiles = true; // One log file per day | ||
```javascript | ||
// Reference the library. | ||
// (installed via 'bower install liqui-logger' ?) | ||
const LIB_LOGGER = require('bower_components/liqui-logger/js/logger'); | ||
var debug_log_target = Logger.AddLogTarget('file', 'TDIWEF'); | ||
debug_log_target.use_hourly_logfiles = true; // One log file per hour | ||
// Call NewConsoleLogger() to get a logger object that prints message to the console. | ||
let Logger = LIB_LOGGER.NewConsoleLogger( 'My Optional Log Group Name' ); | ||
Logger.LogMessage( 'Hello, World!', 'INFO' ); // Just the facts, available in both targets. | ||
Logger.LogMessage( 'Dump of the foo object:', 'DEBUG', foo ); // Only in the debug target! | ||
// Log something | ||
Logger.LogInfo( 'Hello, World!' ); | ||
Logger.info( 'Hello, Again!' ); | ||
``` | ||
Log Targets | ||
------------------------------------------ | ||
--------------------------------------------------------------------- | ||
The following fields are available for all log devices. | ||
``` | ||
log_device: '' | ||
log_levels: '' | ||
output_group: true, | ||
output_date: true, | ||
output_time: true, | ||
output_milliseconds: true, | ||
output_timezone: true, | ||
output_severity: true, | ||
output_severity_words: true, | ||
``` | ||
## Sample Output | ||
Log Devices | ||
------------------------------------------ | ||
Each log target identifies a log device | ||
### Console | ||
``` | ||
log_device: 'console' | ||
log_device: 'stdout' | ||
log_device: 'stderr' | ||
group date time ms severity message | ||
| | | | | | | ||
v v v v v v | ||
========================================== | ||
| Test Group | 2017-01-12 | 03:42:37 | 1547 | TRACE | This is a Trace message. | ||
| Test Group | 2017-01-12 | 03:42:37 | 1548 | DEBUG | This is a Debug message. | ||
| Test Group | 2017-01-12 | 03:42:37 | 1549 | INFO | This is an Info message. | ||
| Test Group | 2017-01-12 | 03:42:37 | 1551 | WARN | This is a Warn message. | ||
| Test Group | 2017-01-12 | 03:42:37 | 1552 | ERROR | This is an Error message. | ||
========================================== | ||
| Test Group | 2017-01-12 | 03:42:37 | 1559 | INFO | Here is some extra data: | ||
{ | ||
"Field1": "Foo", <--- extra data | ||
"Field2": "Bar" | ||
} | ||
========================================== <--- separator line | ||
``` | ||
### File | ||
![ShellLogTarget colorized output](http://lib-logger.liquicode.com/media/logger-color-output.png) | ||
``` | ||
log_device: 'file', | ||
log_path: 'path/to/logs', | ||
log_filename: 'filename', | ||
log_extension: 'log', | ||
use_hourly_logfiles: true, | ||
use_daily_logfiles: true | ||
``` | ||
--------------------------------------------------------------------- | ||
Examples | ||
------------------------------------------ | ||
## Links to More | ||
- [Source Code](https://github.com/agbowlin/lib-logger) | ||
- [Documentation](http://lib-logger.liquicode.com) | ||
- [NPM Registry](https://www.npmjs.com/package/@liquicode/lib-logger) | ||
### PHP | ||
``` | ||
// Create the Logger object. | ||
require_once( 'node_modules/liqui-logger/php/logger.php' ); | ||
//or: require_once( 'bower/liqui-logger/php/logger.php' ); | ||
//or local copy: require_once( 'logger.php' ); | ||
// Set a group name. (optional) | ||
$Logger->Config->group = 'My App'; | ||
// Add a log target. (required) | ||
$console_log_target = $Logger->AddLogTarget( 'console' ); | ||
// Configure this log target to be a bit less verbose. | ||
$console_log_target->output_date = false; | ||
$console_log_target->output_timezone = false; | ||
``` | ||
@@ -11,382 +11,41 @@ //===================================================================== | ||
var Logger = function ( Group, LogDevice, LogLevels ) | ||
{ | ||
// API v0.1.x | ||
let Logger = require( './Logger.0.1.x.js' ).Logger; | ||
// New API | ||
//===================================================================== | ||
// Determine the platform we are executing on. | ||
var platform = ''; | ||
if ( typeof phantom != 'undefined' ) | ||
{ | ||
platform = 'phantomjs'; | ||
} | ||
else if ( typeof require( 'path' ) != 'undefined' ) | ||
{ | ||
platform = 'nodejs'; | ||
} | ||
else | ||
{ | ||
platform = 'browser'; | ||
} | ||
// - Logger | ||
let NewLogger = require( './Logger.js' ).NewLogger; | ||
// - Log Targets | ||
let NewConsoleLogTarget = require( './LogTargets/ConsoleLogTarget.js' ).NewConsoleLogTarget; | ||
let NewShellLogTarget = require( './LogTargets/ShellLogTarget.js' ).NewShellLogTarget; | ||
let NewFileLogTarget = require( './LogTargets/FileLogTarget.js' ).NewFileLogTarget; | ||
//===================================================================== | ||
// A platform specific file function. | ||
var npm_fs = null; | ||
var npm_path = null; | ||
// - Loggers | ||
let NewConsoleLogger = ( LogLevels ) => NewLogger( NewConsoleLogTarget( LogLevels ) ); | ||
let NewShellLogger = ( LogLevels ) => NewLogger( NewShellLogTarget( LogLevels ) ); | ||
let NewFileLogger = ( LogLevels ) => NewLogger( NewFileLogTarget( LogLevels ) ); | ||
function FileAppendTextLine( Path, Filename, Text ) | ||
{ | ||
if ( platform == 'browser' ) | ||
{ | ||
return; | ||
} | ||
else if ( platform == 'nodejs' ) | ||
{ | ||
if ( !npm_fs ) | ||
{ | ||
npm_fs = require( 'fs' ); | ||
} | ||
if ( !npm_path ) | ||
{ | ||
npm_path = require( 'path' ); | ||
} | ||
var filename = npm_path.join( Path, Filename ); | ||
npm_fs.appendFileSync( filename, Text + "\n" ); | ||
return; | ||
} | ||
else if ( platform == 'phantomjs' ) | ||
{ | ||
if ( !npm_fs ) | ||
{ | ||
npm_fs = require( 'fs' ); | ||
} | ||
var filename = Path; | ||
if ( filename ) | ||
{ | ||
filename += npm_fs.separator; | ||
} | ||
filename += Filename; | ||
npm_fs.write( filename, Text + "\n", 'a' ); | ||
return; | ||
} | ||
// Shell Colors | ||
const LIB_SHELL_COLORS = require( './ShellColors.js' ); | ||
} | ||
var Logger = {}; | ||
//===================================================================== | ||
// Logger configuration object. | ||
Logger.Config = { | ||
group: '', | ||
always_use_utc: false, | ||
targets: [] | ||
}; | ||
//===================================================================== | ||
Logger.AddLogTarget = | ||
function AddLogTarget( LogDevice, LogLevels ) | ||
{ | ||
LogLevels = LogLevels || 'TDIWEF'; | ||
var log_target = { | ||
log_device: LogDevice, | ||
log_levels: LogLevels, | ||
// Output options (all devices) | ||
output_group: true, | ||
output_date: true, | ||
output_time: true, | ||
output_milliseconds: true, | ||
output_timezone: true, | ||
output_severity: true, | ||
output_severity_words: true, | ||
// Options for file device | ||
log_path: '', | ||
log_filename: 'logger', | ||
log_extension: 'log', | ||
use_hourly_logfiles: false, | ||
use_daily_logfiles: false | ||
}; | ||
Logger.Config.targets.push( log_target ); | ||
return log_target; | ||
}; | ||
//===================================================================== | ||
Logger.SendTextToLogTarget = | ||
function SendTextToLogTarget( Timestamp, Text, LogTarget ) | ||
{ | ||
LogTarget.log_device = LogTarget.log_device.toLowerCase(); | ||
if ( ( LogTarget.log_device == 'console' ) || ( LogTarget.log_device == 'stdout' ) ) | ||
{ | ||
console.log( Text ); | ||
} | ||
else if ( LogTarget.log_device == 'stderr' ) | ||
{ | ||
console.error( Text ); | ||
} | ||
else if ( LogTarget.log_device == 'file' ) | ||
{ | ||
var filename = LogTarget.log_filename; | ||
if ( LogTarget.use_hourly_logfiles ) | ||
{ | ||
filename += '-' + Timestamp.toISOString().slice( 0, 13 ).replace( /T/g, '-' ); | ||
} | ||
else if ( LogTarget.use_daily_logfiles ) | ||
{ | ||
filename += '-' + Timestamp.toISOString().slice( 0, 10 ); | ||
} | ||
if ( LogTarget.log_extension ) | ||
{ | ||
filename += '.' + LogTarget.log_extension; | ||
} | ||
FileAppendTextLine( LogTarget.log_path, filename, Text ); | ||
} | ||
return; | ||
}; | ||
//===================================================================== | ||
Logger.LogMessage = | ||
function LogMessage( Message, Severity, ExtraData ) | ||
{ | ||
var date = new Date(); | ||
var log_entry = {}; | ||
// Get the message group. | ||
log_entry.group = Logger.Config.group; | ||
// Get the message timestamp. | ||
log_entry.date = date.getFullYear() + | ||
"-" + ( "0" + ( date.getMonth() + 1 ) ).slice( -2 ) + | ||
"-" + ( "0" + date.getDate() ).slice( -2 ); | ||
log_entry.time = ( "0" + date.getHours() ).slice( -2 ) + | ||
":" + ( "0" + date.getMinutes() ).slice( -2 ) + | ||
":" + ( "0" + date.getSeconds() ).slice( -2 ); | ||
log_entry.milliseconds = ( "000" + date.getMilliseconds() ).slice( -4 ); | ||
// Get the timezone offset. | ||
var timezone_minutes = date.getTimezoneOffset() % 60; | ||
var timezone_hours = ( date.getTimezoneOffset() - timezone_minutes ) / 60; | ||
log_entry.timezone = ( "0" + timezone_hours ).slice( -2 ) + ( "0" + timezone_minutes ).slice( -2 ); | ||
// Get the message severity. | ||
Severity = Severity || 'INFO'; | ||
log_entry.severity = Severity.substr( 0, 1 ).toUpperCase(); | ||
if ( log_entry.severity == 'T' ) | ||
{ | ||
log_entry.severity_word = 'TRACE'; | ||
} | ||
else if ( log_entry.severity == 'D' ) | ||
{ | ||
log_entry.severity_word = 'DEBUG'; | ||
} | ||
else if ( log_entry.severity == 'I' ) | ||
{ | ||
log_entry.severity_word = 'INFO '; | ||
} | ||
else if ( log_entry.severity == 'W' ) | ||
{ | ||
log_entry.severity_word = 'WARN '; | ||
} | ||
else if ( log_entry.severity == 'E' ) | ||
{ | ||
log_entry.severity_word = 'ERROR'; | ||
} | ||
else if ( log_entry.severity == 'F' ) | ||
{ | ||
log_entry.severity_word = 'FATAL'; | ||
} | ||
else | ||
{ | ||
log_entry.severity_word = Severity; | ||
} | ||
// Get the message. | ||
log_entry.message = Message; | ||
// Emit the log entry to the targets. | ||
Logger.Config.targets.forEach( | ||
function ( log_target ) | ||
{ | ||
log_target.log_levels = log_target.log_levels.toUpperCase(); | ||
if ( log_target.log_levels.indexOf( log_entry.severity ) >= 0 ) | ||
{ | ||
// Construct the output message. | ||
var out_message = ''; | ||
var left_side = '| '; | ||
var right_side = ' '; | ||
if ( log_target.output_group && log_entry.group ) | ||
{ | ||
out_message += left_side + log_entry.group + right_side; | ||
} | ||
if ( log_target.output_date && log_entry.date ) | ||
{ | ||
out_message += left_side + log_entry.date + right_side; | ||
} | ||
if ( log_target.output_time && log_entry.time ) | ||
{ | ||
out_message += left_side + log_entry.time + right_side; | ||
} | ||
if ( log_target.output_milliseconds && log_entry.milliseconds ) | ||
{ | ||
out_message += left_side + log_entry.milliseconds + right_side; | ||
} | ||
if ( log_target.output_timezone && log_entry.timezone ) | ||
{ | ||
out_message += left_side + log_entry.timezone + right_side; | ||
} | ||
if ( log_target.output_severity_words ) | ||
{ | ||
out_message += left_side + log_entry.severity_word + right_side; | ||
} | ||
else if ( log_target.output_severity ) | ||
{ | ||
out_message += left_side + log_entry.severity + right_side; | ||
} | ||
out_message += left_side + log_entry.message; | ||
// Add the extra data. | ||
if ( ExtraData ) | ||
{ | ||
out_message += "\n" + JSON.stringify( ExtraData, undefined, " " ); | ||
} | ||
// Emit the log entry | ||
Logger.SendTextToLogTarget( date, out_message, log_target ); | ||
} | ||
} ); | ||
// Return the message. | ||
return log_entry; | ||
}; | ||
//===================================================================== | ||
// Some sugar for declarative functions. | ||
Logger.LogTrace = | ||
function LogTrace( Message, ExtraData ) | ||
{ | ||
Logger.LogMessage( Message, 'TRACE', ExtraData ); | ||
}; | ||
Logger.LogDebug = | ||
function LogDebug( Message, ExtraData ) | ||
{ | ||
Logger.LogMessage( Message, 'DEBUG', ExtraData ); | ||
}; | ||
Logger.LogInfo = | ||
function LogInfo( Message, ExtraData ) | ||
{ | ||
Logger.LogMessage( Message, 'INFO', ExtraData ); | ||
}; | ||
Logger.LogWarn = | ||
function LogWarn( Message, ExtraData ) | ||
{ | ||
Logger.LogMessage( Message, 'WARN', ExtraData ); | ||
}; | ||
Logger.LogWarning = | ||
function LogWarning( Message, ExtraData ) | ||
{ | ||
Logger.LogMessage( Message, 'WARN', ExtraData ); | ||
}; | ||
Logger.LogError = | ||
function LogError( Message, ExtraData ) | ||
{ | ||
Logger.LogMessage( Message, 'ERROR', ExtraData ); | ||
}; | ||
Logger.LogFatal = | ||
function LogError( Message, ExtraData ) | ||
{ | ||
Logger.LogMessage( Message, 'FATAL', ExtraData ); | ||
}; | ||
//===================================================================== | ||
// More sugar for common logger interoperability (e.g. MongoDB.logger) | ||
Logger.trace = | ||
function trace( Message, ExtraData ) | ||
{ | ||
Logger.LogMessage( Message, 'TRACE', ExtraData ); | ||
}; | ||
Logger.debug = | ||
function debug( Message, ExtraData ) | ||
{ | ||
Logger.LogMessage( Message, 'DEBUG', ExtraData ); | ||
}; | ||
Logger.info = | ||
function info( Message, ExtraData ) | ||
{ | ||
Logger.LogMessage( Message, 'INFO', ExtraData ); | ||
}; | ||
Logger.log = | ||
function log( Message, ExtraData ) | ||
{ | ||
Logger.LogMessage( Message, 'INFO', ExtraData ); | ||
}; | ||
Logger.warn = | ||
function warn( Message, ExtraData ) | ||
{ | ||
Logger.LogMessage( Message, 'WARN', ExtraData ); | ||
}; | ||
Logger.warning = | ||
function warning( Message, ExtraData ) | ||
{ | ||
Logger.LogMessage( Message, 'WARN', ExtraData ); | ||
}; | ||
Logger.error = | ||
function error( Message, ExtraData ) | ||
{ | ||
Logger.LogMessage( Message, 'ERROR', ExtraData ); | ||
}; | ||
Logger.fatal = | ||
function fatal( Message, ExtraData ) | ||
{ | ||
Logger.LogMessage( Message, 'FATAL', ExtraData ); | ||
}; | ||
//===================================================================== | ||
Logger.LogBlankLine = | ||
function LogBlankLine() | ||
{ | ||
var date = new Date(); | ||
Logger.Config.targets.forEach( | ||
function ( log_target ) | ||
{ | ||
Logger.SendTextToLogTarget( date, '', log_target ); | ||
} ); | ||
}; | ||
//===================================================================== | ||
Logger.LogSeparatorLine = | ||
function LogSeparatorLine() | ||
{ | ||
var date = new Date(); | ||
Logger.Config.targets.forEach( | ||
function ( log_target ) | ||
{ | ||
Logger.SendTextToLogTarget( date, '==========================================', log_target ); | ||
} ); | ||
}; | ||
Logger.Config.group = Group || ''; | ||
if ( typeof LogDevice != 'undefined' ) | ||
{ | ||
Logger.AddLogTarget( LogDevice, LogLevels ); | ||
} | ||
return Logger; | ||
}; | ||
//===================================================================== | ||
// Integrate with the browser environment. | ||
if ( typeof window != 'undefined' ) | ||
if ( typeof window !== 'undefined' ) | ||
{ | ||
window[ 'Logger' ] = Logger; | ||
window[ 'NewLogger' ] = NewLogger; | ||
window[ 'NewConsoleLogTarget' ] = NewConsoleLogTarget; | ||
window[ 'NewShellLogTarget' ] = NewShellLogTarget; | ||
window[ 'NewFileLogTarget' ] = NewFileLogTarget; | ||
window[ 'NewConsoleLogger' ] = NewConsoleLogger; | ||
window[ 'NewShellLogger' ] = NewShellLogger; | ||
window[ 'NewFileLogger' ] = NewFileLogger; | ||
window[ 'ShellBackcolor' ] = LIB_SHELL_COLORS.ShellBackcolor; | ||
window[ 'ShellForecolor' ] = LIB_SHELL_COLORS.ShellForecolor; | ||
window[ 'ShellEffect' ] = LIB_SHELL_COLORS.ShellEffect; | ||
window[ 'ShellText' ] = LIB_SHELL_COLORS.ShellText; | ||
} | ||
@@ -397,5 +56,16 @@ | ||
// Integrate with the nodejs environment. | ||
if ( typeof exports != 'undefined' ) | ||
if ( typeof exports !== 'undefined' ) | ||
{ | ||
exports.Logger = Logger; | ||
exports.NewLogger = NewLogger; | ||
exports.NewConsoleLogTarget = NewConsoleLogTarget; | ||
exports.NewShellLogTarget = NewShellLogTarget; | ||
exports.NewFileLogTarget = NewFileLogTarget; | ||
exports.NewConsoleLogger = NewConsoleLogger; | ||
exports.NewShellLogger = NewShellLogger; | ||
exports.NewFileLogger = NewFileLogger; | ||
exports.ShellBackcolor = LIB_SHELL_COLORS.ShellBackcolor; | ||
exports.ShellForecolor = LIB_SHELL_COLORS.ShellForecolor; | ||
exports.ShellEffect = LIB_SHELL_COLORS.ShellEffect; | ||
exports.ShellText = LIB_SHELL_COLORS.ShellText; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
49
1362
211120
130
4