mirror of
https://github.com/sshuttle/sshuttle.git
synced 2025-08-09 23:57:36 +02:00
Refactor debug, log and Fatal messages.
This commit rewrites the log() function so that it will append a newline at the end of the message if none is present. It doesn't make sense to print a log message without a newline since the next log message (which will write a prefix) expects to be starting at the beginning of a line. Although it isn't strictly necessary, this commit also removes any newlines at the ends of messages. If I missed any, including the newline at the end of the message will continue to work as it did before. Previously, some calls were missing the newline at the end even though including it was necessary for subsequent messages to appear correctly. This code also cleans up some redundant prefixes. The log() method will prepend the prefix and the different processes should set their prefix as soon as they start. Multiline messages are still supported (although the prefix for the additional lines was changed to match the length of the prefix used for the first line).
This commit is contained in:
@ -24,19 +24,19 @@ def test_log(mock_stderr, mock_stdout):
|
||||
call.flush(),
|
||||
]
|
||||
assert mock_stderr.mock_calls == [
|
||||
call.write('prefix: message'),
|
||||
call.write('prefix: message\n'),
|
||||
call.flush(),
|
||||
call.write('prefix: abc'),
|
||||
call.write('prefix: abc\n'),
|
||||
call.flush(),
|
||||
call.write('prefix: message 1\n'),
|
||||
call.flush(),
|
||||
call.write('prefix: message 2\n'),
|
||||
call.write('---> line2\n'),
|
||||
call.write('---> line3\n'),
|
||||
call.write(' line2\n'),
|
||||
call.write(' line3\n'),
|
||||
call.flush(),
|
||||
call.write('prefix: message 3\n'),
|
||||
call.write('---> line2\n'),
|
||||
call.write('---> line3\n'),
|
||||
call.write(' line2\n'),
|
||||
call.write(' line3\n'),
|
||||
call.flush(),
|
||||
]
|
||||
|
||||
@ -51,7 +51,7 @@ def test_debug1(mock_stderr, mock_stdout):
|
||||
call.flush(),
|
||||
]
|
||||
assert mock_stderr.mock_calls == [
|
||||
call.write('prefix: message'),
|
||||
call.write('prefix: message\n'),
|
||||
call.flush(),
|
||||
]
|
||||
|
||||
@ -76,7 +76,7 @@ def test_debug2(mock_stderr, mock_stdout):
|
||||
call.flush(),
|
||||
]
|
||||
assert mock_stderr.mock_calls == [
|
||||
call.write('prefix: message'),
|
||||
call.write('prefix: message\n'),
|
||||
call.flush(),
|
||||
]
|
||||
|
||||
@ -101,7 +101,7 @@ def test_debug3(mock_stderr, mock_stdout):
|
||||
call.flush(),
|
||||
]
|
||||
assert mock_stderr.mock_calls == [
|
||||
call.write('prefix: message'),
|
||||
call.write('prefix: message\n'),
|
||||
call.flush(),
|
||||
]
|
||||
|
||||
|
Reference in New Issue
Block a user