Пример #1
0
 def sync(self, path=""):
     if not path:
         try: path = self._path
         except AttributeError: pass
     if not path: path = self._path = j(dopath(self), rtime())
     logging.warn("! sync %s" % path)
     d, fn = os.path.split(path)
     cdir(d)
     todisk = self.prepare()
     datafile = open(os.path.abspath(path) + ".tmp", 'w')
     fcntl.flock(datafile, fcntl.LOCK_EX | fcntl.LOCK_NB)
     datafile.write(headertxt % "%s characters" % len(todisk))
     datafile.write(todisk)
     datafile.write("\n")
     fcntl.flock(datafile, fcntl.LOCK_UN)
     datafile.close()
     os.rename(path + ".tmp", path)
     return path
Пример #2
0
Файл: log.py Проект: bthate/meds
def loglevel(loglevel, colors=True):
    logger = logging.getLogger("")
    if colors: formatter = Formatter(format, datefmt=datefmt)
    else: formatter = FormatterClean(format, datefmt=datefmt)
    level = LEVELS.get(str(loglevel).lower(), logging.NOTSET)
    filehandler = None
    logger.setLevel(level)
    if logger.handlers:
        for handler in logger.handlers: logger.removeHandler(handler)
    if not os.path.exists(logdir): cdir(logdir)
    try: filehandler = logging.handlers.TimedRotatingFileHandler(j(logdir, "meds.log"), 'midnight')
    except Exception as ex: logging.error(ex)
    ch = logging.StreamHandler()
    ch.setLevel(level)
    if colors: ch.setFormatter(formatter)
    else: ch.setFormatter(formatter)
    logger.addHandler(ch)
    if filehandler:
        ch.setFormatter(formatter)
        filehandler.setLevel(level)
        logger.addHandler(filehandler)
    global enabled
    enabled = True
    return logger
Пример #3
0
 def save(self, stime=""):
     if not stime: stime = rtime()
     path = j(dopath(self), stime)
     self.sync(path)
     return stime