From 3b7b973f636f42ca641b3e19f68fa8a4ccf7aec5 Mon Sep 17 00:00:00 2001 From: suoto Date: Wed, 22 Jan 2020 15:50:17 +0000 Subject: [PATCH] Use --log-stream NONE and/or --sterr NONE to disable logging, stderr Closes #73 --- hdl_checker/server.py | 17 ++++++++--- hdl_checker/tests/test_server.py | 50 ++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/hdl_checker/server.py b/hdl_checker/server.py index f8493be..df14473 100755 --- a/hdl_checker/server.py +++ b/hdl_checker/server.py @@ -66,7 +66,8 @@ def parseArguments(): "--log-stream", action="store", help="[HTTP, LSP] Log file, defaults to stdout when in HTTP or a " - "temporary file named hdl_checker_log_pid.log when in LSP mode", + "temporary file named hdl_checker_log_pid.log when in LSP mode. " + "Use NONE to disable logging altogether", ) parser.add_argument( @@ -79,7 +80,8 @@ def parseArguments(): "--stderr", action="store", help="[HTTP] File to redirect stdout to. Defaults to a temporary file " - "named hdl_checker_stderr_pid.log", + "named hdl_checker_stderr_pid.log. " + "Use NONE to disable redirecting stderr altogether", ) parser.add_argument( @@ -111,8 +113,15 @@ def parseArguments(): args.log_stream = args.log_stream or sys.stdout # If not set, create a temporary file safely so there's no clashes - args.log_stream = args.log_stream or getTemporaryFilename("log") - args.stderr = args.stderr or getTemporaryFilename("stderr") + if args.log_stream == "NONE": + args.log_stream = None + else: + args.log_stream = args.log_stream or getTemporaryFilename("log") + + if args.stderr == "NONE": + args.stderr = None + else: + args.stderr = args.stderr or getTemporaryFilename("stderr") args.log_level = args.log_level or logging.INFO diff --git a/hdl_checker/tests/test_server.py b/hdl_checker/tests/test_server.py index 793ece7..e052eb6 100644 --- a/hdl_checker/tests/test_server.py +++ b/hdl_checker/tests/test_server.py @@ -467,6 +467,56 @@ def test(): "stderr file should not be {}".format(args.stderr), ) + @it.should("disable writing to log when passing --log-stream NONE") # type: ignore + @disableVunit + def test(): + from hdl_checker import server + + # Check it works with LSP + with patch.object( + server.argparse._sys, + "argv", + [p.abspath(server.__file__), "--lsp", "--log-stream", "NONE"], + ): + args = server.parseArguments() + + it.assertIsNone(args.log_stream) + + # Check it works with HTTP server + with patch.object( + server.argparse._sys, + "argv", + [p.abspath(server.__file__), "--log-stream", "NONE"], + ): + args = server.parseArguments() + + it.assertIsNone(args.log_stream) + + @it.should("disable writing to stderr when passing --stderr NONE") # type: ignore + @disableVunit + def test(): + from hdl_checker import server + + # Check it works with LSP + with patch.object( + server.argparse._sys, + "argv", + [p.abspath(server.__file__), "--lsp", "--stderr", "NONE"], + ): + args = server.parseArguments() + + it.assertIsNone(args.stderr) + + # Check it works with HTTP server + with patch.object( + server.argparse._sys, + "argv", + [p.abspath(server.__file__), "--stderr", "NONE"], + ): + args = server.parseArguments() + + it.assertIsNone(args.stderr) + @patch("hdl_checker.server.start_io_lang_server") @patch("hdl_checker.server._binaryStdio", return_value=("stdin", "stdout"))