-
Notifications
You must be signed in to change notification settings - Fork 37
Conversation
src/pkg/logger/logger.go
Outdated
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
"go.uber.org/zap" | ||
"go.uber.org/zap/zapcore" | ||
) | ||
|
||
var defaultLogLocation = "corso-" + time.Now().UTC().Format("2006-01-02T15-04-05Z") + ".log" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default log location is currently $PWD/corso-<timestamp>.log
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me. @gmatev you happy with this? Alternatively, we could co-locate it with the config file location by default. Or perhaps a ~/.corso folder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, if we are changing to a different location, we will also have to consider what it will be in Windows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option would be stick to XDG base directory specification in linux and store it under $XDG_STATE_HOME
which would be $HOME/.loca/state/corso/corso-<timestamp>.log
.
As a follow-up, we should probably consider moving the config file to $XDG_CONFIG_HOME
, which would be $HOME/.config/corso/config.toml
.
There is a relatively vocal group of people(myself kinda included) advocating against polluting home directory on linux: https://www.reddit.com/r/linux/comments/971m0z/im_tired_of_folders_littering_my_home_directory/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree that this should not be home directory or local directory. Suggest we emulate https://kopia.io/docs/advanced/logging/
return "info", defaultLogLocation | ||
} | ||
|
||
if logfile == "-" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They can still use cobra specific stdout
, but this is a more common convention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some concerns about the writer itself, otherwise looks good.
src/pkg/logger/logger.go
Outdated
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
"go.uber.org/zap" | ||
"go.uber.org/zap/zapcore" | ||
) | ||
|
||
var defaultLogLocation = "corso-" + time.Now().UTC().Format("2006-01-02T15-04-05Z") + ".log" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var defaultLogLocation = "corso-" + time.Now().UTC().Format("2006-01-02T15-04-05Z") + ".log" | |
var defaultLogLocation = "corso-" + common.FormatNow(common.SimpleDateTime) + ".log" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:
in common.SimpleDateTime
is an invalid char for files on Windows(zap also does not seem to like it). This format is similar to that but :
replaced with -
. I can create a new constant if you think that is necessary.
src/pkg/logger/logger.go
Outdated
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
"go.uber.org/zap" | ||
"go.uber.org/zap/zapcore" | ||
) | ||
|
||
var defaultLogLocation = "corso-" + time.Now().UTC().Format("2006-01-02T15-04-05Z") + ".log" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me. @gmatev you happy with this? Alternatively, we could co-locate it with the config file location by default. Or perhaps a ~/.corso folder.
} | ||
|
||
if logfile == "-" { | ||
logfile = "stdout" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be stderr
, not stdout. Stdout will cause logging to interfere with end-of-run application prints, preventing users from piping the results to scripts (ex: corso ... --json | jq {...}
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more of a extra option as -
is a common convention for stdin
/ stdout
. If a user wants to pipe to stderr
they can use "stderr" as the filename.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving to unblock this. Prior comments still need to be addressed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also:
- Modify docs/support/bugs-and-features/ to include information on where to find the log file to share
- Modify docs/setup/configuration/ and add a new section (Log files) and specify the default location as well as a reference to the flag.
Aviator status
This PR was merged using Aviator. |
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Log file location can be overridden by setting the `--log-file` flag. | ||
|
||
:::info | ||
You can use `stdout` or `stderr` as the `--log-file` location to redirect the logs to "stdout" and "stderr" respectively. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of You can use ...
- change to Use
stdout ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So "Use stdout
or stderr
as the --log-file
location to redirect the logs to "stdout" or "stderr".
Description
This changes the behavior of logs and writes it to disk instead of
stdout
by default. It also adds a new flag--log-file
to specify the filename for the log file.Does this PR need a docs update or release note?
Type of change
Issue(s)
Test Plan