diff --git a/fancylog/fancylog.py b/fancylog/fancylog.py index c92f192..17049bc 100644 --- a/fancylog/fancylog.py +++ b/fancylog/fancylog.py @@ -4,6 +4,7 @@ import json import logging import os +import platform import subprocess import sys import warnings @@ -564,6 +565,22 @@ 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, @@ -571,14 +588,8 @@ def setup_logging( 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 diff --git a/tests/tests/test_general.py b/tests/tests/test_general.py index 3efcff6..450ad92 100644 --- a/tests/tests/test_general.py +++ b/tests/tests/test_general.py @@ -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, + )