# -*- coding: utf-8 -*-
import logging
import sys

class Logger():
    def __init__(self, logname = 'default', filename = None):
        self.logger = logging.getLogger(logname)
        self.logger.setLevel(logging.DEBUG)
        
        console = logging.StreamHandler(sys.stdout)
        console.setLevel(logging.DEBUG)
        formatter = logging.Formatter('[%(asctime)s.%(msecs)03d] %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
        console.setFormatter(formatter)        
        self.logger.addHandler(console)
        
        if filename is None:
            return
        else:
            self.setFilePath(filename)    
        
    def setFilePath(self, filename):
        filehandler = logging.FileHandler(filename)
        filehandler.setLevel(logging.DEBUG)
        formatter = logging.Formatter('[%(asctime)s.%(msecs)03d] [%(name)s - %(levelname)s] %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
        filehandler.setFormatter(formatter)        
        self.logger.addHandler(filehandler)

    def log(self, msg):
        self.logger.debug(msg)

    def msg(self, msg):
        self.logger.debug(msg)
        
    def test(self):
        self.log('Test string 1')
        self.log('Test string 2')
        self.log('Test string 3')
        
logger = Logger(logname = 'Medialog')
log = logger.log

def main():
    sys.exit(0)

if __name__ == '__main__':
    main()
    

