Truncate logs for caddy

Hi,

I have a esi version of caddy running and i have seen that the logs have grown quite large in size.
I was wondering if i can truncate the logs with the following command or if it will cause caddy to crash.

" > esi-prod_debug.log"

The log in question looks as follows
3.0G esi-prod_debug.log

You might want to look into the log rotate_keep rotate_size rotate_age configuration if you are worried about log sizes.
https://caddyserver.com/docs/log

4 Likes

Will this truncate and remove old logs as well?

I believe it will roll out existing logs immediately if they exceed the age or size limits you specify.

It shouldn’t remove those old logs until they exceed the maximum keep limit.

I have tried adding in the rotate as follows

log / /opt/caddy/logs/esi-prod_debug.log {
rotate_size 10 # 10 MB
rotate_age 31 # 31 days
rotate_keep 10 # keep 10 files
}
but then it follows with the following :

May 09 09:05:48 [29575]: 2019/05/09 09:05:48 /etc/caddy/Caddyfile:60 - Error during parsing: Unknown directive ‘rotate_size’
May 09 09:05:48 systemd[1]: caddy.service: Main process exited, code=exited, status=1/FAILURE
May 09 09:05:48 systemd[1]: caddy.service: Unit entered failed state.

is appending the file a option with the following command

" > esi-prod_debug.log"

I checked the rest of the rotates in caddy file are exactly the same but they seem to be working.

The top line in your Caddyfile must always be the address of the site you want to serve.

log is a directive that needs to be inside a site definition.

Thanks for all the help guys.
The solution has worked.

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