#!/usr/bin/env python

"""
A class for logging... no, not timber
"""

import logging

# class Logger(object):
#     level_relations = {
#         'debug': logging.DEBUG,
#         'info': logging.INFO,
#         'warning': logging.WARNING,
#         'error': logging.ERROR,
#         'crit': logging.CRITICAL
#     }  # relationship mapping
#
#     def __init__(self, filename, level='info', when='D', backCount=3,
#                  fmt='%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s'):
#         self.logger = logging.getLogger(filename)
#         format_str = logging.Formatter(fmt)  # Setting the log format
#         self.logger.setLevel(self.level_relations.get(level))  # Setting the log level
#         console_handler = logging.StreamHandler()  # on-screen output
#         console_handler .setFormatter(format_str)  # Setting the format
#         th = logging.handlers.TimedRotatingFileHandler(filename=filename, when=when, backupCount=backCount,encoding='utf-8')  # automatically generates the file at specified intervals
#         th.setFormatter(format_str)  # Setting the format
#         self.logger.addHandler(console_handler)  # Add the object to the logger
#         self.logger.addHandler(th)

def timber(name):
    file_formatter = logging.Formatter('%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s')
    file_handler = logging.FileHandler("log/all.log")
    file_handler.setLevel(logging.DEBUG)
    file_handler.setFormatter(file_formatter)

    console_handler = logging.StreamHandler()
    console_handler.setLevel(logging.INFO)
    console_handler.setFormatter(file_formatter)

    logger = logging.getLogger(name)
    logger.addHandler(file_handler)
    logger.addHandler(console_handler)
    logger.setLevel(logging.DEBUG)

    return logger
