Index

lognestmonster / 4e8c05e

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

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
1425 Dec 2018 19:590d5c4e7Update index.jsJoshua11100N

Blob @ lognestmonster / index.js

application/javascript3666 bytesdownload raw
1const Logger = {
2 Logger: require("./src/logger.js"),
3 Event: require("./src/event.js"),
4 Statement: require("./src/statement.js"),
5 Queue: require("./src/queue.js")
6}
7
8
9var MyLogger = new Logger.Logger({
10 name: "MyLogger", // This serves no use in the creation of log files, it's just identification for the program
11 locations: { // The names of locations and their corresponding log directories
12 "node": "./log/node",
13 "http": "./log/http"
14 },
15});
16
17let NodeLogQueue = MyLogger.queue("node"); // selects the "node" location log queue
18
19let LoadEvent = new Logger.Event(); // creates a new Event, a nest for Statements
20
21// Statement objects contain [timestamp, verbosity, tag, message] variables and are the containers for all data
22
23// Queue.push(statement);
24// Queue.push(verbosity, tag, message); - implicitly creates a Statement object
25// Queue.push(event); - in this case, the Queue object pushes the `event.statements` table
26NodeLogQueue.push(LoadEvent); // This places LoadEvent at the front of the to-write-to-node-log queue.
27// Note in most scenarios you would want to empty the queue as soon as it's populated, so waiting until
28// the event is written before emptying isn't wise. In this case, because NodeLogQueue has an event
29// pushed to it before the event is finished, the event could be prematurely processed by another
30// synchronous `.write()` call to the queue object. This demonstration is only okay because there is
31// only one `.write()` call to the queue object, which is after the Event object is written.
32
33
34// Although not used here, the Statement object is created with the same parameters used below (verbosity, tag, message)
35// Event.push(verbosity, tag, message); - implicitly creates a Statement object
36// Event.push(event); - in this case, the Event object pushes the `event.statements` table
37
38LoadEvent.push("INFO", "INIT", "Acquiring needed top-level packages.");
39
40
41let LowerNestedEvent = new Logger.Event();
42
43LowerNestedEvent.push("INFO", "INIT", "Loading fs...");
44LowerNestedEvent.push("DEBUG", "INIT", "fs loaded."); // Verbosity levels and tags are still available for result filtering
45
46LowerNestedEvent.push("INFO", "INIT", "Loading http...");
47LowerNestedEvent.push("DEBUG", "INIT", "http loaded.");
48
49LowerNestedEvent.push("INFO", "INIT", "Loading jsonwebtoken...");
50LowerNestedEvent.push("DEBUG", "INIT", "jsonwebtoken loaded.");
51
52LowerNestedEvent.push("INFO", "INIT", "Loading lognestmonster...");
53LowerNestedEvent.push("DEBUG", "INIT", "lognestmonster loaded.");
54
55
56
57LoadEvent.push(LowerNestedEvent);
58LoadEvent.push("INFO", "INIT", "Finished.");
59
60NodeLogQueue.write(); // Makes the queue append all to file and empty itself
61
62/*
63
64A possible parsing system may look like this:
65
66-------------------------------------------------------------------------------------
67
68
69[[NAME]]
70[[TIMESTAMP]]
71[[LOG FILESIZE]]
72[[LOG ITEM COUNT]]
73> 3 ITEMS
74
75
76-------------------------------------------------------------------------------------
77
78
79[[NAME]]
80[[TIMESTAMP]]
81[[LOG FILESIZE]]
82[[LOG ITEM COUNT]]
83v 3 ITEMS
84 TIMESTAMP - INFO - INIT - Acquiring needed top-level packages.
85 > 4 ITEMS
86 TIMESTAMP - INFO - INIT - Finished.
87
88
89-------------------------------------------------------------------------------------
90
91
92[[NAME]]
93[[TIMESTAMP]]
94[[LOG FILESIZE]]
95[[LOG ITEM COUNT]]
96v 3 ITEMS
97 TIMESTAMP - INFO - INIT - Acquiring needed top-level packages.
98 v 4 ITEMS
99 TIMESTAMP - INFO - INIT - Loading fs...
100 TIMESTAMP - INFO - INIT - Loading http...
101 TIMESTAMP - INFO - INIT - Loading jsonwebtoken...
102 TIMESTAMP - INFO - INIT - Loading lognestmonster...
103 TIMESTAMP - INFO - INIT - Finished.
104
105
106*/
107
108
109console.log(JSON.stringify(LoadEvent.statements));
110
111