Skip to content

Commit

Permalink
Assure logging goes to stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed May 17, 2021
1 parent 756fc33 commit e9b5007
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/molecule/console.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Console and terminal utilities."""
import os
import sys
from typing import Any
from typing import Any, Dict

from enrich.console import Console
from rich.style import Style
Expand Down Expand Up @@ -71,9 +71,15 @@ def should_do_markup() -> bool:
return sys.stdout.isatty()


console_options: Dict[str, Any] = {"emoji": False, "theme": theme, "soft_wrap": True}

console = Console(
force_terminal=should_do_markup(), theme=theme, record=True, redirect=True
)
console_options_stderr = console_options.copy()
console_options_stderr["stderr"] = True
console_stderr: Console = Console(**console_options_stderr)

# Define ANSIBLE_FORCE_COLOR if markup is enabled and another value is not
# already given. This assures that Ansible subprocesses are still colored,
# even if they do not run with a real TTY.
Expand Down
4 changes: 2 additions & 2 deletions src/molecule/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

from enrich.logging import RichHandler

from molecule.console import console
from molecule.console import console, console_stderr
from molecule.text import underscore

LOG = logging.getLogger(__name__)
Expand All @@ -48,7 +48,7 @@ def configure() -> None:
# libraries.
logger = logging.getLogger()
handler = RichHandler(
console=console, show_time=False, show_path=False, markup=True
console=console_stderr, show_time=False, show_path=False, markup=True
) # type: ignore
logger.addHandler(handler)
logger.propagate = False
Expand Down

0 comments on commit e9b5007

Please sign in to comment.