Ejemplo n.º 1
0
def logging_setup(name, use_archiver=True, root=None, use_file=True, **kw):
    """
    """
    # set up deprecation warnings
    # import warnings
    #     warnings.simplefilter('default')
    bdir = paths.log_dir if root is None else root

    # make sure we have a log directory
    # if not os.path.isdir(bdir):
    #     os.mkdir(bdir)

    if use_archiver:
        # archive logs older than 1 month
        # lazy load Archive because of circular dependency
        from pychron.core.helpers.archiver import Archiver

        a = Archiver(archive_days=14, archive_months=1, root=bdir)
        a.clean()

    if use_file:
        # create a new logging file
        logname = '{}.current.log'.format(name)
        logpath = os.path.join(bdir, logname)

        if os.path.isfile(logpath):
            backup_logpath, _cnt = unique_path2(bdir,
                                                name,
                                                delimiter='-',
                                                extension='.log',
                                                width=5)

            shutil.copyfile(logpath, backup_logpath)
            os.remove(logpath)

            ps = list_directory(bdir,
                                filtername=logname,
                                remove_extension=False)
            for pi in ps:
                _h, t = os.path.splitext(pi)
                v = os.path.join(bdir, pi)
                shutil.copyfile(v, '{}{}'.format(backup_logpath, t))
                os.remove(v)

    root = logging.getLogger()
    root.setLevel(gLEVEL)
    shandler = logging.StreamHandler()

    handlers = [shandler]
    if use_file:
        rhandler = RotatingFileHandler(logpath, maxBytes=1e7, backupCount=50)
        handlers.append(rhandler)

    fmt = logging.Formatter(gFORMAT)
    for hi in handlers:
        hi.setLevel(gLEVEL)
        hi.setFormatter(fmt)
        root.addHandler(hi)
Ejemplo n.º 2
0
def logging_setup(name, **kw):
    '''
    '''
    from pychron.core.helpers.archiver import Archiver

    # set up deprecation warnings
#     import warnings
#     warnings.simplefilter('default')

    # make sure we have a log directory
    bdir = os.path.join(paths.root, 'logs')
    if not os.path.isdir(bdir):
        os.mkdir(bdir)

    # create a new logging file
    logname = '{}.current.log'.format(name)
    logpath = os.path.join(bdir, logname)

    if os.path.isfile(logpath):
        backup_logpath, _cnt = unique_path(bdir, name, extension='log')

        shutil.copyfile(logpath, backup_logpath)
        os.remove(logpath)

        # get all .# paths
        ps = list_directory(bdir, filtername=logname, remove_extension=False)
        for pi in ps:
            _h, t = os.path.splitext(pi)
            v = os.path.join(bdir, pi)
            shutil.copyfile(v, '{}{}'.format(backup_logpath, t))
            os.remove(v)

#    if sys.version.split(' ')[0] < '2.4.0':
#        logging.basicConfig()
#    else:
    root = logging.getLogger()
    root.setLevel(gLEVEL)
    shandler = logging.StreamHandler()
# #
# # #        global rhandler
    rhandler = RotatingFileHandler(
                    logpath, maxBytes=1e7, backupCount=5)
#
    for hi in (shandler, rhandler):
#        for hi in (rhandler,):
        hi.setLevel(gLEVEL)
        hi.setFormatter(logging.Formatter(gFORMAT))
        root.addHandler(hi)

#     new_logger('main')
    # archive logs older than 1 month
    a = Archiver(archive_days=30,
                 archive_months=6,
                 root=bdir
                 )
    a.clean(False)
Ejemplo n.º 3
0
def logging_setup(name, use_archiver=True, use_file=True, **kw):
    """
    """
    # set up deprecation warnings
    # import warnings
    #     warnings.simplefilter('default')

    bdir = paths.log_dir

    # make sure we have a log directory
    # if not os.path.isdir(bdir):
    #     os.mkdir(bdir)

    if use_archiver:
        # archive logs older than 1 month
        # lazy load Archive because of circular dependency
        from pychron.core.helpers.archiver import Archiver

        a = Archiver(archive_days=14,
                     archive_months=1,
                     root=bdir)
        a.clean()

    if use_file:
        # create a new logging file
        logname = '{}.current.log'.format(name)
        logpath = os.path.join(bdir, logname)

        if os.path.isfile(logpath):
            backup_logpath, _cnt = unique_path2(bdir, name, delimiter='-', extension='.log', width=5)

            shutil.copyfile(logpath, backup_logpath)
            os.remove(logpath)

            ps = list_directory(bdir, filtername=logname, remove_extension=False)
            for pi in ps:
                _h, t = os.path.splitext(pi)
                v = os.path.join(bdir, pi)
                shutil.copyfile(v, '{}{}'.format(backup_logpath, t))
                os.remove(v)

    root = logging.getLogger()
    root.setLevel(gLEVEL)
    shandler = logging.StreamHandler()

    handlers = [shandler]
    if use_file:
        rhandler = RotatingFileHandler(
            logpath, maxBytes=1e7, backupCount=5)
        handlers.append(rhandler)

    for hi in handlers:
        hi.setLevel(gLEVEL)
        hi.setFormatter(logging.Formatter(gFORMAT))
        root.addHandler(hi)
Ejemplo n.º 4
0
    def _video_archiver_default(self):
        from pychron.core.helpers.archiver import Archiver

        return Archiver()
Ejemplo n.º 5
0
 def _video_archiver_default(self):
     return Archiver()