Skip to content

Conversation

@ep0chzer0
Copy link

Summary

Changes logging output from stderr to stdout for better Unix CLI compatibility.

Problem

Slither outputs detector and printer results to stderr instead of stdout, which goes against Unix CLI tool expectations and makes piping/grepping awkward:

# Before: doesn't work as expected
slither . > output.txt        # output.txt is empty, output goes to console
slither . | grep "reentrancy" # nothing found, need `2>&1` workaround

Solution

Changed logging.StreamHandler() to logging.StreamHandler(sys.stdout) in:

  • slither/__main__.py
  • slither/tools/erc_conformance/__main__.py
  • slither/tools/kspec_coverage/__main__.py
  • slither/tools/properties/__main__.py

After this change

slither . > output.txt        # captures slither output correctly
slither . | grep "reentrancy" # works as expected

Notes

Fixes #753

🤖 Generated with Claude Code

@ep0chzer0 ep0chzer0 requested a review from smonicas as a code owner January 16, 2026 12:10
@ep0chzer0
Copy link
Author

Hi maintainers, could you please approve the CI workflow runs for this PR? As a first-time contributor, the workflows require maintainer approval. Thank you!

@ep0chzer0 ep0chzer0 force-pushed the fix/output-to-stdout branch 2 times, most recently from 8a0812b to fe88290 Compare January 16, 2026 13:35
@elopez
Copy link
Member

elopez commented Jan 16, 2026

We need to ensure this doesn't break other tools' expectations, e.g. slither . --print echidna --json - should only have valid JSON on stdout and not any other messages.

@ep0chzer0
Copy link
Author

Thanks for the feedback @elopez! I've updated the PR to address this concern.

Changes:

  • When --json - or --sarif - is used, logs now go to stderr to preserve valid JSON/SARIF on stdout
  • Normal usage (no JSON to stdout) still benefits from stdout logging for better Unix CLI compatibility

I also reverted the changes to the tool subcommands since they set up logging at module level before args are parsed.

The behavior is now:

  • slither . > output.txt - captures logs (normal usage)
  • slither . --json - > output.json - only valid JSON in file, logs to stderr

Changes logging output from stderr to stdout for better Unix CLI compatibility.
This allows standard piping and grepping to work as expected:
- `slither . > output.txt` now captures slither output
- `slither . | grep "reentrancy"` works without `2>&1`

Updated:
- slither/__main__.py
- slither/tools/erc_conformance/__main__.py
- slither/tools/kspec_coverage/__main__.py
- slither/tools/properties/__main__.py

Fixes crytic#753
Address maintainer feedback: When using --json - or --sarif -,
logs must go to stderr to avoid mixing with structured output.

- Normal usage: logs go to stdout (better Unix CLI compatibility)
- With --json - or --sarif -: logs go to stderr (preserve valid JSON)

Reverted changes to tool subcommands since they set up logging at
module level before args are parsed.
@ep0chzer0 ep0chzer0 force-pushed the fix/output-to-stdout branch from 8e4269b to b14b811 Compare January 16, 2026 23:28
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.

why does slither output to stderr instead of stdout?

2 participants