V2: Log to file doesnt seem to work on Windows

1. My Caddy version (caddy version):

2 rc1

2. How I run Caddy:

caddy run

a. System environment:

Windows 10

d. My complete Caddyfile or JSON config:

:2015

respond "Hello from Toby this has reloaded with info about logginf"

log  {
 output file d:/caddytrial/access.log
}

I have tried path with / \ and \\ none work

3. The problem I’m having:

I reload my server with the config above but my log keeps getting written to stdout. There is no file called access.log created in the directory.

4. Error messages and/or full log output:

This is written to stdout but no file.

2020/04/05 16:02:38.519 e[34mINFOe[0m http.log.access handled request {“request”: {“method”: “GET”, “uri”: “/favicon.ico”, “proto”: “HTTP/1.1”, “remote_addr”: “[::1]:52126”, “host”: “localhost:2015”, “headers”: {“Sec-Fetch-Mode”: [“no-cors”], “User-Agent”: [“Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36”], “Sec-Fetch-Dest”: [“image”], “Accept”: [“image/webp,image/apng,image/,/*;q=0.8”], “Sec-Fetch-Site”: [“same-origin”], “Connection”: [“keep-alive”], “Pragma”: [“no-cache”], “Cache-Control”: [“no-cache”], “Referer”: [“http://localhost:2015/?sdfglksdjfg”], “Accept-Encoding”: [“gzip, deflate, br”], “Accept-Language”: [“en-US,en;q=0.9”]}}, “common_log”: “::1 - - [05/Apr/2020:17:02:38 +0100] “GET /favicon.ico HTTP/1.1” 200 57”, “latency”: 0, “size”: 57, “status”: 200, “resp_headers”: {“Server”: [“Caddy”], “Content-Type”: []}}

5. What I already tried:

6. Links to relevant resources:

Just giving this a little nudge up the show. Anyone have any idea what the issue is here?

I’d have to spin up a Windows VM on AWS to try the different scenarios, but can you try configs on the JSON level? Here’s something that works for me (different file name though because I’m on Mac):

{
	"logging": {
		"logs": {
			"default": {
				"writer": {
					"filename": "d:/caddytrial/access.log",
					"output": "file"
				}
			}
		}
	},
	"apps": {
		"http": {
			"servers": {
				"srv0": {
					"listen": [
						":2015"
					],
					"routes": [
						{
							"handle": [
								{
									"handler": "static_response",
									"status_code": "200",
									"body": "Hello from Toby this has reloaded with info about logging"
								}
							],
							"terminal": true
						}
					],
					"logs": {
						"logger_names": {
							"localhost": "default"
						}
					}
				}
			}
		}
	}
}

1 Like

Thanks, that worked.

I have provided here the caddyfile and the conversion to json which doesnt work, it might give some clues as to what is going on

:2015

respond "Hello from Toby this has reloaded with info about loggin CADDYFILE C"

log  {
 output file "d:/caddytrial/accessC.log"
}

{
  "logging": {
    "logs": {
      "log0": {
        "writer": {
          "filename": "d:/caddytrial/accessC.log",
          "output": "file"
        },
        "include": [
          "http.log.access.log0"
        ]
      }
    }
  },
  "apps": {
    "http": {
      "servers": {
        "srv0": {
          "listen": [
            ":2015"
          ],
          "routes": [
            {
              "handle": [
                {
                  "body": "Hello from Toby this has reloaded with info about loggin CADDYFILE C",
                  "handler": "static_response"
                }
              ]
            }
          ],
          "logs": {
            "logger_names": {
              ":2015": "log0"
            }
          }
        }
      }
    }
  }
}

Seems like the only difference is the logger named “default” which is a catch-all. But IMO what you wrote should work… seems like a bug @matt

Toby, can you try with the latest on master? I seem to remember pushing a fix for loggers recently.

Build artifacts here: basicauth: Re-prompt after invalid credentials (fix #3239) (#3240) · caddyserver/caddy@fbd9515 · GitHub

I think this was the commit you’re thinking of @matt ?

https://github.com/caddyserver/caddy/commit/3d6fc1e1b7f41ebbd0c7cb48280ce1a14a56f4d5

I think that was it, yes. Might not have anything to do with it, but just a thought.

This is what I was trying to validate :slight_smile: @matt, that change works for me while rc1 doesn’t, just as Toby reports.

2 Likes

Spent a few hours on this and a couple other edge cases I discovered. This should work then: httpcaddyfile, caddytls: Multiple edge case fixes; add tests · caddyserver/caddy@28fdf64 · GitHub - please try it out!

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