alpaca icon indicating copy to clipboard operation
alpaca copied to clipboard

Where should we store logs by default?

Open akumria opened this issue 3 years ago • 2 comments

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).

akumria avatar Sep 06 '21 00:09 akumria

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.

samuong avatar Sep 06 '21 11:09 samuong

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.

marcelocantos avatar Sep 07 '21 05:09 marcelocantos

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.

samuong avatar Feb 24 '23 03:02 samuong