<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import logging <EOL> from salt . ext . six . moves import StringIO <EOL> from salttesting . case import TestCase <EOL> from salttesting . helpers import ensure_in_syspath , TestsLoggingHandler <EOL> ensure_in_syspath ( '<STR_LIT>' ) <EOL> from salt . log import setup as saltlog <EOL> from salt . log . handlers import StreamHandler <EOL> class TestLog ( TestCase ) : <EOL> '''<STR_LIT>''' <EOL> def test_issue_2853_regex_TypeError ( self ) : <EOL> log = saltlog . SaltLoggingClass ( __name__ ) <EOL> log_format = '<STR_LIT>' <EOL> handler = TestsLoggingHandler ( format = log_format ) <EOL> log . addHandler ( handler ) <EOL> with handler : <EOL> try : <EOL> saltlog . SaltLoggingClass ( '<STR_LIT>' . format ( __name__ ) ) <EOL> except Exception as err : <EOL> raise AssertionError ( <EOL> '<STR_LIT>' . format ( err ) <EOL> ) <EOL> log . removeHandler ( handler ) <EOL> log_format = '<STR_LIT>' <EOL> handler = TestsLoggingHandler ( format = log_format ) <EOL> log . addHandler ( handler ) <EOL> with handler : <EOL> try : <EOL> saltlog . SaltLoggingClass ( '<STR_LIT>' . format ( __name__ ) ) <EOL> except Exception as err : <EOL> raise AssertionError ( <EOL> '<STR_LIT>' . format ( err ) <EOL> ) <EOL> log . removeHandler ( handler ) <EOL> def test_exc_info_on_loglevel ( self ) : <EOL> def raise_exception_on_purpose ( ) : <EOL> <NUM_LIT:1> / <NUM_LIT:0> <EOL> log = saltlog . SaltLoggingClass ( __name__ ) <EOL> stream1 = StringIO ( ) <EOL> stream2 = StringIO ( ) <EOL> handler1 = StreamHandler ( stream1 ) <EOL> handler2 = StreamHandler ( stream2 ) <EOL> handler1 . setLevel ( logging . INFO ) <EOL> handler2 . setLevel ( logging . DEBUG ) <EOL> log . addHandler ( handler1 ) <EOL> log . addHandler ( handler2 ) <EOL> try : <EOL> raise_exception_on_purpose ( ) <EOL> except ZeroDivisionError as exc : <EOL> log . error ( '<STR_LIT>' , <EOL> exc_info_on_loglevel = logging . DEBUG ) <EOL> try : <EOL> self . assertIn ( <EOL> '<STR_LIT>' , <EOL> stream1 . getvalue ( ) <EOL> ) <EOL> self . assertNotIn ( '<STR_LIT>' , stream1 . getvalue ( ) ) <EOL> self . assertIn ( <EOL> '<STR_LIT>' , <EOL> stream2 . getvalue ( ) <EOL> ) <EOL> self . assertIn ( '<STR_LIT>' , stream2 . getvalue ( ) ) <EOL> finally : <EOL> log . removeHandler ( handler1 ) <EOL> log . removeHandler ( handler2 ) <EOL> stream1 = StringIO ( ) <EOL> stream2 = StringIO ( ) <EOL> handler1 = StreamHandler ( stream1 ) <EOL> handler2 = StreamHandler ( stream2 ) <EOL> handler1 . setLevel ( logging . INFO ) <EOL> handler2 . setLevel ( logging . DEBUG ) <EOL> log . addHandler ( handler1 ) <EOL> log . addHandler ( handler2 ) <EOL> try : <EOL> raise_exception_on_purpose ( ) <EOL> except ZeroDivisionError as exc : <EOL> log . error ( '<STR_LIT>' , <EOL> exc_info_on_loglevel = logging . INFO ) <EOL> try : <EOL> self . assertIn ( <EOL> '<STR_LIT>' , <EOL> stream1 . getvalue ( ) <EOL> ) <EOL> self . assertIn ( '<STR_LIT>' , stream1 . getvalue ( ) ) <EOL> self . assertIn ( <EOL> '<STR_LIT>' , <EOL> stream2 . getvalue ( ) <EOL> ) <EOL> self . assertIn ( '<STR_LIT>' , stream2 . getvalue ( ) ) <EOL> finally : <EOL> log . removeHandler ( handler1 ) <EOL> log . removeHandler ( handler2 ) <EOL> stream1 = StringIO ( ) <EOL> stream2 = StringIO ( ) <EOL> handler1 = StreamHandler ( stream1 ) <EOL> handler2 = StreamHandler ( stream2 ) <EOL> handler1 . setLevel ( logging . ERROR ) <EOL> handler2 . setLevel ( logging . INFO ) <EOL> log . addHandler ( handler1 ) <EOL> log . addHandler ( handler2 ) <EOL> try : <EOL> raise_exception_on_purpose ( ) <EOL> except ZeroDivisionError as exc : <EOL> log . error ( '<STR_LIT>' , <EOL> exc_info_on_loglevel = logging . DEBUG ) <EOL> try : <EOL> self . assertIn ( <EOL> '<STR_LIT>' , <EOL> stream1 . getvalue ( ) <EOL> ) <EOL> self . assertNotIn ( '<STR_LIT>' , stream1 . getvalue ( ) ) <EOL> self . assertIn ( <EOL> '<STR_LIT>' , <EOL> stream2 . getvalue ( ) <EOL> ) <EOL> self . assertNotIn ( '<STR_LIT>' , stream2 . getvalue ( ) ) <EOL> finally : <EOL> log . removeHandler ( handler1 ) <EOL> log . removeHandler ( handler2 ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from integration import run_tests <EOL> run_tests ( TestLog , needs_daemon = False ) </s>
