samuong / alpaca

A local HTTP proxy for command-line tools. Supports PAC scripts and NTLM authentication.
Apache License 2.0
184 stars 31 forks source link

Where should we store logs by default? #71

Closed akumria closed 1 year ago

akumria commented 2 years ago

Working out the best place to store logs is complicated.

If the user is running the program, from the console, I suspect that the right place is stdout / stderr (as appropriate).

If, however, they are running it in a "detached" (background, daemon) mode with no associated console (or via some agent), a more reasonable default would seem to be $XDG_STATE_HOME (see: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html).

samuong commented 2 years ago

I think what you're saying is fine, but I'm not sure what changes we would need to make to the code in this repo. Is there a specific change you want made to the alpaca binary itself? Or are you talking about the launchd agent (or systemd unit, or other startup script) that launches it?

This code in this repo just starts a proxy server process and writes some output to stdout/err. It's really up to the packager (e.g. for the homebrew formula, rpm/deb package) to decide how to daemonise that process, and capture (and possibly rotate) the logs. This needs to be left to the packagers because a lot of the conventions are platform-specific.

For macOS, there's a launchd agent in the homebrew formula. I don't know much about launchd and when I originally wrote the formula I wasn't able to figure out how to get launchd to expand variables like $XDG_STATE_HOME or even $HOME, so I just pointed the output at /dev/null. Happy to accept a pull request to fix that in https://github.com/samuong/homebrew-alpaca from anyone that knows how.

marcelocantos commented 2 years ago

Based on github.com/Homebrew/brew/…/service_spec.rb, perhaps you could log to #{HOMEBREW_PREFIX}/var/log/alpaca.log. I don't know how (or whether) HOMEBREW_PREFIX is populated, however.

samuong commented 1 year ago

I've updated the homebrew formula so that it sends logs to var/log/alpaca.log, under the homebrew prefix. So on my Macbook, this is /opt/homebrew/var/log/alpaca.log. It's up to other package maintainers to decide how they want to configure the log file location, but this is the default for homebrew users.