def _adapt_eventdict(eventDict, log_level=INFO, encoding='utf-8', prepend_level=True):
 ev = eventDict.copy()
 if ev['isError']:
  ev.setdefault('logLevel', ERROR)
 if ((ev.get('system') != 'scrapy') and (not ev['isError'])):
  return
 level = ev.get('logLevel')
 if (level < log_level):
  return
 spider = ev.get('spider')
 if spider:
  ev['system'] = spider.name
 message = ev.get('message')
 lvlname = level_names.get(level, 'NOLEVEL')
 if message:
  message = [unicode_to_str(x, encoding) for x in message]
  if prepend_level:
   message[0] = ('%s: %s' % (lvlname, message[0]))
 ev['message'] = message
 why = ev.get('why')
 if why:
  why = unicode_to_str(why, encoding)
  if prepend_level:
   why = ('%s: %s' % (lvlname, why))
 ev['why'] = why
 return ev

def _adapt_eventdict ( eventDict , log_level = INFO , encoding = 'utf-8' , prepend_level = True ) : ev = eventDict . copy ( ) if ev [ 'isError' ] : ev . setdefault ( 'logLevel' , ERROR ) if ( ( ev . get ( 'system' ) != 'scrapy' ) and ( not ev [ 'isError' ] ) ) : return level = ev . get ( 'logLevel' ) if ( level < log_level ) : return spider = ev . get ( 'spider' ) if spider : ev [ 'system' ] = spider . name message = ev . get ( 'message' ) lvlname = level_names . get ( level , 'NOLEVEL' ) if message : message = [ unicode_to_str ( x , encoding ) for x in message ] if prepend_level : message [ 0 ] = ( '%s: %s' % ( lvlname , message [ 0 ] ) ) ev [ 'message' ] = message why = ev . get ( 'why' ) if why : why = unicode_to_str ( why , encoding ) if prepend_level : why = ( '%s: %s' % ( lvlname , why ) ) ev [ 'why' ] = why return ev
adapt twisted log eventdict making it suitable for logging with a scrapy log observer .