uv-belichter-software/utils.py

30 lines
1.3 KiB
Python

"""
uv-belichter-software - Some utilities for better customization and modularization
Copyright (C) 2024 Benjamin Burkhardt
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import config as cfg
from time import sleep
"""
Very simple logging function
Overall log level can be specified in config.py
"""
def log(log_level: int, message: str):
log_mapping = {0: "WARN", 1: "INFO", 2: "DEBUG"}
log_level = int(log_level) # make sure log_level is an integer
if log_level not in [0, 1, 2]:
print(f"[LOGGER] Got a message of unknown log level ({log_level}). Original message is printed below.")
print(f"{message}")
elif cfg.LOG_LEVEL >= log_level: # if log level is valid
print(f"[{log_mapping[log_level]}] {message}")