def __init__(self, opts, name): self.name = name self.opts = opts self.logger = logging.getLogger(name) self.level = logging.DEBUG if self.opts.verbose else logging.INFO self.logger.setLevel(self.level) # create console handler ch = ColorizingStreamHandler() ch.setLevel(self.level) # create formatter and add it to the handlers #ch.setFormatter(logging.Formatter('%(message)s')) self.logger.addHandler(ch) # create file handler if self.opts.log: logfile = os.path.join(BASEDIR, 'box-sync.log') create_file(logfile) fh = logging.FileHandler(logfile) fh.setLevel(logging.DEBUG) fh.setFormatter( logging.Formatter( '[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s')) self.logger.addHandler(fh)
def check_file(self): """ Check for config file existance and create if it doesn't """ if create_file(self.filepath): self.out.info("Created configuration file '%s'" % self.filepath) self.write_default_config(self.filepath) sample_filepath = self.filepath+'.sample' if create_file(sample_filepath): self.out.info("Created example configuration file '%s'" % sample_filepath) self.write_default_config(sample_filepath) # Add all configured sections self.cfgparser = ConfigParser.SafeConfigParser() for section, options in self.options.items(): self.cfgparser.add_section(section) self.cfgparser.read(self.filepath)
def __init__(self, opts, name): self.name = name self.opts = opts self.logger = logging.getLogger(name) self.level = logging.DEBUG if self.opts.verbose else logging.INFO self.logger.setLevel(self.level) # create console handler ch = ColorizingStreamHandler() ch.setLevel(self.level) # create formatter and add it to the handlers #ch.setFormatter(logging.Formatter('%(message)s')) self.logger.addHandler(ch) # create file handler if self.opts.log: logfile = os.path.join(BASEDIR, 'box-sync.log') create_file(logfile) fh = logging.FileHandler(logfile) fh.setLevel(logging.DEBUG) fh.setFormatter(logging.Formatter('[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s')) self.logger.addHandler(fh)