<s> """<STR_LIT>""" <EOL> import logging <EOL> import sys <EOL> import os <EOL> import os . path <EOL> from django . conf import settings <EOL> BLACK , RED , GREEN , YELLOW , BLUE , MAGENTA , CYAN , WHITE = range ( <NUM_LIT:8> ) <EOL> RESET_SEQ = "<STR_LIT>" <EOL> COLOR_SEQ = "<STR_LIT>" <EOL> BOLD_SEQ = "<STR_LIT>" <EOL> COLORIZE = { <EOL> '<STR_LIT>' : BLUE , <EOL> } <EOL> HIGHLIGHT = { <EOL> '<STR_LIT>' : RED , <EOL> '<STR_LIT>' : RED , <EOL> '<STR_LIT>' : YELLOW , <EOL> } <EOL> class MyFormatter ( logging . Formatter ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , color = True ) : <EOL> logging . Formatter . __init__ ( self , <EOL> '<STR_LIT>' , <EOL> "<STR_LIT>" <EOL> ) <EOL> self . use_color = color <EOL> def format ( self , record ) : <EOL> record . pid = os . getpid ( ) <EOL> record . fileandlineno = "<STR_LIT>" % ( record . name , record . filename , record . lineno ) <EOL> l = <NUM_LIT:10> <EOL> record . funcName = ( "<STR_LIT>" + str ( l ) + '<STR_LIT:s>' ) % record . funcName [ : l ] <EOL> levelname = record . levelname <EOL> if self . use_color : <EOL> if levelname in COLORIZE : <EOL> levelname_color = COLOR_SEQ % ( <NUM_LIT:30> + COLORIZE [ levelname ] ) + "<STR_LIT>" % levelname + RESET_SEQ <EOL> record . levelname = levelname_color <EOL> elif levelname in HIGHLIGHT : <EOL> line = logging . Formatter . format ( self , record ) <EOL> line = COLOR_SEQ % ( <NUM_LIT> + HIGHLIGHT [ levelname ] ) + line + RESET_SEQ <EOL> return line <EOL> else : <EOL> if levelname in HIGHLIGHT : <EOL> line = logging . Formatter . format ( self , record ) <EOL> line = "<STR_LIT:*>" * min ( <NUM_LIT> , len ( line ) ) + "<STR_LIT:\n>" + line <EOL> return line <EOL> return logging . Formatter . format ( self , record ) <EOL> def get_logger ( name = None ) : <EOL> """<STR_LIT>""" <EOL> opusroot = logging . getLogger ( "<STR_LIT>" ) <EOL> try : <EOL> logdir = settings . LOG_DIR <EOL> except ( AttributeError , ImportError ) : <EOL> logdir = None <EOL> try : <EOL> loglevel = settings . LOG_LEVEL <EOL> except ( AttributeError , ImportError ) : <EOL> loglevel = logging . DEBUG <EOL> if isinstance ( loglevel , basestring ) : <EOL> loglevel = { "<STR_LIT>" : logging . DEBUG , <EOL> "<STR_LIT>" : logging . INFO , <EOL> "<STR_LIT>" : logging . WARNING , <EOL> "<STR_LIT>" : logging . ERROR , <EOL> "<STR_LIT>" : logging . CRITICAL <EOL> } [ loglevel . upper ( ) ] <EOL> if not opusroot . handlers : <EOL> opusroot . setLevel ( loglevel ) <EOL> if logdir : <EOL> masterlogfile = os . path . join ( logdir , "<STR_LIT>" ) <EOL> masterhandler = logging . FileHandler ( masterlogfile ) <EOL> masterhandler . setFormatter ( MyFormatter ( color = False ) ) <EOL> opusroot . addHandler ( masterhandler ) <EOL> try : <EOL> if hasattr ( sys . stderr , "<STR_LIT>" ) : <EOL> istty = sys . stderr . isatty ( ) <EOL> else : <EOL> istty = False <EOL> except IOError : <EOL> pass <EOL> else : <EOL> if istty : <EOL> colorstderr = logging . StreamHandler ( ) <EOL> colorstderr . setFormatter ( MyFormatter ( color = True ) ) <EOL> opusroot . addHandler ( colorstderr ) <EOL> if not name : <EOL> return opusroot <EOL> applogger = logging . getLogger ( "<STR_LIT>" + name ) <EOL> if not applogger . handlers : <EOL> applogger . setLevel ( loglevel ) <EOL> if logdir : <EOL> applogfile = os . path . join ( logdir , name + "<STR_LIT>" ) <EOL> h = logging . FileHandler ( applogfile ) <EOL> h . setFormatter ( MyFormatter ( color = False ) ) <EOL> applogger . addHandler ( h ) <EOL> return applogger </s>
