Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2: log not writing to file #3185

Closed
wille-io opened this issue Mar 24, 2020 · 2 comments
Closed

v2: log not writing to file #3185

wille-io opened this issue Mar 24, 2020 · 2 comments
Labels
bug 🐞 Something isn't working

Comments

@wille-io
Copy link

wille-io commented Mar 24, 2020

I hope I just don't get my head wrapped around v2 or the documentation is incomplete, but:
Telling caddy to write logs to a file does not create a file but logs to stdout.

I used caddy2_beta19_linux_amd64 from the releases page.

Caddyfile:

:8000 {
  root .
  log {
    output file /home/wille/test.log
  }
}

Started with: caddy2_beta19_linux_amd64 run

The resulting json, curled from /config/:

{
  "apps": {
    "http": {
      "servers": {
        "srv0": {
          "listen": [
            ":8000"
          ],
          "logs": {},
          "routes": [
            {
              "handle": [
                {
                  "handler": "vars",
                  "root": "."
                }
              ]
            }
          ]
        }
      }
    }
  },
  "logging": {
    "logs": {
      "log0": {
        "include": [
          "http.log.access.log0"
        ],
        "writer": {
          "filename": "/home/wille/test.log",
          "output": "file"
        }
      }
    }
  }
}

Visiting 127.0.0.1:8000 generates a log entry on the console:

2020/03/24 10:19:47.236	INFO	http.log.access	handled request	{"request": {"method": "GET", "uri": "/", "proto": "HTTP/1.1", "remote_addr": "127.0.0.1:56772", "host": "127.0.0.1:8000", "headers": {"Upgrade-Insecure-Requests": ["1"], "User-Agent": ["Mozilla/5.0 (X11; Fedora; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"], "Sec-Fetch-User": ["?1"], "Sec-Fetch-Site": ["none"], "Sec-Fetch-Mode": ["navigate"], "Accept-Encoding": ["gzip, deflate, br"], "Connection": ["keep-alive"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"], "Accept-Language": ["de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7"], "If-None-Match": ["\"11cf90bd0f803f7ad36230bcab3bf14a\""], "If-Modified-Since": ["Sun, 15 Mar 2020 20:36:50 GMT"]}}, "common_log": "127.0.0.1 - - [24/Mar/2020:11:19:47 +0100] \"GET / HTTP/1.1\" 0 0", "latency": 0.000013899, "size": 0, "status": 0, "resp_headers": {"Server": ["Caddy"]}}

But:
tail -f /home/wille/test.log
tail: cannot open '/home/wille/test.log' for reading: No such file or directory

Did I miss something?

@mholt
Copy link
Member

mholt commented Mar 24, 2020

Oh... yeah, this is because the site block doesn't have a hostname, only a port. So it can't map any particular host to a particular log. Let me see what can be done about this. Thanks for the report.

@mholt mholt added the bug 🐞 Something isn't working label Mar 24, 2020
@mholt mholt added this to the v2.0.0-beta.20 milestone Mar 24, 2020
@mholt mholt closed this as completed in 2acb208 Mar 24, 2020
@mholt
Copy link
Member

mholt commented Mar 24, 2020

Okie, I changed it so that it will register a logger name mapping for "" in the case of no hostname, as a kind of "default" log for that server. Should work now. I'm gonna tag beta 20.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants