Skip to content

Commit

Permalink
Switch to using the stdlib logger instead of pip.log
Browse files Browse the repository at this point in the history
  • Loading branch information
dstufft committed Sep 10, 2014
1 parent 83cdcc1 commit 767d11e
Show file tree
Hide file tree
Showing 59 changed files with 2,053 additions and 1,347 deletions.
7 changes: 1 addition & 6 deletions docs/pipext.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from textwrap import dedent
from pip import commands
from pip import cmdoptions
from pip.locations import default_log_file
from pip.util import get_prog
from pip.utils import get_prog


class PipCommandUsage(rst.Directive):
Expand Down Expand Up @@ -58,10 +57,6 @@ def _format_option(self, option, cmd_name=None):
opt_help = option.help.replace('%default', str(option.default))
# fix paths with sys.prefix
opt_help = opt_help.replace(sys.prefix, "<sys.prefix>")
opt_help = opt_help.replace(
default_log_file,
"<see :ref:`FileLogging`>",
)
return [bookmark_line, "", line, "", " %s" % opt_help, ""]

def _format_options(self, options, cmd_name=None):
Expand Down
41 changes: 9 additions & 32 deletions docs/reference/pip.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,7 @@ Console logging
~~~~~~~~~~~~~~~

pip offers :ref:`-v, --verbose <--verbose>` and :ref:`-q, --quiet <--quiet>`
to control the console log level. Each option can be used multiple times and
used together. One ``-v`` increases the verbosity by one, whereas one ``-q`` decreases it by
one.

The series of log levels, in order, are as follows::

VERBOSE_DEBUG, DEBUG, INFO, NOTIFY, WARN, ERROR, FATAL

``NOTIFY`` is the default level.

A few examples on how the parameters work to affect the level:

* specifying nothing results in ``NOTIFY``
* ``-v`` results in ``INFO``
* ``-vv`` results in ``DEBUG``
* ``-q`` results in ``WARN``
* ``-vq`` results in ``NOTIFY``

The most practical use case for users is either ``-v`` or ``-vv`` to see
additional logging to help troubleshoot an issue.
to control the console log level.


.. _`FileLogging`:
Expand All @@ -55,20 +36,16 @@ pip offers the :ref:`--log <--log>` option for specifying a file where a maximum
verbosity log will be kept. This option is empty by default. This log appends
to previous logging.

Additionally, when commands fail (i.e. return a non-zero exit code), pip writes
a "failure log" for the failed command. This log overwrites previous
logging. The default location is as follows:

* On Unix and Mac OS X: :file:`$HOME/.pip/pip.log`
* On Windows, the configuration file is: :file:`%HOME%\\pip\\pip.log`

The option for the failure log, is :ref:`--log-file <--log-file>`.
Additionally, pip writes a "debug log" for every command. This log appends and
will periodically rotate and clean itself up to limit on disk file size. The
default location is as follows:

Both logs add a line per execution to specify the date and what pip executable wrote the log.
* On Unix: :file:`$HOME/.cache/pip/log/debug.log`
* On Mac OS X: :file:`$HOME/Library/Logs/pip/debug.log`
* On Windows: :file:`C:\\Users\<username>\AppData\Local\pip\Logs\debug.log`

Like all pip options, ``--log`` and ``log-file``, can also be set as an environment
variable, or placed into the pip config file. See the :ref:`Configuration`
section.
Like all pip options, ``--log`` can also be set as an environment variable, or
placed into the pip config file. See the :ref:`Configuration` section.

.. _`exists-action`:

Expand Down
30 changes: 22 additions & 8 deletions pip/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#!/usr/bin/env python
from __future__ import absolute_import

import logging
import os
import optparse
import warnings

import sys
import re

from pip.exceptions import InstallationError, CommandError, PipError
from pip.log import logger
from pip.util import get_installed_distributions, get_prog
from pip.utils import get_installed_distributions, get_prog
from pip.utils import deprecation
from pip.vcs import git, mercurial, subversion, bazaar # noqa
from pip.baseparser import ConfigOptionParser, UpdatingDefaultsHelpFormatter
from pip.commands import commands, get_summaries, get_similar_commands
Expand All @@ -22,6 +26,9 @@
__version__ = "1.6.dev1"


logger = logging.getLogger(__name__)


