from enum import Enum

from core.eventbus import EventPrintLog, event_bus
import config


class LogLevel(Enum):
    DEBUG = 0
    INFO = 1
    WARNING = 2
    ERROR = 3
    CRITICAL = 4
    
    def __le__(self, other):
        return self.value <= other.value

class LogData:
    def __init__(self, level:LogLevel, message:str):
        self.level = level
        self.message = message

def PrintLog(level:LogLevel, message:str):
    data = LogData(level, message)
    event_bus.publish(EventPrintLog, data)
    if config.console_log:
        print(f'{level.name} {message}')
