summaryrefslogtreecommitdiffstats
path: root/src/js/logger.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 05:50:18 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 05:50:18 +0000
commit55a5d29a66503248916f249ad2a1d8b37cde5a03 (patch)
treea3beb6a90dd3bdaaf67ecb05d42152a494aff946 /src/js/logger.js
parentAdding upstream version 1.55.0+dfsg. (diff)
downloadublock-origin-upstream/1.57.0+dfsg.tar.xz
ublock-origin-upstream/1.57.0+dfsg.zip
Adding upstream version 1.57.0+dfsg.upstream/1.57.0+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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;