2016-04-27 14:28:22 -04:00
|
|
|
import {Injectable} from '@angular/core';
|
2015-11-21 14:23:40 -05:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class LoggerService {
|
2016-04-27 14:28:22 -04:00
|
|
|
logs: string[] = [];
|
2016-01-23 13:21:09 -05:00
|
|
|
prevMsg = '';
|
|
|
|
prevMsgCount = 1;
|
2015-11-21 14:23:40 -05:00
|
|
|
|
2016-04-27 14:28:22 -04:00
|
|
|
log(msg: string) {
|
2016-01-23 13:21:09 -05:00
|
|
|
if (msg === this.prevMsg) {
|
|
|
|
// Repeat message; update last log entry with count.
|
2016-04-27 14:28:22 -04:00
|
|
|
this.logs[this.logs.length - 1] = msg + ` (${this.prevMsgCount += 1}x)`;
|
2016-01-23 13:21:09 -05:00
|
|
|
} else {
|
|
|
|
// New message; log it.
|
|
|
|
this.prevMsg = msg;
|
|
|
|
this.prevMsgCount = 1;
|
|
|
|
this.logs.push(msg);
|
|
|
|
}
|
2015-11-21 14:23:40 -05:00
|
|
|
}
|
|
|
|
|
2016-04-27 14:28:22 -04:00
|
|
|
clear() { this.logs.length = 0; }
|
2015-11-21 14:23:40 -05:00
|
|
|
|
2016-01-23 13:21:09 -05:00
|
|
|
// schedules a view refresh to ensure display catches up
|
2015-11-21 14:23:40 -05:00
|
|
|
tick() {
|
|
|
|
setTimeout(() => {
|
|
|
|
// console.log('tick')
|
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
}
|