Messing with log levels

1. Caddy version (caddy version):

caddy:2-alpine

2. How I run Caddy:

a. System environment:

Docker official release

b. Command:


c. Service/unit/compose file:

caddy:
    container_name: 'caddy'
    image: caddy:2-alpine 
    volumes:
      - ./caddy_server/Caddyfile:/etc/caddy/Caddyfile
      - $HOME/caddy-data:/data
      - /var/www/html:/var/www/html      
    ports:
      - "443:443"
      - "80:80"
    networks:
      - art_net
    restart: on-failure
    depends_on:
      - artserver

d. My complete Caddyfile or JSON config:

artgraficann.ru,
artgrafikann.ru,
artgrafica-nn.ru,
artgrafika-nn.ru,
artmedia-nn.ru,
artgrafica.su,
xn--52-6kclyc3bhlp2a7k.xn--p1ai,
xn----7sbban5ao7bcr0a.xn--p1ai,
xn----7sbaan5ao0aawbw3a.xn--p1ai,
xn--80aaak0am2bbqx.xn--p1ai {

    encode zstd gzip
    root * /var/www/html
	reverse_proxy /get_page artserver:8080
	reverse_proxy /order artserver:8080
	reverse_proxy /art-catalog artserver:8080
	reverse_proxy /check-og artserver:8080
	reverse_proxy /help artserver:8080
	file_server
	
	log {
	    #format json
            #level ERROR
	    level PANIC
	}
}

www.artgraficann.ru,
www.artgrafikann.ru,
www.artgrafica-nn.ru,
www.artgrafika-nn.ru,
www.artmedia-nn.ru,
www.artgrafica.su,
www.xn--52-6kclyc3bhlp2a7k.xn--p1ai,
www.xn----7sbban5ao7bcr0a.xn--p1ai,
www.xn----7sbaan5ao0aawbw3a.xn--p1ai,
www.xn--80aaak0am2bbqx.xn--p1ai {

    redir https://artgraficann.ru{uri}
	
	log {
	    #format json
            #level ERROR
	    level PANIC
	}
}

3. The problem I’m having:

After adding the log section with the level PANIC parameter, the messages with the ERROR level from the specified sites, it seemed to me, disappeared. But there were messages with the INFO level from the general system of the Caddy server. For example, caddy | {“level”: “info”, “ts”: 1625784210.9643526, “logger”: “tls”, “msg”: “cleaned up storage units”}. How do I set the log level for general messages using the Caddyfile? Or perhaps in some other way?

4. Error messages and/or full log output:


5. What I already tried:

I have already read the documentation, sorry, but it seemed to me quite messy. I have searched on this forum. I was looking for examples of config files.

6. Links to relevant resources:


The log directive only configures per-site access logs.

The global option log configures logs for everything.

Log levels are the minimum level to output. PANIC is the highest level, which means you would only see PANIC level logs with that level (which are extremely rare, and should never actually get output). Access logs only actually emit INFO and ERROR logs.

caddy|run: adapting config using caddyfile: /etc/caddy/Caddyfile:3: unrecognized global option: log

{
    email zzz@zzz
	log {
		level ERROR
	}
}

artgraficann.ru,
artgrafikann.ru,
artgrafica-nn.ru,
artgrafika-nn.ru,
artmedia-nn.ru,
artgrafica.su,
xn--52-6kclyc3bhlp2a7k.xn--p1ai,
xn----7sbban5ao7bcr0a.xn--p1ai,
xn----7sbaan5ao0aawbw3a.xn--p1ai,
xn--80aaak0am2bbqx.xn--p1ai {

    encode zstd gzip
    root * /var/www/html
	reverse_proxy /get_page artserver:8080
	reverse_proxy /order artserver:8080
	reverse_proxy /art-catalog artserver:8080
	reverse_proxy /check-og artserver:8080
	reverse_proxy /help artserver:8080
	file_server
	
	log {
		#format json
		level ERROR
		#level PANIC
	}
}

It looks like my mistake. Apparently, support for configuring global logging in Caddyfile started with some recent version and my Docker container was not updated. After completely clearing the cached images, the Caddy server started.

Thank you for the clarification. What’s the difference between PANIC and FATAL?

For next time, please run caddy version to find out the exact version you’re using. You wrote:

Which is an inexact docker image tag.

Panics are in Go are basically fail-fast exit cases where something bad happened. Somewhat similar to exceptions in other programming languages; see Go by Example: Panic. In practice, they should never happen in Caddy, because it’s supposed to be a long-running server. It would be bad if Caddy exited unexpectedly, taking your site down with it. So panics in Caddy typically don’t result in exiting. You should ideally never see any of these, unless there’s a bug in Caddy or one of its dependencies.

Fatals are more abstract, essentially a case where the program decides it needed to exit directly without bubbling up to callers, via calling log.Fatal() which logs then exits in one operation. This should also never happen in Caddy, for the same reasons.

Caddy can fail to start though (exit before the server portion actually starts), if the config is invalid or there’s some other dependent problem (storage is not writable, etc). If Caddy if already running and you push a new config, then if that new config is invalid, then Caddy will simply not switch to that new config, and keep running with the old config.

1 Like

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