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 415335a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
11 changes: 9 additions & 2 deletions hdl_checker/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,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
41 changes: 41 additions & 0 deletions hdl_checker/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,47 @@ 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 415335a

Please sign in to comment.