def _getRulesPath(): d = config.get('rulesdir') if not d: raise Exception('Must configure main.rulesdir in chains.conf') if not os.path.exists(d): raise Exception('No such rulesdir: %s' % d) return d
def _getLogPath(serviceId, filename=None): '''Get path to log dir or file for service(s)''' dir = '%s/services' % _config.get('logdir') if filename: dir += '/' + serviceId if not os.path.exists(dir): os.makedirs(dir) if not filename: filename = '%s.log' % serviceId return '%s/%s' % (dir, filename)
def _getClassConfigPath(serviceClass=None): '''Get path to config dir or file for service class(es)''' f = '%s/config/service-classes' % _config.get('libdir') if not os.path.exists(f): os.makedirs(f) if serviceClass: f = '%s/%s.conf' % (f, serviceClass) return f
def onInit(self): self.loggers = {} self.logdir = '' # Get relative or absolute logdir from config try: self.logdir = self.config.get('logdir') # Use blank if not defined except KeyError: pass # Get absolute logdir if not self.logdir or self.logdir == '': # Log path root if logdir explicitly defined as empty self.logdir = config.get('logdir') elif self.logdir[0] != '/': # Or log path + logdir if logdir defined self.logdir = '%s/%s' % (config.get('logdir'), self.logdir) # Or absolute path if logdir starts with / log.info('Using logdir: %s' % self.logdir)
def getCommandDirs(): dirs = [] # If user has configured custom commands dir items = config.data('commandline') if items: for key in items: tmp = key.split('.') if len(tmp) == 2 and tmp[0] == 'commands': dirs.append( items[key] + '/commands' ) # Build in commands dirs.append( config.get('libdir') + '/commandline/commands' ) return dirs
def getUuidFile(serviceId): dir = '%s/service-uuids' % _config.get('datadir') if not os.path.exists(dir): os.makedirs(dir) return '%s/%s' % (dir, serviceId)
def getSharePath(serviceClass): '''Get path to a service's share dir''' dir = '%s/services/%s' % (_config.get('sharedir'), serviceClass) if not os.path.exists(dir): os.makedirs(dir) return dir
def getDataPath(serviceId): '''Get path to a service's data dir''' dir = '%s/services/%s' % (_config.get('datadir'), serviceId) if not os.path.exists(dir): os.makedirs(dir) return dir
def setFileName(name): if not os.path.exists(config.get("logdir")): os.makedirs(config.get("logdir")) setFilePath(config.get("logdir") + "/" + name + ".log")
for item in arg: result.append(formatMessageItem(item)) return json.dumps(result) else: return json.dumps(arg) # can pass f.ex. __name__ to getLogger() to get per-module logmsgs, # but we don't initialize logger from inside modules logger = logging.getLogger() # Start with a basic print-to-console handler consoleHandler = logging.StreamHandler() # formatter = logging.Formatter('%(asctime)s %(levelname)-10s %(name)-20s %(message)s') formatter = logging.Formatter("%(asctime)s %(levelname)-10s %(message)s") consoleHandler.setFormatter(formatter) logger.addHandler(consoleHandler) level = config.get("loglevel") setLevel(level) if __name__ == "__main__": print "loglevel: %s" % level debug("debug") info("info") warn("warn") error("error")
def getDataDir(self): serviceId = self.get('id') dir = '%s/services/%s' % (_config.get('datadir'), serviceId) if not os.path.exists(dir): os.makedirs(dir) return dir