How can I view event logs or configure caddy to log to a file?

I just got started with caddy and specifically, caddy v2. I am very happy with the project. I did my configuration by sending JSON config to the /load/ endpoint and everything is working as expected.

What I currently need is a way to handle logs. The documentation doesn’t have much on this and I hope to find someone here who could help.
My current JSON config:

{
	"apps":
	{
		"http":
		{
			"servers":
			{
				"srv0":
				{
					"listen": [":443"],
					"routes": [
					{
						"handle": [
						{
							"handler": "subroute",
							"routes": [
							{
								"handle": [
								{
									"handler": "headers",
									"response":
									{
										"deferred": true,
										"set":
										{
											"Content-Security-Policy": ["default-src * data:; referrer origin"],
											"Expect-Ct": ["max-age=604800, enforce"],
											"Feature-Policy": ["geolocation 'self'; microphone 'self'; camera 'self'"],
											"Referrer-Policy": ["strict-origin"],
											"Server": ["Coinp"],
											"Strict-Transport-Security": ["max-age=31536000;"],
											"X-Content-Type-Options": ["nosniff"],
											"X-Download-Options": ["noopen"],
											"X-Frame-Options": ["DENY"],
											"X-Powered-By": ["-"],
											"X-Xss-Protection": ["1; mode=block"]
										}
									}
								}]
							},
							{
								"handle": [
								{
									"handler": "reverse_proxy",
									"upstreams": [
									{
										"dial": "localhost:8000"
									}]
								}],
								"match": [
								{
									"path": ["/"]
								}]
							}]
						}],
						"match": [
						{
							"host": ["hostURL1"]
						}]
					},
					{
						"handle": [
						{
							"handler": "subroute",
							"routes": [
							{
								"handle": [
								{
									"handler": "headers",
									"response":
									{
										"set":
										{
											"X-Forwarded-Proto": ["https"]
										}
									}
								}]
							},
							{
								"handle": [
								{
									"handler": "reverse_proxy",
									"upstreams": [
									{
										"dial": "localhost:8080"
									}]
								}],
								"match": [
								{
									"path": ["/*"]
								}]
							}]
						}],
						"match": [
						{
							"host": ["hostURL2"]
						}]
					}]
				}
			}
		}
	}
}

Take a look at Logging doesn't work in 2.0 beta 13? - #6 by francislavoie

4 Likes

Thanks so much, @seaerkin. I have been able to log to a file after following the discussion on the link you shared.

1 Like

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