<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , division , print_function , with_statement <EOL> import logging <EOL> import logging . handlers <EOL> import sys <EOL> from tornado . escape import _unicode <EOL> from tornado . util import unicode_type , basestring_type <EOL> try : <EOL> import curses <EOL> except ImportError : <EOL> curses = None <EOL> access_log = logging . getLogger ( "<STR_LIT>" ) <EOL> app_log = logging . getLogger ( "<STR_LIT>" ) <EOL> gen_log = logging . getLogger ( "<STR_LIT>" ) <EOL> def _stderr_supports_color ( ) : <EOL> color = False <EOL> if curses and hasattr ( sys . stderr , '<STR_LIT>' ) and sys . stderr . isatty ( ) : <EOL> try : <EOL> curses . setupterm ( ) <EOL> if curses . tigetnum ( "<STR_LIT>" ) > <NUM_LIT:0> : <EOL> color = True <EOL> except Exception : <EOL> pass <EOL> return color <EOL> def _safe_unicode ( s ) : <EOL> try : <EOL> return _unicode ( s ) <EOL> except UnicodeDecodeError : <EOL> return repr ( s ) <EOL> class LogFormatter ( logging . Formatter ) : <EOL> """<STR_LIT>""" <EOL> DEFAULT_FORMAT = '<STR_LIT>' <EOL> DEFAULT_DATE_FORMAT = '<STR_LIT>' <EOL> DEFAULT_COLORS = { <EOL> logging . DEBUG : <NUM_LIT:4> , <EOL> logging . INFO : <NUM_LIT:2> , <EOL> logging . WARNING : <NUM_LIT:3> , <EOL> logging . ERROR : <NUM_LIT:1> , <EOL> } <EOL> def __init__ ( self , color = True , fmt = DEFAULT_FORMAT , <EOL> datefmt = DEFAULT_DATE_FORMAT , colors = DEFAULT_COLORS ) : <EOL> r"""<STR_LIT>""" <EOL> logging . Formatter . __init__ ( self , datefmt = datefmt ) <EOL> self . _fmt = fmt <EOL> self . _colors = { } <EOL> if color and _stderr_supports_color ( ) : <EOL> fg_color = ( curses . tigetstr ( "<STR_LIT>" ) or <EOL> curses . tigetstr ( "<STR_LIT>" ) or "<STR_LIT>" ) <EOL> if ( <NUM_LIT:3> , <NUM_LIT:0> ) < sys . version_info < ( <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:3> ) : <EOL> fg_color = unicode_type ( fg_color , "<STR_LIT:ascii>" ) <EOL> for levelno , code in colors . items ( ) : <EOL> self . _colors [ levelno ] = unicode_type ( curses . tparm ( fg_color , code ) , "<STR_LIT:ascii>" ) <EOL> self . _normal = unicode_type ( curses . tigetstr ( "<STR_LIT>" ) , "<STR_LIT:ascii>" ) <EOL> else : <EOL> self . _normal = '<STR_LIT>' <EOL> def format ( self , record ) : <EOL> try : <EOL> message = record . getMessage ( ) <EOL> assert isinstance ( message , basestring_type ) <EOL> record . message = _safe_unicode ( message ) <EOL> except Exception as e : <EOL> record . message = "<STR_LIT>" % ( e , record . __dict__ ) <EOL> record . asctime = self . formatTime ( record , self . datefmt ) <EOL> if record . levelno in self . _colors : <EOL> record . color = self . _colors [ record . levelno ] <EOL> record . end_color = self . _normal <EOL> else : <EOL> record . color = record . end_color = '<STR_LIT>' <EOL> formatted = self . _fmt % record . __dict__ <EOL> if record . exc_info : <EOL> if not record . exc_text : <EOL> record . exc_text = self . formatException ( record . exc_info ) <EOL> if record . exc_text : <EOL> lines = [ formatted . rstrip ( ) ] <EOL> lines . extend ( _safe_unicode ( ln ) for ln in record . exc_text . split ( '<STR_LIT:\n>' ) ) <EOL> formatted = '<STR_LIT:\n>' . join ( lines ) <EOL> return formatted . replace ( "<STR_LIT:\n>" , "<STR_LIT>" ) <EOL> def enable_pretty_logging ( options = None , logger = None ) : <EOL> """<STR_LIT>""" <EOL> if options is None : <EOL> from tornado . options import options <EOL> if options . logging is None or options . logging . lower ( ) == '<STR_LIT:none>' : <EOL> return <EOL> if logger is None : <EOL> logger = logging . getLogger ( ) <EOL> logger . setLevel ( getattr ( logging , options . logging . upper ( ) ) ) <EOL> if options . log_file_prefix : <EOL> channel = logging . handlers . RotatingFileHandler ( <EOL> filename = options . log_file_prefix , <EOL> maxBytes = options . log_file_max_size , <EOL> backupCount = options . log_file_num_backups ) <EOL> channel . setFormatter ( LogFormatter ( color = False ) ) <EOL> logger . addHandler ( channel ) <EOL> if ( options . log_to_stderr or <EOL> ( options . log_to_stderr is None and not logger . handlers ) ) : <EOL> channel = logging . StreamHandler ( ) <EOL> channel . setFormatter ( LogFormatter ( ) ) <EOL> logger . addHandler ( channel ) <EOL> def define_logging_options ( options = None ) : <EOL> if options is None : <EOL> from tornado . options import options <EOL> options . define ( "<STR_LIT>" , default = "<STR_LIT:info>" , <EOL> help = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> metavar = "<STR_LIT>" ) <EOL> options . define ( "<STR_LIT>" , type = bool , default = None , <EOL> help = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> options . define ( "<STR_LIT>" , type = str , default = None , metavar = "<STR_LIT>" , <EOL> help = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> options . define ( "<STR_LIT>" , type = int , default = <NUM_LIT:100> * <NUM_LIT:1000> * <NUM_LIT:1000> , <EOL> help = "<STR_LIT>" ) <EOL> options . define ( "<STR_LIT>" , type = int , default = <NUM_LIT:10> , <EOL> help = "<STR_LIT>" ) <EOL> options . add_parse_callback ( enable_pretty_logging ) </s>
