Skip to content

Commit 2f02555

Browse files
authored
Logs should go to stderr (#1383)
Currently, we log to stdout, which is contrary to UNIX conventions. Also, it makes it impossible to redirect normal standard output of commands like cmsRWSHelper to a file. Closes #1382.
1 parent 05a3b8d commit 2f02555

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

cms/log.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,16 +393,16 @@ def process(self, msg: str, kwargs: dict):
393393

394394

395395
# Install a shell handler.
396-
shell_handler = StreamHandler(sys.stdout)
396+
shell_handler = StreamHandler(sys.stderr)
397397
shell_handler.setLevel(logging.INFO)
398-
shell_handler.setFormatter(CustomFormatter(has_color_support(sys.stdout)))
398+
shell_handler.setFormatter(CustomFormatter(has_color_support(sys.stderr)))
399399
root_logger.addHandler(shell_handler)
400400

401401

402402
def set_detailed_logs(detailed: bool):
403403
"""Set or unset the shell logs to detailed."""
404404
global shell_handler
405-
color = has_color_support(sys.stdout)
405+
color = has_color_support(sys.stderr)
406406
formatter = DetailedFormatter(color) \
407407
if detailed else CustomFormatter(color)
408408
shell_handler.setFormatter(formatter)

cmsranking/Logger.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ def format(self, record):
243243
root_logger.setLevel(logging.DEBUG)
244244

245245
# Define the stream handler to output on stderr.
246-
shell_handler = StreamHandler(sys.stdout)
246+
shell_handler = StreamHandler(sys.stderr)
247247
shell_handler.setLevel(logging.INFO)
248-
shell_handler.setFormatter(CustomFormatter(has_color_support(sys.stdout)))
248+
shell_handler.setFormatter(CustomFormatter(has_color_support(sys.stderr)))
249249
root_logger.addHandler(shell_handler)
250250

251251

0 commit comments

Comments
 (0)