# Path: twiggy/logger.py
# def emit(level):
#     def decorator(f):
#         def wrapper(self, *args, **kwargs):
#     def __init__(self, fields=None, options=None, min_level=None):
#     def _clone(self):
#     def _emit(self, level, format_spec, args, kwargs):
#     def fields(self, **kwargs):
#     def fields_dict(self, d):
#     def options(self, **kwargs):
#     def trace(self, trace='error'):
#     def name(self, name):
#     def debug(self, format_spec='', *args, **kwargs):
#     def info(self, format_spec='', *args, **kwargs):
#     def notice(self, format_spec='', *args, **kwargs):
#     def warning(self, format_spec='', *args, **kwargs):
#     def error(self, format_spec='', *args, **kwargs):
#     def critical(self, format_spec='', *args, **kwargs):
#     def __init__(self, output, fields=None, options=None, min_level=None):
#     def _clone(self):
#     def _emit(self, level, format_spec, args, kwargs):
#     def _feature_noop(self, *args, **kwargs):
#     def addFeature(cls, func, name=None):
#     def disableFeature(cls, name):
#     def delFeature(cls, name):
#     def __init__(self, fields=None, options=None, emitters=None,
#                  min_level=None, filter=None):
#     def _clone(self):
#     def struct(self, **kwargs):
#     def struct_dict(self, d):
#     def _emit(self, level, format_spec, args, kwargs):
# class BaseLogger(object):
# class InternalLogger(BaseLogger):
# class Logger(BaseLogger):
# 
# Path: twiggy/outputs.py
# class Output(object):
# class AsyncOutput(Output):
# class NullOutput(Output):
# class ListOutput(Output):
# class FileOutput(AsyncOutput):
# class StreamOutput(Output):
#     def _noop_format(msg):
#     def __init__(self, format=None, close_atexit=True):
#     def _sync_init(self):
#     def _open(self):
#     def _close(self):
#     def _write(self, x):
#     def __sync_output_locked(self, msg):
#     def __sync_output_unlocked(self, msg):
#     def __init__(self, format=None, msg_buffer=0, close_atexit=True):
#     def _async_init(self, msg_buffer, close_atexit):
#     def __child_main(self):
#     def __async_output(self, msg):
#     def __async_close(self):
#     def _open(self):
#     def _write(self, msg):
#     def _close(self):
#     def _open(self):
#     def _write(self, msg):
#     def _close(self):
#     def __init__(self, name, format, mode='a', buffering=1, msg_buffer=0, close_atexit=True):
#     def _open(self):
#     def _close(self):
#     def _write(self, x):
#     def __init__(self, format, stream=sys.stderr):
#     def _open(self):
#     def _close(self):
#     def _write(self, x):
# 
# Path: twiggy/levels.py
# class LogLevelMeta(type):
# class LogLevel(with_metaclass(LogLevelMeta, object)):
#     def __new__(meta, name, bases, dct):
#     def __init__(self, name, value):
#     def __str__(self):
#     def __repr__(self):
#     def _lt(self, other):  # pragma: no py2 cover
#     def _le(self, other):  # pragma: no py2 cover
#     def _gt(self, other):  # pragma: no py2 cover
#     def _ge(self, other):  # pragma: no py2 cover
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __cmp__(self, other):  # pragma: no py3 cover
#     def __hash__(self):
# def name2level(name):
# DEBUG = LogLevel('DEBUG', 1)
# INFO = LogLevel('INFO', 2)
# NOTICE = LogLevel('NOTICE', 3)
# WARNING = LogLevel('WARNING', 4)
# ERROR = LogLevel('ERROR', 5)
# CRITICAL = LogLevel('CRITICAL', 6)
# DISABLED = LogLevel('DISABLED', 7)
# 
# Path: twiggy/filters.py
# def msg_filter(x):
# def list_wrapper(lst):
#     def wrapped(msg):
# def regex_wrapper(regexp):
#     def wrapped(msg):
# def names(*names):
#     def set_names_filter(msg):
# def glob_names(*names):
#     def glob_names_filter(msg):
#     def __init__(self, min_level, filter, output):
#     def filter(self):
#     def filter(self, f):
# class Emitter(object):


import itertools
import re
import sys
import pytest
import twiggy as _twiggy
    import unittest
        import unittest2 as unittest
from six import StringIO, string_types
from twiggy import logger, outputs, levels, filters

        print(m.text)
        print(m.traceback)
        print(_twiggy.internal_log._options)

        assert m.level == levels.INFO
        assert m.name == 'twiggy.internal'
        assert "Traceback" in m.traceback
        assert "BOOM" in m.traceback
        assert "Error formatting message" in m.text
        assert re.search("<function .*go_boom", m.text)

    def test_trap_output(self):
        class BorkedOutput(outputs.ListOutput):

            def _write(self, x):
                raise RuntimeError("BORK")

        out = BorkedOutput(close_atexit=False)

        def cleanup(output):
            try:
                del self.emitters['before']
            except KeyError:
                pass

            out.close()

        self.addCleanup(cleanup, out)


