예제 #1
0
파일: log.py 프로젝트: intracer/hashtags
def set_debug(enable=True):
    if not enable:
        raise NotImplementedError()
    dbg_fmtr = file_fmt
    dbg_emtr = StreamEmitter('stderr')

    dbg_sink = SensibleSink(formatter=dbg_fmtr, emitter=dbg_emtr)
    tlog.add_sink(dbg_sink)
예제 #2
0
def build_stream_sink(stream):
    emt = StreamEmitter(stream)
    file_filter = SensibleFilter(success='info',
                                 failure='debug',
                                 exception='debug')
    file_sink = SensibleSink(formatter=file_fmt,
                             emitter=emt,
                             filters=[file_filter])
    return file_sink
예제 #3
0
def _test_exception():
    _tmpl = ('{iso_end} - {exc_type}: {exc_message}'
             ' - {func_name}:{line_number} - {exc_tb_list}')
    sink = SensibleSink(SF(_tmpl),
                        StreamEmitter('stderr'),
                        filters=[SensibleFilter(exception=0)])
    logger = Logger('excelsilog', [sink])
    with logger.info('A for Effort', reraise=False) as tr:
        print tr
        raise ValueError('E for Exception')
    return
예제 #4
0
파일: mw.py 프로젝트: aissatech/montage
    def _setup_api_log(self):
        self.log_file_obj = open(self.log_path, 'ab')
        self.exc_log_file_obj = open(self.exc_log_path, 'ab')

        self.api_log = Logger(self.act_name.lower() + '_log')
        self._api_fmtr = SensibleFormatter(API_LOG_FMT)
        self._api_emtr = StreamEmitter(self.log_file_obj)
        self._api_fltr = SensibleFilter(success='info',
                                        failure='debug',
                                        exception='debug')
        self._api_sink = SensibleSink(formatter=self._api_fmtr,
                                      emitter=self._api_emtr,
                                      filters=[self._api_fltr])
        self.api_log.add_sink(self._api_sink)

        self._exc_emtr = StreamEmitter(self.exc_log_file_obj)
        self._exc_fltr = SensibleFilter(success=None,
                                        failure=None,
                                        exception='info')
        self._exc_sink = SensibleSink(formatter=self._api_fmtr,
                                      emitter=self._exc_emtr,
                                      filters=[self._exc_fltr])
        self.api_log.add_sink(self._exc_sink)
예제 #5
0
def _on_import_log_setup():
    # called at the bottom of the module
    stderr_fmtr = CompactFormatter()
    stderr_emtr = StreamEmitter('stderr', sep='')
    stderr_filter = SensibleFilter(begin='info',
                                   success='info',
                                   failure='info',
                                   exception='debug')
    stderr_sink = SensibleSink(formatter=stderr_fmtr,
                               emitter=stderr_emtr,
                               filters=[stderr_filter])
    sky_log.add_sink(stderr_sink)
    sky_log.add_sink(DevDebugSink(post_mortem=bool(os.getenv('SKY_DEBUG'))))
    sky_log.debug('sky_log_initialization').success()
    return
예제 #6
0
def build_file_enabled_logger(log_file):
    # TODO: make idempotent
    file_emtr = StreamEmitter(log_file)
    file_fmtr = SensibleFormatter(fmt, comment=comment_fmt, begin=begin_fmt)
    file_filter = SensibleFilter(begin='debug',
                                 success='debug',
                                 failure='debug',
                                 exception='debug')
    file_sink = SensibleSink(formatter=file_fmtr,
                             emitter=file_emtr,
                             filters=[file_filter])
    sky_log.add_sink(file_sink)

    log_file_path = getattr(log_file, 'name', None)
    sky_log.info('sky_log_file_initialization',
                 path='file://' + log_file_path).success()
    sky_log.log_file_path = log_file_path

    return sky_log
예제 #7
0
def test_stale_stream(tmpdir):
    # make mock filestream with write/flush that goes stale after 100 writes
    # create logger with stream emitter to mocked file stream
    class StalewardFile(file):
        def __init__(self, *a, **kw):
            file.__init__(self, *a, **kw)
            self._write_count = 0

        def write(self, *a, **kw):
            self._write_count += 1
            if self._write_count > 100:
                exc = IOError('stale file handle')
                exc.errno = errno.ESTALE
                self.close()
                raise exc
            return file.write(self, *a, **kw)

    file_path = '%s/not_always_fresh.log' % (tmpdir, )
    stale_file_obj = StalewardFile(file_path, 'wb')
    emitter = StreamEmitter(stale_file_obj)

    sink = SensibleSink(SF('{status_char} - {iso_end}'),
                        emitter,
                        filters=[SensibleFilter(success=True)])
    logger = Logger('excelsilog', [sink])

    assert emitter.stream is stale_file_obj

    for i in range(200):
        logger.info('yay').success()

    lines = open(file_path).read().splitlines()
    assert len(lines) == 200
    assert len(lines[0]) == len(lines[-1])
    assert stale_file_obj.closed
    assert emitter.stream is not stale_file_obj
