Пример #1
0
def _bootstrap():
    """Get the Inyoka version and store it."""
    global INYOKA_REVISION

    # the path to the contents of the Inyoka module
    conts = os.environ.setdefault('INYOKA_MODULE',
                                  realpath(join(dirname(__file__))))
    # the path to the Inyoka instance folder
    os.environ['INYOKA_INSTANCE'] = realpath(join(conts, pardir))
    os.environ['CELERY_LOADER'] = 'inyoka.core.celery_support.CeleryLoader'

    # get the `INYOKA_REVISION` using the mercurial python api
    try:
        ui = hgui.ui()
        repository = localrepository(ui, join(conts, '..'))
        ctx = repository['tip']
        INYOKA_REVISION = ('%(num)s:%(id)s' % {
            'num': ctx.rev(),
            'id': shorthex(ctx.node())
        })
    except TypeError:
        # fail silently
        pass

    # This value defines the timeout for sockets in seconds.  Per default python
    # sockets do never timeout and as such we have blocking workers.
    # Socket timeouts are set globally within the whole application.
    # The value *must* be a floating point value.
    socket.setdefaulttimeout(10.0)

    #: bind the context
    ctx = ApplicationContext()
    ctx.bind()

    # setup components
    ctx.load_packages(ctx.cfg['activated_components'])
    if ctx.cfg['testing']:
        logger.level_name = 'ERROR'

    # makes INYOKA_REVISION visible in the extra dict of every log record
    proc = Processor(lambda x: x.extra.update(INYOKA_REVISION=INYOKA_REVISION))
    proc.push_application()
Пример #2
0
def _bootstrap():
    """Get the Inyoka version and store it."""
    global INYOKA_REVISION

    # the path to the contents of the Inyoka module
    conts = os.environ.setdefault("INYOKA_MODULE", realpath(join(dirname(__file__))))
    # the path to the Inyoka instance folder
    os.environ["INYOKA_INSTANCE"] = realpath(join(conts, pardir))
    os.environ["CELERY_LOADER"] = "inyoka.core.celery_support.CeleryLoader"

    # get the `INYOKA_REVISION` using the mercurial python api
    try:
        ui = hgui.ui()
        repository = localrepository(ui, join(conts, ".."))
        ctx = repository["tip"]
        INYOKA_REVISION = "%(num)s:%(id)s" % {"num": ctx.rev(), "id": shorthex(ctx.node())}
    except TypeError:
        # fail silently
        pass

    # This value defines the timeout for sockets in seconds.  Per default python
    # sockets do never timeout and as such we have blocking workers.
    # Socket timeouts are set globally within the whole application.
    # The value *must* be a floating point value.
    socket.setdefaulttimeout(10.0)

    #: bind the context
    ctx = ApplicationContext()
    ctx.bind()

    # setup components
    ctx.load_packages(ctx.cfg["activated_components"])
    if ctx.cfg["testing"]:
        logger.level_name = "ERROR"

    # makes INYOKA_REVISION visible in the extra dict of every log record
    proc = Processor(lambda x: x.extra.update(INYOKA_REVISION=INYOKA_REVISION))
    proc.push_application()
Пример #3
0
Файл: log.py Проект: mnms/LTCLI
        '{record.message}',
    ]),
}


def inject_extra(record):
    record.extra['basename'] = os.path.basename(record.filename)
    record.extra['level_color'] = get_log_color(record.level)
    record.extra['clear_color'] = color.ENDC


logger = Logger('root')

# extra info
processor = Processor(inject_extra)
processor.push_application()

# for screen log
screen_level = INFO
stream_handler = StreamHandler(sys.stdout, level=screen_level, bubble=True)
stream_handler.format_string = formatter['screen']
stream_handler.push_application()

# for rolling file log
p = os.environ['FBPATH']
if not os.path.isdir(p):
    os.system('mkdir -p {}'.format(p))
file_path = os.path.expanduser(os.path.join(p, 'logs'))
if os.path.isdir(file_path):
    backup_count = 7
    max_size = 1024 * 1024 * 1024  # 1Gi