Skip to content

Commit 86d42a4

Browse files
committed
Fixed: properly route logs - INFO to stdout, errors to stderr
- INFO and DEBUG logs go to stdout - WARNING, ERROR, CRITICAL logs go to stderr - Follows Unix convention for proper log routing
1 parent cc48f6b commit 86d42a4

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

modlog_wiki_publisher.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,15 +1514,30 @@ def create_argument_parser():
15141514

15151515

15161516
def setup_logging(debug: bool = False):
1517-
"""Setup logging configuration"""
1517+
"""Setup logging configuration with proper stream routing"""
15181518
os.makedirs(LOGS_DIR, exist_ok=True)
15191519

15201520
level = logging.DEBUG if debug else logging.INFO
1521-
logging.basicConfig(
1522-
level=level,
1523-
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
1524-
stream=sys.stdout,
1525-
)
1521+
1522+
# Create formatters
1523+
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
1524+
1525+
# Handler for INFO and DEBUG to stdout
1526+
stdout_handler = logging.StreamHandler(sys.stdout)
1527+
stdout_handler.setLevel(logging.DEBUG)
1528+
stdout_handler.setFormatter(formatter)
1529+
stdout_handler.addFilter(lambda record: record.levelno < logging.WARNING)
1530+
1531+
# Handler for WARNING, ERROR, CRITICAL to stderr
1532+
stderr_handler = logging.StreamHandler(sys.stderr)
1533+
stderr_handler.setLevel(logging.WARNING)
1534+
stderr_handler.setFormatter(formatter)
1535+
1536+
# Configure root logger
1537+
root_logger = logging.getLogger()
1538+
root_logger.setLevel(level)
1539+
root_logger.addHandler(stdout_handler)
1540+
root_logger.addHandler(stderr_handler)
15261541

15271542
# Set prawcore and urllib3 to TRACE level for Reddit API debugging when debug is enabled
15281543
if debug:

0 commit comments

Comments
 (0)