Skip to content

Commit

Permalink
Fix prober, color config
Browse files Browse the repository at this point in the history
  • Loading branch information
aBozowski committed Oct 20, 2023
1 parent c5d668c commit 85517ff
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/tools/interop/idt/capture/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@

log_level = logging.INFO
async_timeout = 45.0
enable_color = True
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@
import os

from capture.utils.shell import Bash
from capture.utils import log
logger = log.get_logger(__file__)


class PlayServicesProber:

def __init__(self, platform):
self.platform = platform
self.artifact_dir = self.platform.artifact_dir
self.logger = log_format.get_logger(__file__)
self.logger = logger

async def _probe_foyer(self) -> None:
self.logger.info("probing remote services")
Expand Down
20 changes: 15 additions & 5 deletions src/tools/interop/idt/capture/utils/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import logging
from typing import TextIO

from capture import config
from .. import config

_CONFIG_LEVEL = config.log_level

Expand All @@ -33,8 +33,10 @@

reset = "\x1b[0m"

format_pre = cyan + "%(asctime)s %(levelname)s {%(module)s} [%(funcName)s] " + reset
format_pre = "%(asctime)s %(levelname)s {%(module)s} [%(funcName)s] " + reset
format_pre = cyan + format_pre if config.enable_color else format_pre
format_post = "%(message)s" + reset
format_no_color = format_pre+format_post

FORMATS = {
logging.DEBUG: format_pre + blue + format_post,
Expand All @@ -48,7 +50,7 @@
class LoggingFormatter(logging.Formatter):

def format(self, record):
log_fmt = FORMATS.get(record.levelno)
log_fmt = FORMATS.get(record.levelno) if config.enable_color else format_no_color
formatter = logging.Formatter(log_fmt)
return formatter.format(record)

Expand All @@ -68,11 +70,19 @@ def border_print(to_print: str, important: bool = False) -> None:
len_borders = len(to_print)
border = f"\n{'_' * len_borders}\n"
i_border = f"\n{'!' * len_borders}\n" if important else ""
print(f"\x1b[35;1m{border}{i_border}{to_print}{i_border}{border}\x1b[0m")
if config.enable_color:
print("\x1b[35;1m")
print(f"{border}{i_border}{to_print}{i_border}{border}")
if config.enable_color:
print("\x1b[0m")


def print_and_write(to_print: str, file: TextIO) -> None:
print(f"\x1b[32;1m{to_print}\x1b[0m")
if config.enable_color:
print("\x1b[32;1m")
print(f"{to_print}")
if config.enable_color:
print("\x1b[0m")
file.write(to_print)


Expand Down

0 comments on commit 85517ff

Please sign in to comment.