"""
Name : Logger
Purpose : Collect logs and maintain log rotation
TODO : Enchantments
@author : Asiri Hewage SLIIT SE 2021
Last Update : 15/05/2020
"""

import logging
from logging.handlers import RotatingFileHandler
from .ConfigManager import ConfigManager


class Logger:
    def __init__(self):
        # get config
        self.conf = ConfigManager()
        self.Config = self.conf.get_configs()
        self.debug_level = self.Config.get('LOGGER', 'log_level')
        self.handlers = [
            RotatingFileHandler(filename=self.Config.get('LOGGER', 'logger_path'), mode='w', maxBytes=512000,
                                backupCount=4)
        ]
        logging.basicConfig(handlers=self.handlers, level=self.debug_level,
                            format=self.Config.get('LOGGER', 'logger_pattern'),
                            datefmt='%m/%d/%Y%I:%M:%S %p')

        self.logger = logging.getLogger(self.Config.get('LOGGER', 'logger_name'))

    def info(self, log):
        self.logger.info(str(log))

    def debug(self, log):
        self.logger.info(str(log))

    def error(self, log):
        self.logger.error(str(log))