2016-05-03 08:06:32 -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
|
2016-05-06 09:17:34 -04:00
|
|
|
tick() { this.tick_then(() => { }); }
|
|
|
|
tick_then(fn: () => any) { setTimeout(fn, 0); }
|
2015-11-21 14:23:40 -05:00
|
|
|
}
|