"""
Logger
======

The Logger class provides shortcuts for colorized logs generated by objects
and the CLI.
"""

from datetime import datetime
from click import secho, style


class Logger(object):
    """
    :param name: The name for the parser. Used to identify different objects,
    such as various workers.
    :type name: str
    """

    format_str = "[{level}] {ts} {name} - {msg}"
    INFO = 'cyan'
    FAIL = 'red'
    OKAY = 'green'
    WARN = 'yellow'

    def __init__(self, name):
        self.name = str(name)

    def log(self, level, message):
        ts = str(datetime.now())[11:-4]
        name = style(self.name, bold=True)
        res = self.format_str.format(
            level=level,
            msg=message,
            name=name,
            ts=ts
        )
        secho(res)

    def info(self, message):
        level = style('INFO', bold=True, fg=self.INFO)
        self.log(level, message)

    def okay(self, message):
        level = style('OKAY', bold=True, fg=self.OKAY)
        self.log(level, message)

    def fail(self, message):
        level = style('FAIL', bold=True, fg=self.FAIL)
        self.log(level, message)

    def warn(self, message):
        level = style('WARN', bold=True, fg=self.WARN)
        self.log(level, message)
