Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions fancylog/fancylog.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import logging
import os
import platform
import subprocess
import sys
import warnings
Expand Down Expand Up @@ -564,21 +565,31 @@ def setup_logging(
Name of the logger to use. If None, the default logger is used.

"""
if multiprocessing_aware and logger_name:
raise ValueError(
"`multiprocessing_aware` is not supported"
"with `logger_name`. Multiprocess logging"
"must be performed with the root logger."
)

if multiprocessing_aware and platform.system() == "Windows":
warnings.warn(
"Multiprocessing logging is not supported on Windows. "
"It has been disabled.",
UserWarning,
stacklevel=2,
)
multiprocessing_aware = False

logger = initialise_logger(
filename,
print_level=print_level,
file_level=file_level,
log_to_console=log_to_console,
logger_name=logger_name,
)
if multiprocessing_aware:
if logger_name:
raise ValueError(
"`multiprocessing_aware` is not supported"
"with `logger_name`. Multiprocess logging"
"must be performed with the root logger."
)

if multiprocessing_aware:
try:
import multiprocessing_logging

Expand Down
17 changes: 17 additions & 0 deletions tests/tests/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,3 +425,20 @@ def test_mock_no_environment(tmp_path):

assert f"{'fancylog':20} {'1.1.1'}"
assert f"{'pytest':20} {'1.1.1'}"


def test_multiprocessing_warning_on_windows(tmp_path):
"""A warning is raised and multiprocessing logging
is disabled on Windows.
"""
with (
patch("platform.system", return_value="Windows"),
pytest.warns(
UserWarning, match="Multiprocessing logging is not supported"
),
):
fancylog.start_logging(
tmp_path,
fancylog,
multiprocessing_aware=True,
)
Loading