<s> import functools <EOL> import os <EOL> import time <EOL> import traceback <EOL> import gunicorn . glogging <EOL> from django . core . management . color import color_style <EOL> def colorize ( style , msg , resp ) : <EOL> """<STR_LIT>""" <EOL> code = resp . status . split ( maxsplit = <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> if code [ <NUM_LIT:0> ] == '<STR_LIT:2>' : <EOL> msg = style . HTTP_SUCCESS ( msg ) <EOL> elif code [ <NUM_LIT:0> ] == '<STR_LIT:1>' : <EOL> msg = style . HTTP_INFO ( msg ) <EOL> elif code == '<STR_LIT>' : <EOL> msg = style . HTTP_NOT_MODIFIED ( msg ) <EOL> elif code [ <NUM_LIT:0> ] == '<STR_LIT:3>' : <EOL> msg = style . HTTP_REDIRECT ( msg ) <EOL> elif code == '<STR_LIT>' : <EOL> msg = style . HTTP_NOT_FOUND ( msg ) <EOL> elif code [ <NUM_LIT:0> ] == '<STR_LIT:4>' : <EOL> msg = style . HTTP_BAD_REQUEST ( msg ) <EOL> else : <EOL> msg = style . HTTP_SERVER_ERROR ( msg ) <EOL> return msg <EOL> class GunicornLogger ( gunicorn . glogging . Logger ) : <EOL> """<STR_LIT>""" <EOL> datefmt = r'<STR_LIT>' <EOL> def __init__ ( self , cfg ) : <EOL> super ( GunicornLogger , self ) . __init__ ( cfg ) <EOL> if os . environ . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> self . stylize = lambda msg , resp : msg <EOL> else : <EOL> self . stylize = functools . partial ( colorize , color_style ( ) ) <EOL> def now ( self ) : <EOL> """<STR_LIT>""" <EOL> return time . strftime ( r'<STR_LIT>' ) <EOL> def make_access_message ( self , resp , req , environ , request_time ) : <EOL> safe_atoms = self . atoms_wrapper_class ( <EOL> self . atoms ( resp , req , environ , request_time ) , <EOL> ) <EOL> return self . stylize ( self . cfg . access_log_format % safe_atoms , resp ) <EOL> def access ( self , resp , req , environ , request_time ) : <EOL> """<STR_LIT>""" <EOL> if not ( self . cfg . accesslog or self . cfg . logconfig or self . cfg . syslog ) : <EOL> return <EOL> msg = self . make_access_message ( resp , req , environ , request_time ) <EOL> try : <EOL> self . access_log . info ( msg ) <EOL> except : <EOL> self . error ( traceback . format_exc ( ) ) </s>
