Closed schenklklopfer closed 6 months ago
Hi @schenklklopfer,
In https://github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin/blob/e6b10b8ac4ec5516a232e605950f9e6317c7f4a0/pkg/logger/logger.go#L19 you have the new function which initialize the logger instance for the plugin.
logError := log.New(io.Discard, "ERROR: CrowdsecBouncerTraefikPlugin: ", log.Ldate|log.Ltime)
logInfo := log.New(io.Discard, "INFO: CrowdsecBouncerTraefikPlugin: ", log.Ldate|log.Ltime)
logDebug := log.New(io.Discard, "DEBUG: CrowdsecBouncerTraefikPlugin: ", log.Ldate|log.Ltime)
logError.SetOutput(os.Stderr)
logInfo.SetOutput(os.Stdout)
if logLevel == "DEBUG" {
logDebug.SetOutput(os.Stdout)
}
Right now, most valuable information are in Debug logs.
In that function we define 3 loggers and set their output to stdout/stderr.
So for instance, if you use the plugin and define traefik access logs and "internal" logs to files, you will still get the plugin logs in stdout/stderr.
See exemple below:
traefik:
image: "traefik:v3.0.0"
container_name: "traefik"
restart: unless-stopped
command:
- "--accesslog"
- "--accesslog.filepath=/var/log/traefik/access.log"
- "--log"
- "--log.filePath=/var/log/traefik/traefik.log"
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
- "--experimental.plugins.bouncer.modulename=github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin"
- "--experimental.plugins.bouncer.version=v1.3.0"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "logs:/var/log/traefik"
USER@HOST:~/PATH/crowdsec-bouncer-traefik-plugin$ docker exec -it traefik ls -alh /var/log/traefik
total 12K
drwxr-xr-x 2 root root 4.0K May 8 09:10 .
drwxr-xr-x 1 root root 4.0K May 8 09:10 ..
-rw-r--r-- 1 root root 2.0K May 1 06:32 access.log
-rw-r--r-- 1 root root 0 May 8 09:10 traefik.log
USER@HOST:~/PATH/crowdsec-bouncer-traefik-plugin$ docker logs traefik
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/05/08 09:10:44 IP 172.21.0.5 is trusted
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/05/08 09:10:44 getTLSConfigCrowdsec:CrowdsecLapiScheme https:no
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/05/08 09:10:44 cache:New initialized isRedis:false
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/05/08 09:10:44 New initialized mode:live
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/05/08 09:10:44 IP 172.21.0.5 is trusted
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/05/08 09:10:44 getTLSConfigCrowdsec:CrowdsecLapiScheme https:no
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/05/08 09:10:44 cache:New initialized isRedis:false
DEBUG: CrowdsecBouncerTraefikPlugin: 2024/05/08 09:10:44 New initialized mode:live
We do not support logging to a file. I hope I answered your question.
Hi, thank you very much!
So the logoutput does not follow the format settings in loki. I'd expeted to see JSON formatted logging if in Loki is logging set to JSON, like:
accessLog:
format: json
fields:
defaultMode: keep
names:
...
I couldn't see the log because I log in JSON and all lines that are not valid JSON were not visible in my logql queries. But ignoring JSON formatting allows me to see those logs in Loki/Grafana as well.
But this is okay. One just needs to know where to look at :)
Currently middleware and Traefik can't share logging options see https://github.com/traefik/traefik/issues/8204.
I have added a PR to explain it is logged in stdout/stderr in the README.
In the futur, we could add an option to log in JSON format (still in stdout).
Thank you very much!
Sorry to re-open, but where to find the logs when using traefik and crowdsec on bare metal?
Got it journalctl -u traefik
Is your feature request related to a problem? Please describe. 🐛 The README shows options for "LogLevel", like "INFO" or "DEBUG". But the README does not show where this log is located.
Describe the solution you'd like ✨ A line that says where the log is. Something like /var/log/...
Additional context I have no clue where the log is at all? Is it maybe in the "log" configured in the traefik conf like:
Or is it contained in the accessLog like:
I cannot find any line of this log at all... As stated in https://github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin/pull/134/commits/86bb79e1ae39c100c532a36e048ac3512a0e7981 I think it will be prefixed with "CrowdsecBouncerTraefikPlugin",
but I cannot find anything in my logs when I grep for it.
I am very very sorry to ask this, but I am very desperate...