Monviech / os-caddy-plugin

Caddy Plugin with GUI for OPNsense
Other
38 stars 0 forks source link

Changing logging view to use /ui/diagnostics #35

Closed Monviech closed 8 months ago

Monviech commented 9 months ago

I have implemented my own logging solution, but talking with AdSchellevis (thanks a lot by the way) revealed that you can also use the core diagnostic utilities by using the inherited diagnostics log.volt view. It seems like that it can use the caddy.log file, and only needs an own parser to get the log file in line with what is expected.

Link example: /ui/diagnostics/log/core/caddy

TODO:

Monviech commented 9 months ago

I don't think I will change this anytime soon since it involves the same effort as my already working solution. If my current solution breaks in the future (unlikely since it builds upon configd and api actions) I will reconsider this.

Monviech commented 8 months ago

Since Caddy supports the log output net to unixgram I can reopen this and start on refactoring the logging.

log {
        output net unixgram//var/run/logpriv
}
Monviech commented 8 months ago

I need help with this. I already tried some things like parsing/filtering with syslog-ng, using the "format transform" of caddy. But they all failed in some way. It's taking a considerable amount of time and right now I ponder if it's even worth it. There's so many stones in the way for me.

Right now, the custom GUI log works just fine, even though it's not integrated into syslog-ng.

Monviech commented 8 months ago

I came further, using a custom syslog-ng parser, combined with the caddy format-transform encoder, I could format the log output of caddy to the expected format of syslog ng. Now a log can be displayed in /ui/diagnostics/log/core/caddy. I'm working on displying the most important message keys, and then will refactor the logging.

CaddyLog

Monviech commented 8 months ago

I won't use the caddy transform module. I will use a custom socket for caddy. Here is an example working configuration for syslog-ng:

# Define Unix socket source for Caddy
source s_caddy {
    unix-dgram("/var/caddy/var/run/log");
};

# Parser for Caddy log levels
parser p_caddy_levels {
    channel {
        filter {
            message(".*debug.*") or
            message(".*info.*") or
            message(".*warn.*") or
            message(".*error.*") or
            message(".*panic.*") or
            message(".*fatal.*");
        };
        rewrite {
            set-severity("7" condition(message(".*debug.*")));  # DEBUG -> Debug
            set-severity("6" condition(message(".*info.*")));   # INFO -> Informational
            set-severity("4" condition(message(".*warn.*")));   # WARN -> Warning
            set-severity("3" condition(message(".*error.*")));  # ERROR -> Error
            set-severity("2" condition(message(".*panic.*")));  # PANIC -> Critical
            set-severity("1" condition(message(".*fatal.*")));  # FATAL -> Alert
        };
    };
};

# Destination for Caddy logs
destination d_local_caddy {
    file(
        "/var/log/caddy/caddy_${YEAR}${MONTH}${DAY}.log"
        create-dirs(yes)
        flags(syslog-protocol)
    );
};

# Log path for processing Caddy logs
log {
    source(s_caddy);
    parser(p_caddy_levels);
    rewrite { set("caddy" value("PROGRAM")); };
    destination(d_local_caddy);
};