def autocomplete():
"""Command and option completion for the main option parser (and options)
and its subcommands (and options).
Expand Down Expand Up @@ -171,6 +178,13 @@ def main(args=None):
if args is None:
args = sys.argv[1:]

# Enable our Deprecation Warnings
for deprecation_warning in deprecation.DEPRECATIONS:
warnings.simplefilter("default", deprecation_warning)

# Configure our deprecation warnings to be sent through loggers
deprecation.install_warning_logger()

autocomplete()

try:
Expand Down Expand Up @@ -208,14 +222,14 @@ def from_dist(cls, dist, dependency_links, find_tags=False):
try:
req = get_src_requirement(dist, location, find_tags)
except InstallationError as exc:
logger.warn(
logger.warning(
"Error when trying to get requirement for VCS system %s, "
"falling back to uneditable format" % exc
"falling back to uneditable format", exc
)
req = None
if req is None:
logger.warn(
'Could not determine repository location of %s' % location
logger.warning(
'Could not determine repository location of %s', location
)
comments.append(
'## !! Could not determine repository location'
Expand All @@ -238,8 +252,8 @@ def from_dist(cls, dist, dependency_links, find_tags=False):
dependency_links,
)
if not svn_location:
logger.warn(
'Warning: cannot find svn location for %s' % req)
logger.warning(
'Warning: cannot find svn location for %s', req)
comments.append(
'## FIXME: could not find svn URL in dependency_links '
'for this package:'
Expand Down
2 changes: 2 additions & 0 deletions pip/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import

import sys

# If we are running from a wheel, add the wheel to sys.path
Expand Down
78 changes: 78 additions & 0 deletions pip/appdirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
This code was taken from https://github.com/ActiveState/appdirs and modified
to suite our purposes.
"""
from __future__ import absolute_import

import os
import sys

Expand Down Expand Up @@ -52,6 +54,82 @@ def user_cache_dir(appname):
return path


def user_data_dir(appname, roaming=False):
"""
Return full path to the user-specific data dir for this application.
"appname" is the name of application.
If None, just the system directory is returned.
"roaming" (boolean, default False) can be set True to use the Windows
roaming appdata directory. That means that for users on a Windows
network setup for roaming profiles, this user data will be
sync'd on login. See
<http://technet.microsoft.com/en-us/library/cc766489(WS.10).aspx>
for a discussion of issues.
Typical user data directories are:
Mac OS X: ~/Library/Application Support/<AppName>
Unix: ~/.local/share/<AppName> # or in
$XDG_DATA_HOME, if defined
Win XP (not roaming): C:\Documents and Settings\<username>\ ...
...Application Data\<AppName>
Win XP (roaming): C:\Documents and Settings\<username>\Local ...
...Settings\Application Data\<AppName>
Win 7 (not roaming): C:\\Users\<username>\AppData\Local\<AppName>
Win 7 (roaming): C:\\Users\<username>\AppData\Roaming\<AppName>
For Unix, we follow the XDG spec and support $XDG_DATA_HOME.
That means, by default "~/.local/share/<AppName>".
"""
if WINDOWS:
const = roaming and "CSIDL_APPDATA" or "CSIDL_LOCAL_APPDATA"
path = os.path.join(os.path.normpath(_get_win_folder(const)), appname)
elif sys.platform == "darwin":
path = os.path.join(
os.path.expanduser('~/Library/Application Support/'),
appname,
)
else:
path = os.path.join(
os.getenv('XDG_DATA_HOME', os.path.expanduser("~/.local/share")),
appname,
)

return path


def user_log_dir(appname):
"""
Return full path to the user-specific log dir for this application.
"appname" is the name of application.
If None, just the system directory is returned.
Typical user cache directories are:
Mac OS X: ~/Library/Logs/<AppName>
Unix: ~/.cache/<AppName>/log # or under $XDG_CACHE_HOME if
defined
Win XP: C:\Documents and Settings\<username>\Local Settings\ ...
...Application Data\<AppName>\Logs
Vista: C:\\Users\<username>\AppData\Local\<AppName>\Logs
On Windows the only suggestion in the MSDN docs is that local settings
go in the `CSIDL_LOCAL_APPDATA` directory. (Note: I'm interested in
examples of what some windows apps use for a logs dir.)
OPINION: This function appends "Logs" to the `CSIDL_LOCAL_APPDATA`
value for Windows and appends "log" to the user cache dir for Unix.
"""
if WINDOWS:
path = os.path.join(user_data_dir(appname), "Logs")
elif sys.platform == "darwin":
path = os.path.join(os.path.expanduser('~/Library/Logs'), appname)
else:
path = os.path.join(user_cache_dir(appname), "log")

return path


# for the discussion regarding site_config_dirs locations
# see <https://github.com/pypa/pip/issues/1733>
def site_config_dirs(appname):
Expand Down
Loading

0 comments on commit 767d11e

Please sign in to comment.