bugfix, reworked timestamps and minor tweaks

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-04-11 01:09:49 +03:00
parent ddfdb66206
commit fed5f32723
4 changed files with 51 additions and 48 deletions

View File

@ -274,11 +274,15 @@ var LoggerActions = actions.Actions({
this.log this.log
&& this.log.splice(0, this.log.length) && this.log.splice(0, this.log.length)
return this }, return this },
print: function(){ print: function(to_console){
return this.log ? to_console = to_console === undefined ?
true
: to_console
var str = this.log ?
this.log this.log
.map(function([path, status, rest]){ .map(function([date, path, status, rest]){
return path.join(': ') + (path.length > 0 ? ': ' : '') return `[${ new Date(date).getTimeStamp(true) }] `
+ path.join(': ') + (path.length > 0 ? ': ' : '')
+ status + status
+ (rest.length > 1 ? + (rest.length > 1 ?
':\n\t' ':\n\t'
@ -287,7 +291,10 @@ var LoggerActions = actions.Actions({
: '') : '')
+ rest.join(': ') }) + rest.join(': ') })
.join('\n') .join('\n')
: '' }, : ''
return to_console ?
(console.log(str), this)
: str },
// main API... // main API...
@ -313,10 +320,13 @@ var LoggerActions = actions.Actions({
emit: function(status, ...rest){ emit: function(status, ...rest){
// write to log... // write to log...
this.log !== false this.log !== false
&& this.log.push([this.path, status, rest]) && this.log.push([
Date.now(),
this.path,
status,
rest])
// maintain log size... // maintain log size...
this.log !== false this.log !== false
&& this.log.push([this.path, status, rest])
&& (this.max_size > 0 && (this.max_size > 0
&& this.log.length > this.max_size && this.log.length > this.max_size
&& this.log.splice(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: '', doc: '',
tag: 'lifecycle', tag: 'lifecycle',
suggested: [
'logger',
],
priority: 'high', priority: 'high',
actions: LifeCycleActions, actions: LifeCycleActions,
@ -2289,6 +2302,9 @@ module.SelfTest = ImageGridFeatures.Feature({
depends: [ depends: [
'lifecycle' 'lifecycle'
], ],
suggested: [
'logger',
],
priority: 'low', priority: 'low',
actions: SelfTestActions, actions: SelfTestActions,

View File

@ -25,7 +25,6 @@ core.ImageGridFeatures.Feature('imagegrid-commandline', [
core.ImageGridFeatures.Feature('imagegrid-minimal', [ core.ImageGridFeatures.Feature('imagegrid-minimal', [
'lifecycle', 'lifecycle',
'logger', // XXX
'alias', 'alias',
'peer', 'peer',
'fs', 'fs',

View File

@ -333,36 +333,28 @@ var patchDate =
module.patchDate = function(date){ module.patchDate = function(date){
date = date || Date date = date || Date
date.prototype.toShortDate = function(){ date.prototype.toShortDate = function(show_ms){
var y = this.getFullYear() return ''
var M = this.getMonth()+1 + this.getFullYear()
M = M < 10 ? '0'+M : M +'-'+ ('0'+this.getMonth()+1).slice(-2)
var D = this.getDate() +'-'+ ('0'+this.getDate()).slice(-2)
D = D < 10 ? '0'+D : D +' '+ ('0'+this.getHours()).slice(-2)
var H = this.getHours() +':'+ ('0'+this.getMinutes()).slice(-2)
H = H < 10 ? '0'+H : H +':'+ ('0'+this.getSeconds()).slice(-2)
var m = this.getMinutes() + (show_ms ?
m = m < 10 ? '0'+m : m ':'+(('000'+this.getMilliseconds()).slice(-3))
var s = this.getSeconds() : '') }
s = s < 10 ? '0'+s : s date.prototype.getTimeStamp = function(show_ms){
return ''
return ''+y+'-'+M+'-'+D+' '+H+':'+m+':'+s + this.getFullYear()
} + ('0'+this.getMonth()+1).slice(-2)
date.prototype.getTimeStamp = function(no_seconds){ + ('0'+this.getDate()).slice(-2)
var y = this.getFullYear() + ('0'+this.getHours()).slice(-2)
var M = this.getMonth()+1 + ('0'+this.getMinutes()).slice(-2)
M = M < 10 ? '0'+M : M + ('0'+this.getSeconds()).slice(-2)
var D = this.getDate() + (show_ms ?
D = D < 10 ? '0'+D : D ('000'+this.getMilliseconds()).slice(-3)
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.setTimeStamp = function(ts){ date.prototype.setTimeStamp = function(ts){
ts = ts.replace(/[^0-9]*/g, '') ts = ts.replace(/[^0-9]*/g, '')
this.setFullYear(ts.slice(0, 4)) this.setFullYear(ts.slice(0, 4))
@ -371,14 +363,12 @@ module.patchDate = function(date){
this.setHours(ts.slice(8, 10)) this.setHours(ts.slice(8, 10))
this.setMinutes(ts.slice(10, 12)) this.setMinutes(ts.slice(10, 12))
this.setSeconds(ts.slice(12, 14)) this.setSeconds(ts.slice(12, 14))
return this this.setMilliseconds(ts.slice(14, 17) || 0)
} return this }
date.timeStamp = function(){ date.timeStamp = function(...args){
return (new this()).getTimeStamp() return (new this()).getTimeStamp(...args) }
}
date.fromTimeStamp = function(ts){ date.fromTimeStamp = function(ts){
return (new this()).setTimeStamp(ts) return (new this()).setTimeStamp(ts) }
}
// convert string time period to milliseconds... // convert string time period to milliseconds...
date.str2ms = function(str, dfl){ date.str2ms = function(str, dfl){
dfl = dfl || 'ms' dfl = dfl || 'ms'

View File

@ -117,6 +117,4 @@ $(function(){
/********************************************************************** /**********************************************************************
* vim:set ts=4 sw=4 : */ * vim:set ts=4 sw=4 : */ return module })
return module })
//})