14 my $logger = new Logger(Logger->SUGAR, ":timestamp [:loglevel%5] :package%8 :fileline%10 :msg");
16 $logger->debug("debug");
17 $logger->info("info");
18 $logger->warn("warn");
19 $logger->error("error");
22 # 2023-07-02 19:22:03 [DEBUG] main test.pl:12 debug
23 # 2023-07-02 19:22:03 [INFO ] main test.pl:13 info
24 # 2023-07-02 19:22:03 [WARN ] main test.pl:14 warn
25 # 2023-07-02 19:22:03 [ERROR] main test.pl:15 error
28 ### formating the logger
30 logger has these fields:
35 * fileline (file with line number)
39 prepend the field with a `:` and postfix the field with a `%` followed by a number. Add spaces in between.
42 `:timestamp [:loglevel%5] :package%8 :fileline%10 :msg`
44 note: if your field value is longer than the specified length, it will print out the full value.
46 format: `:timestamp [:loglevel%2] :package%8 :fileline%10 :msg`
49 2023-07-02 19:21:54 [DEBUG] main test.pl debug
50 2023-07-02 19:21:54 [INFO] main test.pl info
51 2023-07-02 19:21:54 [WARN] main test.pl warn
52 2023-07-02 19:21:54 [ERROR] main test.pl error
57 there are two options to print logs:
61 JSON logging is meant for being picked up by services such as grafana or the elk stack.
62 Sugar logging is meant for human readable output to stdout.
66 { "level": "DEBUG", "msg": "debug", "package": "main", "file": "test.pl:12" }
67 { "level": "INFO", "msg": "info", "package": "main", "file": "test.pl:13" }
68 { "level": "WARN", "msg": "warn", "package": "main", "file": "test.pl:14" }
69 { "level": "ERROR", "msg": "error", "package": "main", "file": "test.pl:15" }
74 2023-07-02 19:22:03 [DEBUG] main test.pl:12 debug
75 2023-07-02 19:22:03 [INFO ] main test.pl:13 info
76 2023-07-02 19:22:03 [WARN ] main test.pl:14 warn
77 2023-07-02 19:22:03 [ERROR] main test.pl:15 error