-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.js
46 lines (31 loc) · 1.27 KB
/
demo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const { Logger } = require("./index.js");
// Create a parent logger
const parent = Logger.console("parent");
parent.info("Some info");
parent.error("An error!");
parent.info("Some", "delimited", "info");
// Change the log level
parent.set_log_level("warn");
parent.info("I am not printed");
parent.set_log_level("none");
parent.error("I do nothing, now");
// Better yet, just create a no-op logger from the start. Useful for unit test configurations
const no_op = Logger.noop();
// Create a child logger
const child = parent.create_child("child.1");
child.info("I am not printed, because I inherited a log level");
child.set_log_level("debug");
child.info("But now I am!");
// Change the logging format
const only_time = Logger.console("no_stamp", { format:"[:LTIME] :TYPE - :NAMESPACE | :STRING" });
only_time.info("Only the time!");
const no_timestamp = Logger.console("no_stamp", { format:":TYPE - :NAMESPACE | :STRING" });
no_timestamp.info("Simplified!");
const no_header = Logger.console("no_header", { format:null });
// But what if I hate beautiful colors?
const eye_pain = Logger.console("eye_pain", { no_colors:true });
eye_pain.warn("IT BURNS!");
// Log into a file
const file = Logger.append_file("test.log", "A");
file.info("This is in a file");
file.warn("AND SO IS THIS");