Skip to content

Commit

Permalink
Use --log-stream NONE and/or --sterr NONE to disable logging, stderr
Browse files Browse the repository at this point in the history
Closes #73
  • Loading branch information
suoto committed Jan 22, 2020
1 parent 7084b66 commit 3b7b973
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
17 changes: 13 additions & 4 deletions hdl_checker/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<PID>.log when in LSP mode",
"temporary file named hdl_checker_log_pid<PID>.log when in LSP mode. "
"Use NONE to disable logging altogether",
)

parser.add_argument(
Expand All @@ -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<PID>.log",
"named hdl_checker_stderr_pid<PID>.log. "
"Use NONE to disable redirecting stderr altogether",
)

parser.add_argument(
Expand Down Expand Up @@ -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

Expand Down
50 changes: 50 additions & 0 deletions hdl_checker/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit 3b7b973

Please sign in to comment.