Skip to content

Commit

Permalink
Move logging
Browse files Browse the repository at this point in the history
  • Loading branch information
aBozowski committed Oct 24, 2023
1 parent 9df3206 commit 5b6b325
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 28 deletions.
2 changes: 0 additions & 2 deletions src/tools/interop/idt/capture/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@

import logging

log_level = logging.INFO
async_timeout = 45.0
enable_color = True
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

import os

from capture.utils import log
import log
from capture.utils.artifact import create_standard_log_name
from capture.utils.log import print_and_write, add_border
from log import print_and_write, add_border
from capture.platform.android import Android

logger = log.get_logger(__file__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from .command_map import dumpsys, getprop
from .prober import PlayServicesProber

from capture.utils import log
import log

logger = log.get_logger(__file__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import os

from capture.utils.shell import Bash
from capture.utils import log
import log

logger = log.get_logger(__file__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from capture.base import EcosystemCapture, UnsupportedCapturePlatformException
from capture.utils.artifact import create_standard_log_name
from capture.utils.log import print_and_write
from log import print_and_write
from capture.platform.android.android import Android


Expand Down
4 changes: 2 additions & 2 deletions src/tools/interop/idt/capture/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
from capture.utils.async_control import get_timeout
from capture.base import EcosystemCapture, PlatformLogStreamer, UnsupportedCapturePlatformException
from capture.utils.artifact import safe_mkdir
from capture.utils.log import border_print
from capture.utils import log
from log import border_print
import log

_PLATFORM_MAP: typing.Dict[str, PlatformLogStreamer] = {}
_ECOSYSTEM_MAP: typing.Dict[str, PlatformLogStreamer] = {}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/interop/idt/capture/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import traceback
from typing import Any

from capture.utils import log
import log

logger = log.get_logger(__file__)

Expand Down
2 changes: 1 addition & 1 deletion src/tools/interop/idt/capture/pcap/pcap.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from capture.utils.artifact import create_standard_log_name
from capture.utils.shell import Bash

from capture.utils import log
import log

logger = log.get_logger(__file__)

Expand Down
2 changes: 1 addition & 1 deletion src/tools/interop/idt/capture/platform/android/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from . import streams
from .capabilities import Capabilities

from capture.utils import log
import log

logger = log.get_logger(__file__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
if TYPE_CHECKING:
from capture.platform.android import Android

from capture.utils import log
import log
from . import config

logger = log.get_logger(__file__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from typing import TYPE_CHECKING
from ..base import AndroidStream

from capture.utils import log
import log

logger = log.get_logger(__file__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
if TYPE_CHECKING:
from capture.platform.android import Android

from capture.utils import log
import log

logger = log.get_logger(__file__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
if TYPE_CHECKING:
from capture.platform.android import Android

from capture.utils import log
import log

logger = log.get_logger(__file__)

Expand Down
3 changes: 1 addition & 2 deletions src/tools/interop/idt/capture/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
# limitations under the License.
#

from . import artifact, async_control, log, shell
from . import artifact, async_control, shell

__all__ = [
'artifact',
'async_control',
'log',
'shell',
]
2 changes: 1 addition & 1 deletion src/tools/interop/idt/capture/utils/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import time
from multiprocessing import Process
from pathlib import Path
from . import log
import log

logger = log.get_logger(__file__)

Expand Down
2 changes: 1 addition & 1 deletion src/tools/interop/idt/capture/utils/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from mobly.utils import stop_standing_subprocess

from capture.utils import log
import log

logger = log.get_logger(__file__)

Expand Down
20 changes: 20 additions & 0 deletions src/tools/interop/idt/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# Copyright (c) 2023 Project CHIP Authors
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import logging

enable_color = True
log_level = logging.INFO
6 changes: 4 additions & 2 deletions src/tools/interop/idt/idt.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
import sys
from pathlib import Path

import config
from capture import EcosystemController, EcosystemFactory, PacketCaptureRunner, PlatformFactory
from capture.utils.artifact import create_file_timestamp, safe_mkdir
from capture.utils.log import border_print
from log import border_print
from discovery import MatterBleScanner, MatterDnssdListener

splash = '''\x1b[0m
Expand All @@ -43,7 +44,8 @@
class InteropDebuggingTool:

def __init__(self) -> None:
print(splash)
if config.enable_color:
print(splash)
self.artifact_dir = None
create_artifact_dir = True
if len(sys.argv) == 1:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import logging
from typing import TextIO

from .. import config
import config

_CONFIG_LEVEL = config.log_level

Expand Down Expand Up @@ -71,21 +71,20 @@ def border_print(to_print: str, important: bool = False) -> None:
border = f"\n{'_' * len_borders}\n"
i_border = f"\n{'!' * len_borders}\n" if important else ""
if config.enable_color:
print("\x1b[35;1m", end="")
print(magenta, end="")
print(f"{border}{i_border}{to_print}{i_border}{border}")
if config.enable_color:
print("\x1b[0m", end="")
print(reset, end="")


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


def add_border(to_print: str) -> str:
"""Add star borders to important strings"""
return '\n' + '*' * len(to_print) + '\n' + to_print

0 comments on commit 5b6b325

Please sign in to comment.