def log_to_file(filename, level=DEBUG):
 l = logging.getLogger('paramiko')
 if (len(l.handlers) > 0):
  return
 l.setLevel(level)
 f = open(filename, 'w')
 lh = logging.StreamHandler(f)
 lh.setFormatter(logging.Formatter('%(levelname)-.3s [%(asctime)s.%(msecs)03d] thr=%(_threadid)-3d %(name)s: %(message)s', '%Y%m%d-%H:%M:%S'))
 l.addHandler(lh)

def log_to_file ( filename , level = DEBUG ) : l = logging . getLogger ( 'paramiko' ) if ( len ( l . handlers ) > 0 ) : return l . setLevel ( level ) f = open ( filename , 'w' ) lh = logging . StreamHandler ( f ) lh . setFormatter ( logging . Formatter ( '%(levelname)-.3s [%(asctime)s.%(msecs)03d] thr=%(_threadid)-3d %(name)s: %(message)s' , '%Y%m%d-%H:%M:%S' ) ) l . addHandler ( lh )
send paramiko logs to a logfile .