summaryrefslogtreecommitdiffstats
path: root/src/js/logger.js
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/js/logger.js32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/js/logger.js b/src/js/logger.js
index 5d1114f..766188e 100644
--- a/src/js/logger.js
+++ b/src/js/logger.js
@@ -23,7 +23,7 @@
/******************************************************************************/
-import { broadcastToAll } from './broadcast.js';
+import { broadcast, broadcastToAll } from './broadcast.js';
/******************************************************************************/
@@ -47,34 +47,38 @@ const janitorTimer = vAPI.defer.create(( ) => {
broadcastToAll({ what: 'loggerDisabled' });
});
-const boxEntry = function(details) {
- if ( details.tstamp === undefined ) {
- details.tstamp = Date.now();
- }
+const boxEntry = details => {
+ details.tstamp = Date.now() / 1000 | 0;
return JSON.stringify(details);
};
+const pushOne = box => {
+ if ( writePtr !== 0 && box === buffer[writePtr-1] ) { return; }
+ if ( writePtr === buffer.length ) {
+ buffer.push(box);
+ } else {
+ buffer[writePtr] = box;
+ }
+ writePtr += 1;
+};
+
const logger = {
enabled: false,
ownerId: undefined,
- writeOne: function(details) {
+ writeOne(details) {
if ( buffer === null ) { return; }
- const box = boxEntry(details);
- if ( writePtr === buffer.length ) {
- buffer.push(box);
- } else {
- buffer[writePtr] = box;
- }
- writePtr += 1;
+ pushOne(boxEntry(details));
},
- readAll: function(ownerId) {
+ readAll(ownerId) {
this.ownerId = ownerId;
if ( buffer === null ) {
this.enabled = true;
buffer = [];
janitorTimer.on(logBufferObsoleteAfter);
+ broadcast({ what: 'loggerEnabled' });
}
const out = buffer.slice(0, writePtr);
+ buffer.fill('', 0, writePtr);
writePtr = 0;
lastReadTime = Date.now();
return out;