提交 b7466523 编写于 作者: J Jannis Leidel

Overwrite the local log file in ~/.pip/pip.log instead of appending to prevent...

Overwrite the local log file in ~/.pip/pip.log instead of appending to prevent huge log files. For a verbose log file use the --log option explicitely (which will be appended to).
上级 0bf943e4
......@@ -106,7 +106,7 @@ class Command(object):
## FIXME: not sure if this sure come before or after venv restart
if options.log:
log_fp = open_logfile_append(options.log)
log_fp = open_logfile(options.log, 'a')
logger.consumers.append((logger.DEBUG, log_fp))
else:
log_fp = None
......@@ -132,7 +132,7 @@ class Command(object):
log_fn = options.log_file
text = '\n'.join(complete_log)
logger.fatal('Storing complete log in %s' % log_fn)
log_fp = open_logfile_append(log_fn)
log_fp = open_logfile(log_fn, 'w')
log_fp.write(text)
log_fp.close()
return exit
......@@ -177,7 +177,7 @@ def format_exc(exc_info=None):
traceback.print_exception(*exc_info, **dict(file=out))
return out.getvalue()
def open_logfile_append(filename):
def open_logfile(filename, mode='a'):
"""Open the named log file in append mode.
If the file already exists, a separator will also be printed to
......@@ -185,7 +185,7 @@ def open_logfile_append(filename):
"""
filename = os.path.expanduser(filename)
exists = os.path.exists(filename)
log_fp = open(filename, 'a')
log_fp = open(filename, mode)
if exists:
print >> log_fp, '-'*60
print >> log_fp, '%s run on %s' % (sys.argv[0], time.strftime('%c'))
......
......@@ -6,7 +6,7 @@ import pkg_resources
import ConfigParser
import os
from distutils.util import strtobool
from pip.locations import default_config_file
from pip.locations import default_config_file, default_log_file
class UpdatingDefaultsHelpFormatter(optparse.IndentedHelpFormatter):
"""Custom help formatter for use in ConfigOptionParser that updates
......@@ -186,7 +186,7 @@ parser.add_option(
'--local-log', '--log-file',
dest='log_file',
metavar='FILENAME',
default='./pip-log.txt',
default=default_log_file,
help=optparse.SUPPRESS_HELP)
parser.add_option(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册