from robot.api import logger

from .context import ContextAware


LOG_LEVELS = ['TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR']


class LibraryComponent(ContextAware):

    def __init__(self, context):
        ContextAware.__init__(self, context)

    @staticmethod
    def info(msg, html=False):
        logger.info(msg, html)

    @staticmethod
    def debug(msg, html=False):
        logger.debug(msg, html)

    @staticmethod
    def log(msg, level='INFO', html=False):
        if level.upper() in LOG_LEVELS:
            logger.write(msg, level, html)

    @staticmethod
    def warn(msg, html=False):
        logger.warn(msg, html)
