Skip to content

Commit a37bd71

Browse files
dguidoclaude
andcommitted
fix: Suppress CryticCompile INFO messages during subcommand execution
Configure logging to suppress CryticCompile INFO-level messages before importing crytic_compile, ensuring the "running" and compilation messages don't appear in tool output. This fixes CI e2e tests that compare output against expected files. Changes: - Move logging.basicConfig() before crytic_compile import - Set CryticCompile logger to WARNING level early - Change configure_logger() to use WARNING instead of INFO for CryticCompile - Add noqa: E402 comments for imports after logging config Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 175b7a9 commit a37bd71

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

slither/__main__.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,23 @@
1919
if os.environ.get("_TYPER_COMPLETE_ARGS", False):
2020
warnings.filterwarnings("ignore")
2121

22-
import typer
23-
from typing_extensions import Annotated
24-
25-
from crytic_compile import CryticCompile, InvalidCompilation
26-
from crytic_compile import compile_all, is_supported
27-
28-
from slither.detectors import all_detectors
29-
from slither.detectors.abstract_detector import AbstractDetector
30-
from slither.detectors.classification import DetectorClassification
31-
from slither.printers import all_printers
32-
from slither.printers.abstract_printer import AbstractPrinter
33-
from slither.slither import Slither
34-
from slither.utils.output import (
22+
# Configure logging BEFORE importing crytic_compile to suppress INFO messages
23+
logging.basicConfig()
24+
logging.getLogger("CryticCompile").setLevel(logging.WARNING)
25+
26+
import typer # noqa: E402
27+
from typing_extensions import Annotated # noqa: E402
28+
29+
from crytic_compile import CryticCompile, InvalidCompilation # noqa: E402
30+
from crytic_compile import compile_all, is_supported # noqa: E402
31+
32+
from slither.detectors import all_detectors # noqa: E402
33+
from slither.detectors.abstract_detector import AbstractDetector # noqa: E402
34+
from slither.detectors.classification import DetectorClassification # noqa: E402
35+
from slither.printers import all_printers # noqa: E402
36+
from slither.printers.abstract_printer import AbstractPrinter # noqa: E402
37+
from slither.slither import Slither # noqa: E402
38+
from slither.utils.output import ( # noqa: E402
3539
Output,
3640
ZipType,
3741
OutputFormat,
@@ -42,9 +46,9 @@
4246
output_detectors_json,
4347
output_printers,
4448
)
45-
from slither.utils.output_capture import StandardOutputCapture
46-
from slither.utils.colors import red, set_colorization_enabled
47-
from slither.utils.command_line import (
49+
from slither.utils.output_capture import StandardOutputCapture # noqa: E402
50+
from slither.utils.colors import red, set_colorization_enabled # noqa: E402
51+
from slither.utils.command_line import ( # noqa: E402
4852
FailOnLevel,
4953
defaults_flag_in_config,
5054
DEFAULT_JSON_OUTPUT_TYPES,
@@ -59,12 +63,10 @@
5963
target_type,
6064
read_config_file,
6165
)
62-
from slither.exceptions import SlitherException
66+
from slither.exceptions import SlitherException # noqa: E402
6367

64-
logging.basicConfig()
6568
logger = logging.getLogger("Slither")
6669

67-
6870
app = SlitherApp("detect", rich_markup_mode="markdown", result_callback=slither_end_callback)
6971

7072
# Because the app will be used by the tools to add commands, we need to define it before importing them
@@ -1097,14 +1099,14 @@ def configure_logger(log_level: int = logging.INFO):
10971099
logging.getLogger(logger_name).setLevel(log_level)
10981100

10991101
console_handler = logging.StreamHandler()
1100-
console_handler.setLevel(logging.INFO)
1102+
console_handler.setLevel(logging.WARNING)
11011103

11021104
console_handler.setFormatter(FormatterCryticCompile())
11031105

11041106
crytic_compile_error = logging.getLogger("CryticCompile")
11051107
crytic_compile_error.addHandler(console_handler)
11061108
crytic_compile_error.propagate = False
1107-
crytic_compile_error.setLevel(logging.INFO)
1109+
crytic_compile_error.setLevel(logging.WARNING)
11081110

11091111

11101112
def main():

0 commit comments

Comments
 (0)