metwork-framework/log_proxy

introduce a log directory

thefab opened this issue · 4 comments

Now, LOGNAME can be a file name or a complete file path. It's great.

But it would be nice to add a --log-directory option (default to LOGPROXY_LOG_DIRECTORY or empty) to add before LOGNAME to build the complete log file path.

For example:

[...] |log_proxy --log-directory=/tmp foo.log
# will log in /tmp/foo.log

[...] |log_proxy --log-directory=/tmp/foo bar/foo.log
# will log in /tmp/foo/bar/foo.log

[...] |log_proxy foo.log
# will log in foo.log (current directory) [if LOGPROXY_LOG_DIRECTORY is empty]

[...] |log_proxy foo.log
# will log in /tmp/foo/foo.log (current directory) [if LOGPROXY_LOG_DIRECTORY == "/tmp/foo"]

[...] |log_proxy /tmp/foo.log
# will log in /tmp/foo.log

[...] |log_proxy --log-directory=/foo /tmp/foo.log
# will log in /tmp/foo.log (because LOGNAME starts with `/`, `--log-directory` is ignored)

[...] |log_proxy --log-directory=/foo/ bar.log
# will raise an error (because we don't want any trailing `/` on log-directory)

It would be really nice for metwork plugins to be able to change all log files location with a simple env var change in the plugin env.

any advice @thebaptiste?

Why is it a problem if --log-directory (or LOGPROXY_LOG_DIRECTORY) ends with '/' ?

[...] |log_proxy --log-directory=/foo/ bar.log
#will log in /foo//bar.log, which is the same as /foo/bar.log

May be we could suppress the trailing '/' but I don't think it's essential and whatever I think it's not a good idea to raise an error for that.

As you want :-) it was only to make the development easier ;-)

Should we try to create the log directory if it doesn't exist ?