Logging multiple vhosts to central log file?

I’m looking into migrating a nginx server with several subdomains to caddy.

Most of my current setup is simple enough to do this in a straightforward manner, but I’m a bit stuck on the log directive.
As far as I understand it is possible to use multiple log entries per vhost, at least I found a resolved issue regarding that exact problem. What I don’t know is if it is possible to have several log directives pointing to the same logfile.

My intention is something similar to:

sub1.example.com {
    root /srv/www/sub1site/

    log /var/log/caddy/sub1/access.log
    log /var/log/caddy/everything.log
    errors /var/log/caddy/sub1/errors.log
    errors /var/log/caddy/allerrors.log

sub2.example.com {
    root /srv/www/sub2site/

    log /var/log/caddy/sub2/access.log
    log /var/log/caddy/everything.log
    errors /var/log/caddy/sub2/errors.log
    errors /var/log/caddy/allerrors.log

This brings up several questions:

  • Is this permissible?
  • Will the vhosts step on each other’s toes while trying to write to the log?
  • How would I handle rotation of the central log?

Yes you can.

That’s not quite helpful. :slight_smile: Sure, i can point them all at the same file. But can I do that without destroying data?

And there’s still the log rotation issue.

Yes it is permissible.
Yes, with the latest build the log code will work quite happily with multiple hosts all writing to the same logfile.

You can setup log rotation as per the docs in each of the log blocks. For the shared log you should only have to specify the rotation details once.

1 Like

Great, that’s exactly what I wanted to know. Thank you.

(I had a suspicion/hope that it would work this way, but since I’m new to caddy I prefer to make sure before I trash a lot of data.)

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