Skip to content

Conversation

@idunbarh
Copy link
Member

@idunbarh idunbarh commented Sep 5, 2024

Description

This PR fixes #149.

When piping bomctl export ... to another command, we should not be printing logging info to stdout. This is cause SBOM schema failures on the tools receiving the sbom content.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

./bomctl fetch https://raw.githubusercontent.com/bomctl/bomctl-playground/main/examples/bomctl-container-image/bomctl_bomctl_v0.3.0.cdx.json
./bomctl ls
./bomctl export urn:uuid:f360ad8b-dc41-4256-afed-337a04dff5db
./bomctl export urn:uuid:f360ad8b-dc41-4256-afed-337a04dff5db | grype

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Signed-off-by: Ian Dunbar-Hall <ian.dunbar-hall@lmco.com>
@jhoward-lm
Copy link
Contributor

jhoward-lm commented Sep 5, 2024

I could see this issue potentially having a more widespread impact. I don't have any problems with this solution, but @idunbarh @ashearin how would you feel about sending all console logging to stderr to avoid this popping up again?

Basically in logger.go, change this to use os.Stderr instead

logger := log.NewWithOptions(os.Stdout, log.Options{Prefix: prefix, Level: log.GetLevel()})

I tested by making this change and running

bomctl fetch <URL> --verbose --netrc               # prints output
bomctl fetch <URL> --verbose --netrc 2> /dev/null  # suppresses output
bomctl fetch <URL> --verbose --netrc > test.txt    # prints output to console and writes nothing to test.txt

Signed-off-by: Ian Dunbar-Hall <ian.dunbar-hall@lmco.com>
@idunbarh
Copy link
Member Author

idunbarh commented Sep 5, 2024

I could see this issue potentially having a more widespread impact. I don't have any problems with this solution, but @idunbarh @ashearin how would you feel about sending all console logging to stderr to avoid this popping up again?

Basically in logger.go, change this to use os.Stderr instead

logger := log.NewWithOptions(os.Stdout, log.Options{Prefix: prefix, Level: log.GetLevel()})

I tested by making this change and running

bomctl fetch <URL> --verbose --netrc               # prints output
bomctl fetch <URL> --verbose --netrc 2> /dev/null  # suppresses output
bomctl fetch <URL> --verbose --netrc > test.txt    # prints output to console and writes nothing to test.txt

Great suggestion! Updated to change logs to stderr.

@ashearin ashearin merged commit 725501e into main Sep 5, 2024
@ashearin ashearin deleted the export-stdout branch September 5, 2024 16:49
pkwiatkowski1 pushed a commit to pkwiatkowski1/bomctl that referenced this pull request Sep 5, 2024
…bomctl#150)

* fix: changed logs to be sent to stderr

Signed-off-by: Ian Dunbar-Hall <ian.dunbar-hall@lmco.com>

---------

Signed-off-by: Ian Dunbar-Hall <ian.dunbar-hall@lmco.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Export command piping of stdout causes issues from logging

4 participants