Show and save log

1. The problem I’m having:

I would like both to stream log to the stdout and save it to a log file. is there a way to make it work?

I did not find a way to do both as global directive, docker by default prints in the docker logs console of the container but I would like to save it to a file as well, if I uncomment

	log {
		output file /var/log/caddy.log
	}

log gets saved but nothing is shown

2. Error messages and/or full log output:

3. Caddy version:

v2.6.4

4. How I installed and ran Caddy:

a. System environment:

Docker, custom build with cloudflare dns and crowdsec plugin

b. Command:

c. Service/unit/compose file:

version: "3.6"
services:
  caddy-dns:
    container_name: "caddy-dns-proxy"
    image: "ghcr.io/mariomare22/caddy-dns:latest"
    networks:
      - "internet"
      - "caddy-proxy_local"
    ports:
      - "443:443/tcp"
    restart: "unless-stopped"
    volumes:
      - "/home/mario/config/caddy/caddyfile:/etc/caddy"
      - "/home/mario/config/caddy/data:/data"
      - "/home/mario/config/caddy/config:/config"
      - "/home/mario/config/caddy/log:/var/log"

d. My complete Caddy config:

{
	acme_ca https://acme-staging-v02.api.letsencrypt.org/directory
	email myemail
	# log {
	 #	output file /var/log/caddy.log
	#}
	crowdsec {
        api_url http://crowdsec:8080
        api_key mylocalapi
        ticker_interval 15s
        #disable_streaming
        #enable_hard_fails
    }
}

(cloudflare) {
	tls {
		dns cloudflare myapikey
		resolvers 1.1.1.1
	}
}

(trusted_proxy_list) {
	trusted_proxies 10.0.0.0/8 172.16.0.0/16
}

# Authelia Portal.
autheliadomain {
	import cloudflare
	reverse_proxy authelia:9091 {
		import trusted_proxy_list
	}
}

5. Links to relevant resources:

You can make multiple loggers. If you give your custom one a name, it will not override the default one.

{
	log file-log {
		output file /var/log/caddy.log
	}
}

You should configure this in global options now. Add this:

{
	servers {
		trusted_proxies static 10.0.0.0/8 172.16.0.0/16
	}
}

The advantage is that this will apply to all servers/proxies, and you can remove the { } block for reverse_proxy. In v2.7.0 there will be further benefits like automatic parsing of the client IP, the logs will contain the parsed client IP.

Hey! thanks for the reply

{
	acme_ca https://acme-staging-v02.api.letsencrypt.org/directory
	email mmyemail
	log file-log{
		output file /var/log/caddy.log
	}
	crowdsec {
        api_url http://crowdsec:8080
        api_key crowdsecapi
        ticker_interval 15s
        #disable_streaming
        #enable_hard_fails
    }
	servers {
		trusted_proxies static 10.0.0.0/8 172.16.0.0/16
	}
}

(cloudflare) {
	tls {
		dns cloudflare myapikey
		resolvers 1.1.1.1
	}
}



# Authelia Portal.
autheliamydomain {
	import cloudflare
	reverse_proxy authelia:9091
}

testdomain {
	import cloudflare
	forward_auth authelia:9091 {
		uri /api/verify?rd=https://autheliamydomain/
		copy_headers Remote-User Remote-Groups Remote-Name Remote-Email
	}
}

homeassistantdomain {
	import cloudflare
	reverse_proxy http://homeassistant:8123
}

this configuration throws an error on the first import cloudflare

What did I mess up?

If you don’t share the exact error, I can’t really help.

But you are missing a space after the logger name. Spaces are important in the Caddyfile. Otherwise, the { is considered part of the logger name.

yes that was it :smiley: thank you!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.