mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-14 05:47:14 +02:00
moved log out to utils
This commit is contained in:
41
tests/scripts/utils_for_test.py
Normal file
41
tests/scripts/utils_for_test.py
Normal file
@ -0,0 +1,41 @@
|
||||
# SPDX-License-Identifier: LGPL-3.0-or-other
|
||||
# Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||
'''
|
||||
This file is used for common utils used for integration tests between simulators and receivers.
|
||||
'''
|
||||
|
||||
import sys
|
||||
from enum import Enum
|
||||
from colorama import Fore, Style, init
|
||||
|
||||
init(autoreset=True)
|
||||
|
||||
class LogLevel(Enum):
|
||||
INFO = 0
|
||||
INFORED = 1
|
||||
INFOGREEN = 2
|
||||
INFOBLUE = 3
|
||||
WARNING = 4
|
||||
ERROR = 5
|
||||
DEBUG = 6
|
||||
|
||||
LOG_LABELS = {
|
||||
LogLevel.WARNING: "WARNING: ",
|
||||
LogLevel.ERROR: "ERROR: ",
|
||||
LogLevel.DEBUG: "DEBUG: "
|
||||
}
|
||||
|
||||
LOG_COLORS = {
|
||||
LogLevel.INFO: Fore.WHITE,
|
||||
LogLevel.INFORED: Fore.RED,
|
||||
LogLevel.INFOGREEN: Fore.GREEN,
|
||||
LogLevel.INFOBLUE: Fore.BLUE,
|
||||
LogLevel.WARNING: Fore.YELLOW,
|
||||
LogLevel.ERROR: Fore.RED,
|
||||
LogLevel.DEBUG: Fore.CYAN
|
||||
}
|
||||
|
||||
def Log(level: LogLevel, message: str, stream=sys.stdout):
|
||||
color = LOG_COLORS.get(level, Fore.WHITE)
|
||||
label = LOG_LABELS.get(level, "")
|
||||
print(f"{color}{label}{message}{Style.RESET_ALL}", file=stream, flush=True)
|
Reference in New Issue
Block a user