diff --git a/setup.py b/setup.py index dcce524e7..1ee9a1ee4 100644 --- a/setup.py +++ b/setup.py @@ -36,7 +36,7 @@ bundled_plugins = [ core_deps = [ "cachelib>=0.2,<0.3", "Click>=8.0.3,<9", - "colorlog>=5.0.1,<6", + "colorlog>=6,<7", "emoji>=1.4.2,<2", "feedparser>=6.0.8,<7", "filetype>=1.0.7,<2", diff --git a/src/octoprint/__init__.py b/src/octoprint/__init__.py index bfaee7ea8..5cd8e5a70 100644 --- a/src/octoprint/__init__.py +++ b/src/octoprint/__init__.py @@ -68,6 +68,7 @@ def init_platform( verbosity=0, uncaught_logger=None, uncaught_handler=None, + disable_color=True, safe_mode=False, ignore_blacklist=False, after_preinit_logging=None, @@ -109,6 +110,7 @@ def init_platform( verbosity=verbosity, uncaught_logger=uncaught_logger, uncaught_handler=uncaught_handler, + disable_color=disable_color, ) except Exception as ex: raise FatalStartupError("Could not initialize logging", cause=ex) @@ -252,6 +254,7 @@ def init_logging( verbosity=0, uncaught_logger=None, uncaught_handler=None, + disable_color=True, ): """Sets up logging.""" @@ -272,7 +275,6 @@ def init_logging( "reset": True, "log_colors": { "DEBUG": "cyan", - "INFO": "white", "WARNING": "yellow", "ERROR": "red", "CRITICAL": "bold_red", @@ -286,7 +288,7 @@ def init_logging( "console": { "class": "octoprint.logging.handlers.OctoPrintStreamHandler", "level": "DEBUG", - "formatter": "colored", + "formatter": "simple" if disable_color else "colored", "stream": "ext://sys.stdout", }, "file": { diff --git a/src/octoprint/cli/__init__.py b/src/octoprint/cli/__init__.py index 827396249..57f753c09 100644 --- a/src/octoprint/cli/__init__.py +++ b/src/octoprint/cli/__init__.py @@ -62,6 +62,7 @@ def init_platform_for_cli(ctx): get_ctx_obj_option(ctx, "configfile", None), overlays=get_ctx_obj_option(ctx, "overlays", None), safe_mode=True, + disable_color=get_ctx_obj_option(ctx, "no_color", False), ) ( @@ -236,6 +237,15 @@ def standard_options(hidden=False): expose_value=False, help="Enable safe mode; disables all third party plugins.", ), + factory( + "--no-color", + "no_color", + is_flag=True, + callback=set_ctx_obj_option, + is_eager=True, + expose_value=False, + help="Disable colored console output. Alternatively set the NO_COLOR environment variable to a value of 1.", + ), ] return bulk_options(options) diff --git a/src/octoprint/cli/server.py b/src/octoprint/cli/server.py index dcefd9d07..0a234eace 100644 --- a/src/octoprint/cli/server.py +++ b/src/octoprint/cli/server.py @@ -31,6 +31,7 @@ def run_server( ignore_blacklist, octoprint_daemon=None, overlays=None, + disable_color=False, ): """Initializes the environment and starts up the server.""" @@ -120,6 +121,7 @@ def run_server( ignore_blacklist=ignore_blacklist, after_safe_mode=log_startup, after_environment_detector=log_register_rollover, + disable_color=disable_color, ) ( settings, @@ -307,6 +309,7 @@ def serve_command(ctx, **kwargs): safe_mode = "flag" if get_value("safe_mode") else None ignore_blacklist = get_value("ignore_blacklist") overlays = get_value("overlays") + no_color = get_value("no_color") if v4 and not host: host = "0.0.0.0" @@ -324,6 +327,7 @@ def serve_command(ctx, **kwargs): safe_mode, ignore_blacklist, overlays=overlays, + disable_color=no_color, )