Tree


.gitignorecommits | blame
README.mdcommits | blame
lib/
parseznc.pl*commits | blame

README.md

# IRCNOW lib


## Logger

example usage:
```perl
use strict;
use warnings;

use lib qw(./lib);
use IRCNOW::Logger;

my $logger = new IRCNOW::Logger(IRCNOW::Logger->INFO, IRCNOW::Logger->SUGAR);
#my $logger = new IRCNOW::Logger(IRCNOW::Logger->DEBUG, IRCNOW::Logger->SUGAR);
#my $logger = new Logger(IRCNOW::Logger->DEBUG, Logger->SUGAR, ":loglevel :timestamp :msg");
#my $logger = new Logger(IRCNOW::Logger->DEBUG, Logger->SUGAR, ":loglevel :invalid :timestamp :msg");
#my $logger = new Logger(IRCNOW::Logger->DEBUG, Logger->SUGAR, ":timestamp [:loglevel%2] :package%8 :file%10 :msg");

$logger->debug("debug");
$logger->info("info");
$logger->warn("warn");
$logger->error("error");


# output:
# 2023-07-02 19:22:03 [DEBUG] main     test.pl:12 debug
# 2023-07-02 19:22:03 [INFO ] main     test.pl:13 info
# 2023-07-02 19:22:03 [WARN ] main     test.pl:14 warn
# 2023-07-02 19:22:03 [ERROR] main     test.pl:15 error
```

Arguments are: `verbosity, printType, format`.

### formating the logger

logger has these fields:
* timestamp
* loglevel
* package
* file
* fileline (file with line number)
* line
* msg

prepend the field with a `:` and postfix the field with a `%` followed by a number. Add spaces in between.
ex:

`:timestamp [:loglevel%5] :package%8 :fileline%10 :msg`

note: if your field value is longer than the specified length, it will print out the full value.
ex: 
format: `:timestamp [:loglevel%2] :package%8 :fileline%10 :msg` 
result:
```
2023-07-02 19:21:54 [DEBUG] main     test.pl    debug
2023-07-02 19:21:54 [INFO] main     test.pl    info
2023-07-02 19:21:54 [WARN] main     test.pl    warn
2023-07-02 19:21:54 [ERROR] main     test.pl    error
```

### sugar vs json

there are two options to print logs:
* sugar
* JSON

JSON logging is meant for being picked up by services such as grafana or the elk stack.
Sugar logging is meant for human readable output to stdout. 

example of JSON:
```
{ "level": "DEBUG", "msg": "debug", "package": "main", "file": "test.pl:12" }
{ "level": "INFO", "msg": "info", "package": "main", "file": "test.pl:13" }
{ "level": "WARN", "msg": "warn", "package": "main", "file": "test.pl:14" }
{ "level": "ERROR", "msg": "error", "package": "main", "file": "test.pl:15" }
```

example of Sugar:
```
2023-07-02 19:22:03 [DEBUG] main     test.pl:12 debug
2023-07-02 19:22:03 [INFO ] main     test.pl:13 info
2023-07-02 19:22:03 [WARN ] main     test.pl:14 warn
2023-07-02 19:22:03 [ERROR] main     test.pl:15 error
```