|
9 | 9 | from c42eventextractor.logging.formatters import FileEventDictToJSONFormatter |
10 | 10 | from c42eventextractor.logging.formatters import FileEventDictToRawJSONFormatter |
11 | 11 | from c42eventextractor.logging.handlers import NoPrioritySysLogHandlerWrapper |
| 12 | +from click.exceptions import ClickException |
12 | 13 |
|
13 | 14 | from code42cli.cmds.search.enums import FileEventsOutputFormat |
14 | 15 | from code42cli.util import get_url_parts |
@@ -38,28 +39,12 @@ def _init_logger(logger, handler, output_format): |
38 | 39 |
|
39 | 40 | def handleError(record): |
40 | 41 | """Override logger's `handleError` method to exit if an exception is raised while trying to |
41 | | - log, and replace stdout with devnull because if we're here it's usually because stdout has |
42 | | - been closed on us. |
| 42 | + log, otherwise it would continue to gather and process events if the connection breaks but send |
| 43 | + them nowhere. |
43 | 44 | """ |
44 | 45 | t, v, tb = sys.exc_info() |
45 | 46 | if t == BrokenPipeError: |
46 | | - sys.stdout = open(os.devnull) |
47 | | - sys.exit() |
48 | | - |
49 | | - |
50 | | -def get_logger_for_stdout(name_suffix="main", formatter=None): |
51 | | - logger = logging.getLogger("code42_stdout_{}".format(name_suffix)) |
52 | | - if logger_has_handlers(logger): |
53 | | - return logger |
54 | | - |
55 | | - with logger_deps_lock: |
56 | | - if not logger_has_handlers(logger): |
57 | | - handler = logging.StreamHandler(sys.stdout) |
58 | | - handler.handleError = handleError |
59 | | - formatter = formatter or _get_standard_formatter() |
60 | | - logger.setLevel(logging.INFO) |
61 | | - return add_handler_to_logger(logger, handler, formatter) |
62 | | - return logger |
| 47 | + raise ClickException("Network connection broken while sending results.") |
63 | 48 |
|
64 | 49 |
|
65 | 50 | def get_logger_for_server(hostname, protocol, output_format): |
|
0 commit comments