Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

correct flags for log file #13

Merged
merged 1 commit into from
Feb 17, 2024
Merged

Conversation

seiyab
Copy link
Contributor

@seiyab seiyab commented Feb 17, 2024

Trying grype, I found that it overwrites previous content in log file without truncating. So in some situations, log file can be broken. Feel free to ask me to use other flags like O_APPEND or O_EXCL.

Reproduction:

printf 'previous content\n%.0s' {1..10} > my-log.txt
GRYPE_LOG_LEVEL=info GRYPE_LOG_FILE=./my-log.txt go run ./cmd/grype alpine

Resulting my-log.txt:

[0000]  INFO grype version: [not provided]
[0001]  INFO found 12 vulnerability matches across 15 packages
ious content
previous content
previous content
previous content

Merging this, resulting my-log.txt wil be:

[0000]  INFO grype version: [not provided]
[0001]  INFO found 12 vulnerability matches across 15 packages

Signed-off-by: seiya <20365512+seiyab@users.noreply.github.com>
Copy link
Contributor

@kzantow kzantow left a comment

Choose a reason for hiding this comment

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

This makes sense to me @seiyab; thanks! Since we're already overwriting any existing file here, truncating it seems like the right thing to do if it exists.

@kzantow kzantow merged commit ee28a48 into anchore:main Feb 17, 2024
3 checks passed
@seiyab seiyab deleted the correct-log-file-flags branch February 18, 2024 05:59
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants