diff --git a/ui (gen4)/features/core.js b/ui (gen4)/features/core.js index 01dada3c..1cfd1d42 100755 --- a/ui (gen4)/features/core.js +++ b/ui (gen4)/features/core.js @@ -274,11 +274,15 @@ var LoggerActions = actions.Actions({ this.log && this.log.splice(0, this.log.length) return this }, - print: function(){ - return this.log ? + print: function(to_console){ + to_console = to_console === undefined ? + true + : to_console + var str = this.log ? this.log - .map(function([path, status, rest]){ - return path.join(': ') + (path.length > 0 ? ': ' : '') + .map(function([date, path, status, rest]){ + return `[${ new Date(date).getTimeStamp(true) }] ` + + path.join(': ') + (path.length > 0 ? ': ' : '') + status + (rest.length > 1 ? ':\n\t' @@ -287,7 +291,10 @@ var LoggerActions = actions.Actions({ : '') + rest.join(': ') }) .join('\n') - : '' }, + : '' + return to_console ? + (console.log(str), this) + : str }, // main API... @@ -313,10 +320,13 @@ var LoggerActions = actions.Actions({ emit: function(status, ...rest){ // write to log... this.log !== false - && this.log.push([this.path, status, rest]) + && this.log.push([ + Date.now(), + this.path, + status, + rest]) // maintain log size... this.log !== false - && this.log.push([this.path, status, rest]) && (this.max_size > 0 && this.log.length > this.max_size && this.log.splice(0, this.log.length - this.max_size)) @@ -829,6 +839,9 @@ module.LifeCycle = ImageGridFeatures.Feature({ doc: '', tag: 'lifecycle', + suggested: [ + 'logger', + ], priority: 'high', actions: LifeCycleActions, @@ -2289,6 +2302,9 @@ module.SelfTest = ImageGridFeatures.Feature({ depends: [ 'lifecycle' ], + suggested: [ + 'logger', + ], priority: 'low', actions: SelfTestActions, diff --git a/ui (gen4)/features/meta.js b/ui (gen4)/features/meta.js index 030ee6c8..9f5bc48a 100755 --- a/ui (gen4)/features/meta.js +++ b/ui (gen4)/features/meta.js @@ -25,7 +25,6 @@ core.ImageGridFeatures.Feature('imagegrid-commandline', [ core.ImageGridFeatures.Feature('imagegrid-minimal', [ 'lifecycle', - 'logger', // XXX 'alias', 'peer', 'fs', diff --git a/ui (gen4)/lib/util.js b/ui (gen4)/lib/util.js index c9be6b0b..fa02c8a3 100755 --- a/ui (gen4)/lib/util.js +++ b/ui (gen4)/lib/util.js @@ -333,36 +333,28 @@ var patchDate = module.patchDate = function(date){ date = date || Date - date.prototype.toShortDate = function(){ - var y = this.getFullYear() - var M = this.getMonth()+1 - M = M < 10 ? '0'+M : M - var D = this.getDate() - D = D < 10 ? '0'+D : D - var H = this.getHours() - H = H < 10 ? '0'+H : H - var m = this.getMinutes() - m = m < 10 ? '0'+m : m - var s = this.getSeconds() - s = s < 10 ? '0'+s : s - - return ''+y+'-'+M+'-'+D+' '+H+':'+m+':'+s - } - date.prototype.getTimeStamp = function(no_seconds){ - var y = this.getFullYear() - var M = this.getMonth()+1 - M = M < 10 ? '0'+M : M - var D = this.getDate() - D = D < 10 ? '0'+D : D - var H = this.getHours() - H = H < 10 ? '0'+H : H - var m = this.getMinutes() - m = m < 10 ? '0'+m : m - var s = this.getSeconds() - s = s < 10 ? '0'+s : s - - return ''+y+M+D+H+m+s - } + date.prototype.toShortDate = function(show_ms){ + return '' + + this.getFullYear() + +'-'+ ('0'+this.getMonth()+1).slice(-2) + +'-'+ ('0'+this.getDate()).slice(-2) + +' '+ ('0'+this.getHours()).slice(-2) + +':'+ ('0'+this.getMinutes()).slice(-2) + +':'+ ('0'+this.getSeconds()).slice(-2) + + (show_ms ? + ':'+(('000'+this.getMilliseconds()).slice(-3)) + : '') } + date.prototype.getTimeStamp = function(show_ms){ + return '' + + this.getFullYear() + + ('0'+this.getMonth()+1).slice(-2) + + ('0'+this.getDate()).slice(-2) + + ('0'+this.getHours()).slice(-2) + + ('0'+this.getMinutes()).slice(-2) + + ('0'+this.getSeconds()).slice(-2) + + (show_ms ? + ('000'+this.getMilliseconds()).slice(-3) + : '') } date.prototype.setTimeStamp = function(ts){ ts = ts.replace(/[^0-9]*/g, '') this.setFullYear(ts.slice(0, 4)) @@ -371,14 +363,12 @@ module.patchDate = function(date){ this.setHours(ts.slice(8, 10)) this.setMinutes(ts.slice(10, 12)) this.setSeconds(ts.slice(12, 14)) - return this - } - date.timeStamp = function(){ - return (new this()).getTimeStamp() - } + this.setMilliseconds(ts.slice(14, 17) || 0) + return this } + date.timeStamp = function(...args){ + return (new this()).getTimeStamp(...args) } date.fromTimeStamp = function(ts){ - return (new this()).setTimeStamp(ts) - } + return (new this()).setTimeStamp(ts) } // convert string time period to milliseconds... date.str2ms = function(str, dfl){ dfl = dfl || 'ms' diff --git a/ui (gen4)/ui.js b/ui (gen4)/ui.js index 59be46ae..8712714a 100755 --- a/ui (gen4)/ui.js +++ b/ui (gen4)/ui.js @@ -117,6 +117,4 @@ $(function(){ /********************************************************************** -* vim:set ts=4 sw=4 : */ -return module }) -//}) +* vim:set ts=4 sw=4 : */ return module })