# Path: twiggy/logger.py
# def emit(level):
#     def decorator(f):
#         def wrapper(self, *args, **kwargs):
#     def __init__(self, fields=None, options=None, min_level=None):
#     def _clone(self):
#     def _emit(self, level, format_spec, args, kwargs):
#     def fields(self, **kwargs):
#     def fields_dict(self, d):
#     def options(self, **kwargs):
#     def trace(self, trace='error'):
#     def name(self, name):
#     def debug(self, format_spec='', *args, **kwargs):
#     def info(self, format_spec='', *args, **kwargs):
#     def notice(self, format_spec='', *args, **kwargs):
#     def warning(self, format_spec='', *args, **kwargs):
#     def error(self, format_spec='', *args, **kwargs):
#     def critical(self, format_spec='', *args, **kwargs):
#     def __init__(self, output, fields=None, options=None, min_level=None):
#     def _clone(self):
#     def _emit(self, level, format_spec, args, kwargs):
#     def _feature_noop(self, *args, **kwargs):
#     def addFeature(cls, func, name=None):
#     def disableFeature(cls, name):
#     def delFeature(cls, name):
#     def __init__(self, fields=None, options=None, emitters=None,
#                  min_level=None, filter=None):
#     def _clone(self):
#     def struct(self, **kwargs):
#     def struct_dict(self, d):
#     def _emit(self, level, format_spec, args, kwargs):
# class BaseLogger(object):
# class InternalLogger(BaseLogger):
# class Logger(BaseLogger):
# 
# Path: twiggy/outputs.py
# class Output(object):
# class AsyncOutput(Output):
# class NullOutput(Output):
# class ListOutput(Output):
# class FileOutput(AsyncOutput):
# class StreamOutput(Output):
#     def _noop_format(msg):
#     def __init__(self, format=None, close_atexit=True):
#     def _sync_init(self):
#     def _open(self):
#     def _close(self):
#     def _write(self, x):
#     def __sync_output_locked(self, msg):
#     def __sync_output_unlocked(self, msg):
#     def __init__(self, format=None, msg_buffer=0, close_atexit=True):
#     def _async_init(self, msg_buffer, close_atexit):
#     def __child_main(self):
#     def __async_output(self, msg):
#     def __async_close(self):
#     def _open(self):
#     def _write(self, msg):
#     def _close(self):
#     def _open(self):
#     def _write(self, msg):
#     def _close(self):
#     def __init__(self, name, format, mode='a', buffering=1, msg_buffer=0, close_atexit=True):
#     def _open(self):
#     def _close(self):
#     def _write(self, x):
#     def __init__(self, format, stream=sys.stderr):
#     def _open(self):
#     def _close(self):
#     def _write(self, x):
# 
# Path: twiggy/levels.py
# class LogLevelMeta(type):
# class LogLevel(with_metaclass(LogLevelMeta, object)):
#     def __new__(meta, name, bases, dct):
#     def __init__(self, name, value):
#     def __str__(self):
#     def __repr__(self):
#     def _lt(self, other):  # pragma: no py2 cover
#     def _le(self, other):  # pragma: no py2 cover
#     def _gt(self, other):  # pragma: no py2 cover
#     def _ge(self, other):  # pragma: no py2 cover
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __cmp__(self, other):  # pragma: no py3 cover
#     def __hash__(self):
# def name2level(name):
# DEBUG = LogLevel('DEBUG', 1)
# INFO = LogLevel('INFO', 2)
# NOTICE = LogLevel('NOTICE', 3)
# WARNING = LogLevel('WARNING', 4)
# ERROR = LogLevel('ERROR', 5)
# CRITICAL = LogLevel('CRITICAL', 6)
# DISABLED = LogLevel('DISABLED', 7)
# 
# Path: twiggy/filters.py
# def msg_filter(x):
# def list_wrapper(lst):
#     def wrapped(msg):
# def regex_wrapper(regexp):
#     def wrapped(msg):
# def names(*names):
#     def set_names_filter(msg):
# def glob_names(*names):
#     def glob_names_filter(msg):
#     def __init__(self, min_level, filter, output):
#     def filter(self):
#     def filter(self, f):
# class Emitter(object):


# Path: tests/test_logger.py
import itertools
import re
import sys
import pytest
import twiggy as _twiggy
    import unittest
        import unittest2 as unittest
from six import StringIO, string_types
from twiggy import logger, outputs, levels, filters


        print(m.text)
        print(m.traceback)
        print(_twiggy.internal_log._options)

        assert m.level == levels.INFO
        assert m.name == 'twiggy.internal'
        assert "Traceback" in m.traceback
        assert "BOOM" in m.traceback
        assert "Error formatting message" in m.text
        assert re.search("<function .*go_boom", m.text)

    def test_trap_output(self):
        class BorkedOutput(outputs.ListOutput):

            def _write(self, x):
                raise RuntimeError("BORK")

        out = BorkedOutput(close_atexit=False)

        def cleanup(output):
            try:
                del self.emitters['before']
            except KeyError:
                pass

            out.close()

        self.addCleanup(cleanup, out)


        self.emitters['before'] = filters.Emitter(levels.DEBUG, None, out)