Created
October 1, 2013 06:08
-
-
Save dmptrluke/6774460 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import logging | |
import config | |
class Bot(object): | |
def __init__(self, name): | |
# basic variables | |
self.name = name | |
self.start_time = time.time() | |
# set up config and logging | |
self.setup() | |
print self.config | |
def setup(self): | |
# logging | |
self.logger = self.get_logger() | |
self.logger.debug("Logging engine started.") | |
# logging | |
self.config = self.get_config() | |
self.config.reload() | |
self.logger.debug("Config loaded.") | |
def get_config(self): | |
return config.Config(self.name) | |
def get_logger(self): | |
# create logger | |
logger = logging.getLogger(self.name) | |
logger.setLevel(logging.DEBUG) | |
# add a file handler | |
log_name = "{}.log".format(self.name) | |
fh = logging.FileHandler(log_name) | |
fh.setLevel(logging.DEBUG) | |
# create a formatter and set the formatter for the handler. | |
frmt = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s') | |
fh.setFormatter(frmt) | |
# add the Handler to the logger | |
logger.addHandler(fh) | |
return logger |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment