4 * 1.1. [Formating the logger](#Formatingthelogger)
5 * 1.2. [SUGAR vs JSON](#SUGARvsJSON)
6 * 1.3. [Loggin Verbosity](#LogginVerbosity)
9 ## 1. <a name='Logger'></a>Logger
19 my $logger = new IRCNOW::Logger(IRCNOW::Logger->INFO, IRCNOW::Logger->SUGAR);
20 #my $logger = new IRCNOW::Logger(IRCNOW::Logger->DEBUG, IRCNOW::Logger->SUGAR);
21 #my $logger = new Logger(IRCNOW::Logger->DEBUG, Logger->SUGAR, ":loglevel :timestamp :msg");
22 #my $logger = new Logger(IRCNOW::Logger->DEBUG, Logger->SUGAR, ":loglevel :invalid :timestamp :msg");
23 #my $logger = new Logger(IRCNOW::Logger->DEBUG, Logger->SUGAR, ":timestamp [:loglevel%2] :package%8 :file%10 :msg");
25 $logger->debug("debug");
26 $logger->info("info");
27 $logger->warn("warn");
28 $logger->error("error");
32 # 2023-07-02 19:22:03 [DEBUG] main test.pl:12 debug
33 # 2023-07-02 19:22:03 [INFO ] main test.pl:13 info
34 # 2023-07-02 19:22:03 [WARN ] main test.pl:14 warn
35 # 2023-07-02 19:22:03 [ERROR] main test.pl:15 error
38 Arguments are: `verbosity, printType, format`.
40 ### 1.1. <a name='Formatingthelogger'></a>Formating the logger
42 Logger has these fields:
47 * fileline (file with line number)
51 Prepend the field with a `:` and postfix the field with a `%` followed by a number. Add spaces in between.
54 `:timestamp [:loglevel%5] :package%8 :fileline%10 :msg`
56 Note: If your field value is longer than the specified length, it will print out the full value.
58 Format: `:timestamp [:loglevel%2] :package%8 :fileline%10 :msg`
61 2023-07-02 19:21:54 [DEBUG] main test.pl debug
62 2023-07-02 19:21:54 [INFO] main test.pl info
63 2023-07-02 19:21:54 [WARN] main test.pl warn
64 2023-07-02 19:21:54 [ERROR] main test.pl error
67 ### 1.2. <a name='SUGARvsJSON'></a>SUGAR vs JSON
69 There are two options to print logs:
73 JSON logging is meant for being picked up by services such as grafana or the elk stack.
74 Sugar logging is meant for human readable output to stdout.
78 { "level": "DEBUG", "msg": "debug", "package": "main", "file": "test.pl:12" }
79 { "level": "INFO", "msg": "info", "package": "main", "file": "test.pl:13" }
80 { "level": "WARN", "msg": "warn", "package": "main", "file": "test.pl:14" }
81 { "level": "ERROR", "msg": "error", "package": "main", "file": "test.pl:15" }
86 2023-07-02 19:22:03 [DEBUG] main test.pl:12 debug
87 2023-07-02 19:22:03 [INFO ] main test.pl:13 info
88 2023-07-02 19:22:03 [WARN ] main test.pl:14 warn
89 2023-07-02 19:22:03 [ERROR] main test.pl:15 error
92 ### 1.3. <a name='LogginVerbosity'></a>Logging Verbosity
94 There are verbosity levels:
97 * ERROR (backwards compatible)
99 * WARN (backwards compatible)
104 Each level is in order such that if the `INFO` level was chosen, you would see logs for `ERROR`, `WARN`, and `INFO`