|
| 1 | +======= |
| 2 | +Logging |
| 3 | +======= |
| 4 | + |
| 5 | +.. note:: TODO(shade) This document is written from a shade POV. It needs to |
| 6 | + be combined with the existing logging guide, but also the logging |
| 7 | + systems need to be rationalized. |
| 8 | + |
| 9 | +`openstacksdk` uses `Python Logging`_. As `openstacksdk` is a library, it does |
| 10 | +not configure logging handlers automatically, expecting instead for that to be |
| 11 | +the purview of the consuming application. |
| 12 | + |
| 13 | +Simple Usage |
| 14 | +------------ |
| 15 | + |
| 16 | +For consumers who just want to get a basic logging setup without thinking |
| 17 | +about it too deeply, there is a helper method. If used, it should be called |
| 18 | +before any other openstacksdk functionality. |
| 19 | + |
| 20 | +.. autofunction:: openstack.enable_logging |
| 21 | + |
| 22 | +.. code-block:: python |
| 23 | +
|
| 24 | + import openstack |
| 25 | + openstack.enable_logging() |
| 26 | +
|
| 27 | +The ``stream`` parameter controls the stream where log message are written to. |
| 28 | +It defaults to `sys.stdout` which will result in log messages being written |
| 29 | +to STDOUT. It can be set to another output stream, or to ``None`` to disable |
| 30 | +logging to the console. |
| 31 | + |
| 32 | +The ``path`` parameter sets up logging to log to a file. By default, if |
| 33 | +``path`` is given and ``stream`` is not, logging will only go to ``path``. |
| 34 | + |
| 35 | +You can combine the ``path`` and ``stream`` parameters to log to both places |
| 36 | +simultaneously. |
| 37 | + |
| 38 | +To log messages to a file called ``openstack.log`` and the console on |
| 39 | +``stdout``: |
| 40 | + |
| 41 | +.. code-block:: python |
| 42 | +
|
| 43 | + import sys |
| 44 | + import openstack |
| 45 | +
|
| 46 | + openstack.enable_logging( |
| 47 | + debug=True, path='openstack.log', stream=sys.stdout) |
| 48 | +
|
| 49 | +
|
| 50 | +`openstack.enable_logging` also sets up a few other loggers and |
| 51 | +squelches some warnings or log messages that are otherwise uninteresting or |
| 52 | +unactionable by an openstacksdk user. |
| 53 | + |
| 54 | +Advanced Usage |
| 55 | +-------------- |
| 56 | + |
| 57 | +`openstacksdk` logs to a set of different named loggers. |
| 58 | + |
| 59 | +Most of the logging is set up to log to the root ``openstack`` logger. |
| 60 | +There are additional sub-loggers that are used at times, primarily so that a |
| 61 | +user can decide to turn on or off a specific type of logging. They are listed |
| 62 | +below. |
| 63 | + |
| 64 | +openstack.config |
| 65 | + Issues pertaining to configuration are logged to the ``openstack.config`` |
| 66 | + logger. |
| 67 | + |
| 68 | +openstack.task_manager |
| 69 | + `openstacksdk` uses a Task Manager to perform remote calls. The |
| 70 | + ``openstack.task_manager`` logger emits messages at the start and end |
| 71 | + of each Task announcing what it is going to run and then what it ran and |
| 72 | + how long it took. Logging ``openstack.task_manager`` is a good way to |
| 73 | + get a trace of external actions `openstacksdk` is taking without full |
| 74 | + `HTTP Tracing`_. |
| 75 | + |
| 76 | +openstack.iterate_timeout |
| 77 | + When `openstacksdk` needs to poll a resource, it does so in a loop that waits |
| 78 | + between iterations and ultimately times out. The |
| 79 | + ``openstack.iterate_timeout`` logger emits messages for each iteration |
| 80 | + indicating it is waiting and for how long. These can be useful to see for |
| 81 | + long running tasks so that one can know things are not stuck, but can also |
| 82 | + be noisy. |
| 83 | + |
| 84 | +openstack.fnmatch |
| 85 | + `openstacksdk` will try to use `fnmatch`_ on given `name_or_id` arguments. |
| 86 | + It's a best effort attempt, so pattern misses are logged to |
| 87 | + ``openstack.fnmatch``. A user may not be intending to use an fnmatch |
| 88 | + pattern - such as if they are trying to find an image named |
| 89 | + ``Fedora 24 [official]``, so these messages are logged separately. |
| 90 | + |
| 91 | +.. _fnmatch: https://pymotw.com/2/fnmatch/ |
| 92 | + |
| 93 | +HTTP Tracing |
| 94 | +------------ |
| 95 | + |
| 96 | +HTTP Interactions are handled by `keystoneauth`_. If you want to enable HTTP |
| 97 | +tracing while using openstacksdk and are not using `openstack.enable_logging`, |
| 98 | +set the log level of the ``keystoneauth`` logger to ``DEBUG``. |
| 99 | + |
| 100 | +For more information see https://docs.openstack.org/keystoneauth/latest/using-sessions.html#logging |
| 101 | + |
| 102 | +.. _keystoneauth: https://docs.openstack.org/keystoneauth/latest/ |
| 103 | + |
| 104 | +Python Logging |
| 105 | +-------------- |
| 106 | + |
| 107 | +Python logging is a standard feature of Python and is documented fully in the |
| 108 | +Python Documentation, which varies by version of Python. |
| 109 | + |
| 110 | +For more information on Python Logging for Python v2, see |
| 111 | +https://docs.python.org/2/library/logging.html. |
| 112 | + |
| 113 | +For more information on Python Logging for Python v3, see |
| 114 | +https://docs.python.org/3/library/logging.html. |
0 commit comments