caddyserver / caddy

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
https://caddyserver.com
Apache License 2.0
55.72k stars 3.92k forks source link

more humanreadable outputs? #3368

Closed My1 closed 4 years ago

My1 commented 4 years ago

wouldn't it be nice if the messages would be easy to read by humans (like in caddy 1)?

compare this

C:\caddy>caddy2.exe run --adapter caddyfile -config="caddy2conf.txt"
2020/05/07 08:17:45.965 ←[34mINFO←[0m   using provided configuration    {"config
_file": "caddy2conf.txt", "config_adapter": "caddyfile"}
2020/05/07 08:17:45.971 ←[34mINFO←[0m   admin   admin endpoint started  {"addres
s": "tcp/localhost:2019", "enforce_origin": false, "origins": ["localhost:2019",
 "[::1]:2019", "127.0.0.1:2019"]}
2020/05/07 10:17:45 [INFO][cache:0xc000534f00] Started certificate maintenance r
outine
2020/05/07 10:17:45 [WARNING] Stapling OCSP: no OCSP stapling for [localhost]: no OCSP server specified in certificate
2020/05/07 08:17:45.993 ←[34mINFO←[0m   http    skipping automatic certificate m
anagement because one or more matching certificates are already loaded  {"domain
": "localhost", "server_name": "srv0"}
2020/05/07 08:17:45.993 ←[34mINFO←[0m   http    enabling automatic HTTP->HTTPS r
edirects        {"server_name": "srv0"}
2020/05/07 08:17:45.993 ←[34mINFO←[0m   http    server is listening only on the
HTTP port, so no automatic HTTPS will be applied to this server {"server_name":
"srv1", "http_port": 80}
2020/05/07 08:17:45.994 ←[33mWARN←[0m   http    user server is listening on same
 interface as automatic HTTP->HTTPS redirects; user-configured routes might over
ride these redirects    {"server_name": "srv1", "interface": "tcp/:80"}
2020/05/07 08:17:45.996 ←[34mINFO←[0m   tls     cleaned up storage units
2020/05/07 08:17:45.998 ←[34mINFO←[0m   autosaved config        {"file": "C:\\Us
ers\\My1\\AppData\\Roaming\\Caddy\\autosave.json"}
2020/05/07 08:17:45.998 ←[34mINFO←[0m   serving initial configuration

to this

C:\caddy>caddy1 -conf="caddyconf.txt"
Activating privacy features... done.

Serving HTTPS on port 443
https://localhost

Serving HTTP on port 80
http://localhost
http://127.0.0.1

like what is that "←[33m" and so on about? also at least for dev where I dont leave caddy running for days or even years at a time I could live with Hours minutes and seconds only.

by changing 2020/05/07 08:17:45.996 ←[34mINFO←[0m to 08:17:45 INFO it becomes a lot easier to read, also using linebreaks at the right time may help.

This is with caddy2.0 on windows 8.1.

francislavoie commented 4 years ago

This is because your terminal doesn't support coloured output.

I would suggest you use https://github.com/microsoft/terminal which is the new terminal from Microsoft, but I think it's only available for Windows 10.

There might be a way for Caddy to detect if a terminal does not have colour support and skip printing those characters, but I'm not certain.

Edit: we could possibly use https://github.com/efekarakus/termcolor

mohammed90 commented 4 years ago

The colors come from uber-go/zap.

https://github.com/caddyserver/caddy/blob/6e4132eb89ccf399c97c9439f6f9ff9fcac21956/logging.go#L679

I assume customizing it will require a wrapper writer/encoder? @mholt would know for sure. He dove deep into zap.

mholt commented 4 years ago

You can customize the log output: https://caddyserver.com/docs/json/logging/

You'll want to choose an encoder that you like, and customize it (or write a new one).