Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Write logs to disk by default #2082

Merged
merged 8 commits into from
Jan 13, 2023
Merged

Write logs to disk by default #2082

merged 8 commits into from
Jan 13, 2023

Conversation

meain
Copy link
Member

@meain meain commented Jan 10, 2023

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?

  • ✅ Yes, it's included
  • 🕐 Yes, but in a later PR
  • ⛔ No

Type of change

  • 🌻 Feature
  • 🐛 Bugfix
  • 🗺️ Documentation
  • 🤖 Test
  • 💻 CI/Deployment
  • 🧹 Tech Debt/Cleanup

Issue(s)

Test Plan

  • 💪 Manual
  • ⚡ Unit test
  • 💚 E2E

@meain meain self-assigned this Jan 10, 2023
@meain meain temporarily deployed to Testing January 10, 2023 09:54 — with GitHub Actions Inactive
@meain meain temporarily deployed to Testing January 10, 2023 09:54 — with GitHub Actions Inactive
@meain meain temporarily deployed to Testing January 10, 2023 09:55 — with GitHub Actions Inactive
@meain meain temporarily deployed to Testing January 10, 2023 09:55 — with GitHub Actions Inactive
@meain meain temporarily deployed to Testing January 10, 2023 09:55 — with GitHub Actions Inactive
@meain meain temporarily deployed to Testing January 10, 2023 09:56 — with GitHub Actions Inactive
@meain meain temporarily deployed to Testing January 10, 2023 10:01 — with GitHub Actions Inactive
@meain meain temporarily deployed to Testing January 10, 2023 10:01 — with GitHub Actions Inactive
@meain meain temporarily deployed to Testing January 10, 2023 10:02 — with GitHub Actions Inactive
@meain meain temporarily deployed to Testing January 10, 2023 10:02 — with GitHub Actions Inactive
@meain meain temporarily deployed to Testing January 10, 2023 10:02 — with GitHub Actions Inactive

"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"
Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member Author

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/

Copy link
Contributor

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 == "-" {
Copy link
Member Author

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.

@meain meain temporarily deployed to Testing January 10, 2023 10:06 — with GitHub Actions Inactive
Copy link
Contributor

@ryanfkeepers ryanfkeepers left a 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.


"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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var defaultLogLocation = "corso-" + time.Now().UTC().Format("2006-01-02T15-04-05Z") + ".log"
var defaultLogLocation = "corso-" + common.FormatNow(common.SimpleDateTime) + ".log"

Copy link
Member Author

@meain meain Jan 11, 2023

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.


"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"
Copy link
Contributor

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"
Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Contributor

@ryanfkeepers ryanfkeepers left a 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.

ntolia
ntolia previously requested changes Jan 11, 2023
Copy link
Contributor

@ntolia ntolia left a 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.

@meain meain temporarily deployed to Testing January 11, 2023 09:26 — with GitHub Actions Inactive
@meain meain temporarily deployed to Testing January 11, 2023 09:26 — with GitHub Actions Inactive
@meain meain temporarily deployed to Testing January 11, 2023 09:26 — with GitHub Actions Inactive
@meain meain temporarily deployed to Testing January 11, 2023 11:44 — with GitHub Actions Inactive
@meain meain temporarily deployed to Testing January 11, 2023 11:44 — with GitHub Actions Inactive
@meain meain temporarily deployed to Testing January 11, 2023 11:44 — with GitHub Actions Inactive
@meain meain temporarily deployed to Testing January 11, 2023 11:44 — with GitHub Actions Inactive
@meain meain temporarily deployed to Testing January 11, 2023 11:49 — with GitHub Actions Inactive
@meain meain temporarily deployed to Testing January 11, 2023 11:49 — with GitHub Actions Inactive
@meain meain temporarily deployed to Testing January 11, 2023 11:49 — with GitHub Actions Inactive
@meain meain temporarily deployed to Testing January 11, 2023 11:50 — with GitHub Actions Inactive
@meain meain temporarily deployed to Testing January 11, 2023 11:50 — with GitHub Actions Inactive
@meain meain temporarily deployed to Testing January 11, 2023 11:50 — with GitHub Actions Inactive
@aviator-app
Copy link
Contributor

aviator-app bot commented Jan 13, 2023

Aviator status

Aviator will automatically update this comment as the status of the PR changes.

This PR was merged using Aviator.

@aviator-app aviator-app bot temporarily deployed to Testing January 13, 2023 07:23 Inactive
@aviator-app aviator-app bot temporarily deployed to Testing January 13, 2023 07:23 Inactive
@aviator-app aviator-app bot temporarily deployed to Testing January 13, 2023 07:24 Inactive
@sonarcloud
Copy link

sonarcloud bot commented Jan 13, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@aviator-app aviator-app bot temporarily deployed to Testing January 13, 2023 07:24 Inactive
@aviator-app aviator-app bot temporarily deployed to Testing January 13, 2023 07:24 Inactive
@aviator-app aviator-app bot temporarily deployed to Testing January 13, 2023 07:24 Inactive
@aviator-app aviator-app bot merged commit 01d8d08 into main Jan 13, 2023
@aviator-app aviator-app bot deleted the logs-to-disk branch January 13, 2023 07:44
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.
Copy link
Contributor

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

Copy link
Contributor

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

@meain meain mentioned this pull request Jan 13, 2023
3 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Log to disk by default
4 participants