Stop Logging ERROR http.log.error

1. The problem I’m having:

I am using Caddy on an IoT device and I would like to stop the ERROR http.log.error messages from printing in the logs.

2. Error messages and/or full log output:

2023-09-05T16:58:49-07:00  client  2023/09/05 23:58:49.948      ERROR   http.log.error  dial tcp 127.0.0.1:8080: connect: connection refused    {"request": {"remote_ip": "52.4.252.97", "remote_port": "62873", "proto": "HTTP/1.1", "method": "GET", "host": "578260463dd0b7f975ddbd76f9ab2d5c.balena-devices.com", "uri": "/server/socket.io/?EIO=4&transport=polling&t=OfdoDTh", "headers": {"Accept-Encoding": ["gzip, deflate"], "Referer": ["http://578260463dd0b7f975ddbd76f9ab2d5c.balena-devices.com/"], "Accept-Language": ["en-CA,en-US;q=0.9,en;q=0.8"], "User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Safari/605.1.15"], "Accept": ["*/*"], "Connection": ["keep-alive"]}}, "duration": 0.000876365, "status": 502, "err_id": "2ztwp9r2r", "err_trace": "reverseproxy.statusError (reverseproxy.go:1299)"}
2023-09-05T16:58:55-07:00  client  2023/09/05 23:58:55.225      ERROR   http.log.error  dial tcp 127.0.0.1:8080: connect: connection refused    {"request": {"remote_ip": "52.4.252.97", "remote_port": "13789", "proto": "HTTP/1.1", "method": "GET", "host": "578260463dd0b7f975ddbd76f9ab2d5c.balena-devices.com", "uri": "/server/socket.io/?EIO=4&transport=polling&t=OfdoEm0", "headers": {"Accept-Language": ["en-CA,en-US;q=0.9,en;q=0.8"], "User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Safari/605.1.15"], "Accept": ["*/*"], "Connection": ["keep-alive"], "Accept-Encoding": ["gzip, deflate"], "Referer": ["http://578260463dd0b7f975ddbd76f9ab2d5c.balena-devices.com/"]}}, "duration": 0.001385029, "status": 502, "err_id": "bpwjztqdz", "err_trace": "reverseproxy.statusError (reverseproxy.go:1299)"}

3. Caddy version:

Caddy version is v2.6.4 running in Docker.

4. How I installed and ran Caddy:

a. System environment:

Docker on Linux running on ARM, the image is arm64v8/caddy:2.6.4-alpine

b. Command:

FROM arm64v8/caddy:2.6.4-alpine
COPY --from=build-stage /app/build/ /usr/share/html
# Copy the default Caddyfile provided by build-stage
COPY --from=build-stage /app/Caddyfile /etc/caddy

c. Service/unit/compose file:

  client:
    build: "./client"
    privileged: true
    network_mode: host
    depends_on:
      - server
    volumes:
      - caddy_data:/data
      - caddy_config:/config

d. My complete Caddy config:

:80 {

  handle /* {
      root * /usr/share/html 
      file_server
      try_files {path} /index.html
    }

  handle_path /server* {
		reverse_proxy 127.0.0.1:8080
	}

  handle_path /stream-server* {
		reverse_proxy 127.0.0.1:8889
	}
}

5. Links to relevant resources:

The easiest way, but is kind of nuclear, is to set the log level to PANIC or FATAL.

But let’s go back to this:

Why do you want to do this? What is the problem?

@matt

Thanks for the quick response. As I said I am using Caddy for an IoT device and when he server is not reachable the error message fills up the logs which are streamed to servers on metered connection. So it’s mostly about removing clutter to ensure the logs are valuable.

I see… hmm. So yeah, I guess that would be the way to do it if you want a completely self-contained, natively-supported solution.

In general though I just recommend ignoring log messages you don’t care about. So whatever is ingesting the logs can drop them.

You can add this to your global options:

{
	log {
		exclude http.log.error
	}
}
1 Like

@francislavoie @matt Thank you for the help!

Francis’ solution is better! :sweat_smile:

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