1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
|
..
This work is licensed under a Creative Commons Attribution 3.0 Unported
License.
http://creativecommons.org/licenses/by/3.0/legalcode
==================
Logging Guidelines
==================
.. note::
Many of these guidelines were originally authored as `a cross-project spec
<https://specs.openstack.org/openstack/openstack-specs/specs/log-guidelines.html>`_.
Motivation
==========
A consistent, unified logging format will better enable cloud
administrators to monitor and maintain their environments. Therefore
this document provides guidelines for best practices regarding how
developers should use logging within their code.
Adding Variables to Log Messages
================================
String interpolation should be delayed to be handled by the logging
code, rather than being done at the point of the logging call. For
example, **do not do this**::
# WRONG
LOG.info('some message: variable=%s' % variable)
Instead, use this style::
# RIGHT
LOG.info('some message: variable=%s', variable)
This allows the logging package to skip creating the formatted log
message if the message is not going to be emitted because of the
current log level.
Definition of Log Levels
========================
.. note::
The following definitions were originally taken from `a popular
answer on StackOverflow <http://stackoverflow.com/a/2031209>`_.
``DEBUG``
Shows everything and is likely not suitable for normal production
operation due to the sheer size of logs generated.
``INFO``
Usually indicates successful service start/stop, versions and such
non-error related data. This should include largely positive units
of work that are accomplished (such as starting a compute service,
creating a user, deleting a volume, etc.).
``AUDIT``
This should not be used. All previous messages at ``AUDIT`` level
should be changed to ``INFO``, or sent as notifications to a
notification queue. (The origin of ``AUDIT`` was a NASA-specific
requirement which led to confusion/misuse and is no longer relevant
to the current code.)
``WARNING``
Indicates that there might be a systemic issue; potential
predictive failure notice.
``ERROR``
An error has occurred and an administrator should research
the event.
``CRITICAL``
An error has occurred and the system might be unstable;
administrator attention is required immediately.
Log levels from an operator perspective
---------------------------------------
We can think of this from an operator perspective the following ways
(Note: we are not specifying operator policy here, just trying to set
tone for developers that aren't familiar with how these messages will
be interpreted):
``CRITICAL``
ZOMG! Cluster on FIRE! Call all pagers, wake up everyone. This is
an unrecoverable error with a service that has or probably will lead
to service death or massive degradation.
``ERROR``
Serious issue with cloud: administrator should be notified
immediately via email/pager. On call people expected to respond.
``WARNING``
Something is not right; should get looked into during the next work
week. Administrators should be working through eliminating warnings
as part of normal work.
``INFO``
Normal status messages showing measurable units of positive work
passing through under normal functioning of the system. Should not
be so verbose as to overwhelm real signal with noise. Should not be
continuous "I'm alive!" messages. See `Log messages at INFO and
above should represent a "unit of work"`_ for more details.
``DEBUG``
Developer logging level. Only enable if you are interested in
reading through a ton of additional information about what is going
on. See `Debugging start / end messages`_ for more details.
``TRACE``
In functions which support this level, details every parameter and
operation to help diagnose subtle bugs. This should only be enabled
for specific areas of interest or the log volume will be
overwhelming. Some system performance degradation should be
expected.
Overall logging principles
==========================
The following principles should apply to all messages.
Debugging start / end messages
------------------------------
At the ``DEBUG`` log level it is often extremely important to flag the
beginning and ending of actions to track the progression of flows
(which might error out before the unit of work is completed).
This should be made clear by there being a "starting" message with
some indication of completion for that starting point.
In a real OpenStack environment lots of things are happening in
parallel. There are multiple workers per services, multiple instances
of services in the cloud.
Log messages at INFO and above should represent a "unit of work"
----------------------------------------------------------------
The ``INFO`` log level is defined as: "normal status messages showing
measurable units of positive work passing through under normal
functioning of the system."
A measurable unit of work should be describable by a short sentence
fragment, in the past tense with a noun and a verb of something
significant.
Examples::
Instance spawned
Instance destroyed
Volume attached
Image failed to copy
Words like "started", "finished", or any verb ending in "ing" are
flags for non unit of work messages.
Examples of good and bad uses of INFO
-------------------------------------
Below are some examples of good and bad uses of ``INFO``. In the good
examples we can see the 'noun / verb' fragment for a unit of work.
"Successfully" is probably superfluous and could be removed.
**Good**
::
2014-01-26 15:36:10.597 28297 INFO nova.virt.libvirt.driver [-]
[instance: b1b8e5c7-12f0-4092-84f6-297fe7642070] Instance spawned
successfully.
2014-01-26 15:36:14.307 28297 INFO nova.virt.libvirt.driver [-]
[instance: b1b8e5c7-12f0-4092-84f6-297fe7642070] Instance destroyed
successfully.
In the bad examples we see trace-level thinking put into messages at
``INFO`` level and above:
**Bad**
::
2014-01-26 15:36:11.198 INFO nova.virt.libvirt.driver
[req-ded67509-1e5d-4fb2-a0e2-92932bba9271
FixedIPsNegativeTestXml-1426989627 FixedIPsNegativeTestXml-38506689]
[instance: fd027464-6e15-4f5d-8b1f-c389bdb8772a] Creating image
2014-01-26 15:36:11.525 INFO nova.virt.libvirt.driver
[req-ded67509-1e5d-4fb2-a0e2-92932bba9271
FixedIPsNegativeTestXml-1426989627 FixedIPsNegativeTestXml-38506689]
[instance: fd027464-6e15-4f5d-8b1f-c389bdb8772a] Using config drive
2014-01-26 15:36:12.326 AUDIT nova.compute.manager
[req-714315e2-6318-4005-8f8f-05d7796ff45d FixedIPsTestXml-911165017
FixedIPsTestXml-1315774890] [instance:
b1b8e5c7-12f0-4092-84f6-297fe7642070] Terminating instance
2014-01-26 15:36:12.570 INFO nova.virt.libvirt.driver
[req-ded67509-1e5d-4fb2-a0e2-92932bba9271
FixedIPsNegativeTestXml-1426989627 FixedIPsNegativeTestXml-38506689]
[instance: fd027464-6e15-4f5d-8b1f-c389bdb8772a] Creating config
drive at
/opt/stack/data/nova/instances/fd027464-6e15-4f5d-8b1f
-c389bdb8772a/disk.config
This is mostly an overshare issue. At ``INFO``, these are stages that
don't really need to be fully communicated.
Messages shouldn't need a secret decoder ring
---------------------------------------------
**Bad**
::
2014-01-26 15:36:14.256 28297 INFO nova.compute.manager [-]
Lifecycle event 1 on VM b1b8e5c7-12f0-4092-84f6-297fe7642070
As a general rule, when using constants or enums, ensure they are
translated back to user strings prior to being sent to the user.
Specific event types
--------------------
In addition to the above guidelines very specific additional
recommendations exist. These are guidelines rather than hard rules to
be adhered to, so common sense should always be exercised.
WSGI requests
~~~~~~~~~~~~~
- Should be logged at ``INFO`` level.
- Should be logged exactly once per request.
- Should include enough information to know what the request was
(but not so much as to overwhelm the logs).
The last point is notable, because some ``POST`` API requests don't
include enough information in the URL alone to determine what the
API did. For instance, Nova server actions (where ``POST`` includes a
method name), although including ``POST`` request payloads could be
excessive, so common sense should be exercised.
**Rationale:** Operators should be able to easily see what API
requests their users are making in their cloud to understand the usage
patterns of their users with their cloud.
Operator deprecation warnings
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Should be logged at ``WARN`` level.
- Where possible, should be logged exactly once per service start (not
on every request through code). However it may be tricky to keep
track of whether a warning was already issued, so common sense should
dictate the best approach.
- Should include directions on what to do to migrate from the
deprecated state.
**Rationale:** Operators need to know that some aspect of their cloud
configuration is now deprecated, and will require changes in the
future. And they need enough of a bread crumb trail to figure out how
to do that.
REST API deprecation warnings
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Should **not** be logged any higher than ``DEBUG``, since these are
not operator-facing messages.
- Should be logged no more than once per REST API usage / project,
definitely not on *every* REST API call.
**Rationale:** The users of the REST API don't have access to the
system logs. Therefore logging at a ``WARNING`` level is telling the
wrong people about the fact that they are using a deprecated API.
Deprecation of user-facing APIs should be communicated via user-facing
mechanisms, e.g. API change notes associated with new API versions.
Stacktraces in logs
~~~~~~~~~~~~~~~~~~~
- Should be **exceptional** events, for unforeseeable circumstances
that are not yet recoverable by the system.
- Should be logged at ``ERROR`` level.
- Should be considered high priority bugs to be addressed by the
development team.
**Rationale:** The current behavior of OpenStack is extremely stack
trace happy. Many existing stack traces in the logs are considered
*normal*. This dramatically increases the time to find the root cause
of real issues in OpenStack.
Logging by non-OpenStack components
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
OpenStack uses a ton of libraries, which have their own definitions of
logging. This causes a lot of extraneous information in normal logs by
wildly different definitions of those libraries.
As such, all 3rd party libraries should have their logging levels
adjusted so only real errors are logged.
Currently proposed settings for 3rd party libraries:
- ``amqp=WARN``
- ``boto=WARN``
- ``qpid=WARN``
- ``sqlalchemy=WARN``
- ``suds=INFO``
- ``iso8601=WARN``
- ``requests.packages.urllib3.connectionpool=WARN``
- ``urllib3.connectionpool=WARN``
Testing
=======
See tests provided by
https://blueprints.launchpad.net/nova/+spec/clean-logs
References
==========
- Security Log Guidelines -
https://wiki.openstack.org/wiki/Security/Guidelines/logging_guidelines
- Wiki page for basic logging standards proposal developed early in
Icehouse - https://wiki.openstack.org/wiki/LoggingStandards
- Apache Log4j levels (which many tools work with) -
https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html
|