예제 #8
0
파일: log.py 프로젝트: ra2003/chert
fmt = ('{status_char}+{import_delta_s}'
       ' - {duration_ms:>8.3f}ms'
       ' - {parent_depth_indent}{end_message}')

begin_fmt = ('{status_char}+{import_delta_s}'
             ' --------------'
             ' {parent_depth_indent}{begin_message}')

stderr_fmtr = SensibleFormatter(fmt, begin=begin_fmt)
stderr_emtr = StreamEmitter('stderr')
stderr_filter = SensibleFilter(success='info',
                               failure='debug',
                               exception='debug')
stderr_sink = SensibleSink(formatter=stderr_fmtr,
                           emitter=stderr_emtr,
                           filters=[stderr_filter])
chert_log.add_sink(stderr_sink)

try:
    from lithoxyl.emitters import SyslogEmitter
except Exception:
    pass
else:
    syslog_filter = SensibleFilter(success='critical',
                                   failure='critical',
                                   exception='critical')
    syslog_emt = SyslogEmitter('chert')
    syslog_sink = SensibleSink(formatter=stderr_fmtr,
                               emitter=syslog_emt,
                               filters=[syslog_filter])
예제 #9
0
# -*- coding: utf-8 -*-

from lithoxyl import (SensibleSink,
                      SensibleFilter,
                      SensibleFormatter as SF,
                      SensibleMessageFormatter as SMF)
from lithoxyl.emitters import StreamEmitter, AggregateEmitter
from lithoxyl.logger import Logger


fmtr = SF('{status_char}{begin_timestamp}')
strm_emtr = StreamEmitter('stderr')
fltr = SensibleFilter('debug')
aggr_emtr = AggregateEmitter()
strm_sink = SensibleSink(formatter=fmtr, emitter=strm_emtr)
fake_sink = SensibleSink(filters=[fltr], formatter=fmtr, emitter=aggr_emtr)


def test_sensible_basic():
    log = Logger('test_ss', [strm_sink, fake_sink])

    print

    log.debug('greet').success('hey')
    assert aggr_emtr.get_entry(-1).startswith('s')

    with log.debug('greet') as t:
        t.success('hello')
        t.warn("everything ok?")

    assert aggr_emtr.get_entry(-1).startswith('S')
예제 #10
0
    def __init__(self, filepath, encoding=None, **kwargs):
        self.encoding = encoding
        super(FixedFileEmitter, self).__init__(filepath, encoding, **kwargs)

CUR_PATH = os.path.dirname(os.path.abspath(__file__))
LOG_FILE_PATH = os.path.join(CUR_PATH, 'logs', 'update_log.txt')

tlog = Logger('toplog')

file_fmt = SensibleFormatter('{status_char}{iso_end_local_noms_notz} - {duration_s}s - {action_name} - {event_message}')
file_emt = FixedFileEmitter(LOG_FILE_PATH)
file_filter = SensibleFilter(success='critical',
                              failure='info',
                              exception='debug')
file_sink = SensibleSink(formatter=file_fmt,
                         emitter=file_emt,
                         filters=[file_filter])
tlog.add_sink(file_sink)


def set_debug(enable=True):
    if not enable:
        raise NotImplementedError()
    dbg_fmtr = file_fmt
    dbg_emtr = StreamEmitter('stderr')
    
    dbg_sink = SensibleSink(formatter=dbg_fmtr,
                            emitter=dbg_emtr)
    tlog.add_sink(dbg_sink)
    
예제 #11
0
import os

from lithoxyl import Logger, SensibleSink, Formatter, StreamEmitter
from lithoxyl.filters import ThresholdFilter

tlog = Logger('toplog')

stderr_fmt = Formatter('{status_char}{end_local_iso8601_noms_notz} - {duration_secs}s - {record_name} - {message}')
stderr_emt = StreamEmitter('stderr')
stderr_filter = ThresholdFilter(success='debug',
                                failure='debug',
                                exception='debug')
stderr_sink = SensibleSink(formatter=stderr_fmt,
                           emitter=stderr_emt,
                           filters=[stderr_filter])
#                           on=['begin', 'complete'])  # TODO: clunk
tlog.add_sink(stderr_sink)


class DevDebugSink(object):
    # TODO: configurable max number of traceback signatures, after
    #       which exit/ignore?

    def __init__(self, reraise=False, post_mortem=False):
        self.reraise = reraise
        self.post_mortem = post_mortem

    #def on_complete(self, record):
    #    some conditions and a pdb perhaps