Index

lognestmonster / 9f3fa60

A general-purpose single-header C logging library and parser for event-based logs. (Incomplete)

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
3325 Dec 2018 23:56aad9bcbUpdate queue.jsJoshua1208N

Blob @ lognestmonster / src / queue.js

application/javascript1268 bytesdownload raw
1const statement = require("./statement.js");
2const event = require("./event.js");
3
4const FileHandler = require("./fileHandler.js");
5
6class Queue {
7 constructor(name, location) {
8 this.name = name;
9 this.timestamp = new Date();
10 this.location = location;
11 this.filename = this.location + "/" + this.timestamp.toISOString().replace(/\:/g, "-").replace(/\./g, "-") + ".log";
12 this.queue = [];
13
14 FileHandler.AppendFile(this.filename, "");
15
16 return this;
17 }
18
19 push() {
20 if (arguments.length >= 3) this.queue.push(new statement(arguments[0], arguments[1], arguments[2]));
21 else if (arguments.length > 0) {
22 if (arguments[0] instanceof event) this.queue.push(arguments[0].statements); // object is an Event
23 else if (arguments[0] instanceof statement) this.queue.push(arguments[0]); // object is a Statement
24 else throw new TypeError("Expected an Event or Statement");
25 } else throw new Error("Expeted at least one argument");
26 return this;
27 }
28
29 write() {
30 let queueLength = this.queue.length;
31 let appendString = ""
32 this.queue.forEach(function (item) {
33 appendString += JSON.stringify(item) + "\n";
34 });
35 this.queue = this.queue.slice(queueLength);
36 FileHandler.AppendFile(this.filename, appendString);
37 return this;
38 }
39}
40
41module.exports = Queue;
42