1
0

index.rst 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. .. _logging:
  2. =======
  3. Logging
  4. =======
  5. The salt project tries to get the logging to work for you and help us solve any
  6. issues you might find along the way.
  7. If you want to get some more information on the nitty-gritty of salt's logging
  8. system, please head over to the :ref:`logging development
  9. document <logging-internals>`, if all you're after is salt's logging
  10. configurations, please continue reading.
  11. .. conf_log:: log_levels
  12. Log Levels
  13. ==========
  14. The log levels are ordered numerically such that setting the log level to a
  15. specific level will record all log statements at that level and higher. For
  16. example, setting ``log_level: error`` will log statements at ``error``,
  17. ``critical``, and ``quiet`` levels, although nothing *should* be logged at
  18. ``quiet`` level.
  19. Most of the logging levels are defined by default in Python's logging library
  20. and can be found in the official :ref:`Python documentation <python:levels>`.
  21. Salt uses some more levels in addition to the standard levels. All levels
  22. available in salt are shown in the table below.
  23. .. note::
  24. Python dependencies used by salt may define and use additional logging
  25. levels. For example, the Python 2 version of the ``multiprocessing``
  26. standard Python library `uses the levels
  27. <https://docs.python.org/2/library/multiprocessing.html#logging>`_
  28. ``subwarning``, 25 and ``subdebug``, 5.
  29. +----------+---------------+--------------------------------------------------------------------------+
  30. | Level | Numeric value | Description |
  31. +==========+===============+==========================================================================+
  32. | quiet | 1000 | Nothing should be logged at this level |
  33. +----------+---------------+--------------------------------------------------------------------------+
  34. | critical | 50 | Critical errors |
  35. +----------+---------------+--------------------------------------------------------------------------+
  36. | error | 40 | Errors |
  37. +----------+---------------+--------------------------------------------------------------------------+
  38. | warning | 30 | Warnings |
  39. +----------+---------------+--------------------------------------------------------------------------+
  40. | info | 20 | Normal log information |
  41. +----------+---------------+--------------------------------------------------------------------------+
  42. | profile | 15 | Profiling information on salt performance |
  43. +----------+---------------+--------------------------------------------------------------------------+
  44. | debug | 10 | Information useful for debugging both salt implementations and salt code |
  45. +----------+---------------+--------------------------------------------------------------------------+
  46. | trace | 5 | More detailed code debugging information |
  47. +----------+---------------+--------------------------------------------------------------------------+
  48. | garbage | 1 | Even more debugging information |
  49. +----------+---------------+--------------------------------------------------------------------------+
  50. | all | 0 | Everything |
  51. +----------+---------------+--------------------------------------------------------------------------+
  52. Available Configuration Settings
  53. ================================
  54. .. conf_log:: log_file
  55. ``log_file``
  56. ------------
  57. The log records can be sent to a regular file, local path name, or network
  58. location. Remote logging works best when configured to use rsyslogd(8) (e.g.:
  59. ``file:///dev/log``), with rsyslogd(8) configured for network logging. The
  60. format for remote addresses is:
  61. .. code-block:: text
  62. <file|udp|tcp>://<host|socketpath>:<port-if-required>/<log-facility>
  63. Where ``log-facility`` is the symbolic name of a syslog facility as defined in
  64. the :py:meth:`SysLogHandler documentation
  65. <logging.handlers.SysLogHandler.encodePriority>`. It defaults to ``LOG_USER``.
  66. Default: Dependent of the binary being executed, for example, for
  67. ``salt-master``, ``/var/log/salt/master``.
  68. Examples:
  69. .. code-block:: yaml
  70. log_file: /var/log/salt/master
  71. .. code-block:: yaml
  72. log_file: /var/log/salt/minion
  73. .. code-block:: yaml
  74. log_file: file:///dev/log
  75. .. code-block:: yaml
  76. log_file: file:///dev/log/LOG_DAEMON
  77. .. code-block:: yaml
  78. log_file: udp://loghost:10514
  79. .. conf_log:: log_level
  80. ``log_level``
  81. -------------
  82. Default: ``warning``
  83. The level of log record messages to send to the console. One of ``all``,
  84. ``garbage``, ``trace``, ``debug``, ``profile``, ``info``, ``warning``,
  85. ``error``, ``critical``, ``quiet``.
  86. .. code-block:: yaml
  87. log_level: warning
  88. .. note::
  89. Add ``log_level: quiet`` in salt configuration file to completely disable
  90. logging. In case of running salt in command line use ``--log-level=quiet``
  91. instead.
  92. .. conf_log:: log_level_logfile
  93. ``log_level_logfile``
  94. ---------------------
  95. Default: ``info``
  96. The level of messages to send to the log file. One of ``all``, ``garbage``,
  97. ``trace``, ``debug``, ``profile``, ``info``, ``warning``, ``error``,
  98. ``critical``, ``quiet``.
  99. .. code-block:: yaml
  100. log_level_logfile: warning
  101. .. conf_log:: log_datefmt
  102. ``log_datefmt``
  103. ---------------
  104. Default: ``%H:%M:%S``
  105. The date and time format used in console log messages. Allowed date/time
  106. formatting matches those used in :py:func:`time.strftime`.
  107. .. code-block:: yaml
  108. log_datefmt: '%H:%M:%S'
  109. .. conf_log:: log_datefmt_logfile
  110. ``log_datefmt_logfile``
  111. -----------------------
  112. Default: ``%Y-%m-%d %H:%M:%S``
  113. The date and time format used in log file messages. Allowed date/time
  114. formatting matches those used in :py:func:`time.strftime`.
  115. .. code-block:: yaml
  116. log_datefmt_logfile: '%Y-%m-%d %H:%M:%S'
  117. .. conf_log:: log_fmt_console
  118. ``log_fmt_console``
  119. -------------------
  120. Default: ``[%(levelname)-8s] %(message)s``
  121. The format of the console logging messages. All standard python logging
  122. :py:class:`~logging.LogRecord` attributes can be used. Salt also provides these
  123. custom LogRecord attributes to colorize console log output:
  124. .. code-block:: python
  125. '%(colorlevel)s' # log level name colorized by level
  126. '%(colorname)s' # colorized module name
  127. '%(colorprocess)s' # colorized process number
  128. '%(colormsg)s' # log message colorized by level
  129. .. note::
  130. The ``%(colorlevel)s``, ``%(colorname)s``, and ``%(colorprocess)``
  131. LogRecord attributes also include padding and enclosing brackets, ``[`` and
  132. ``]`` to match the default values of their collateral non-colorized
  133. LogRecord attributes.
  134. .. code-block:: yaml
  135. log_fmt_console: '[%(levelname)-8s] %(message)s'
  136. .. conf_log:: log_fmt_logfile
  137. ``log_fmt_logfile``
  138. -------------------
  139. Default: ``%(asctime)s,%(msecs)03d [%(name)-17s][%(levelname)-8s] %(message)s``
  140. The format of the log file logging messages. All standard python logging
  141. :py:class:`~logging.LogRecord` attributes can be used. Salt also provides
  142. these custom LogRecord attributes that include padding and enclosing brackets
  143. ``[`` and ``]``:
  144. .. code-block:: python
  145. '%(bracketlevel)s' # equivalent to [%(levelname)-8s]
  146. '%(bracketname)s' # equivalent to [%(name)-17s]
  147. '%(bracketprocess)s' # equivalent to [%(process)5s]
  148. .. code-block:: yaml
  149. log_fmt_logfile: '%(asctime)s,%(msecs)03d [%(name)-17s][%(levelname)-8s] %(message)s'
  150. .. conf_log:: log_granular_levels
  151. ``log_granular_levels``
  152. -----------------------
  153. Default: ``{}``
  154. This can be used to control logging levels more specifically, based on log call name. The example sets
  155. the main salt library at the 'warning' level, sets ``salt.modules`` to log
  156. at the ``debug`` level, and sets a custom module to the ``all`` level:
  157. .. code-block:: yaml
  158. log_granular_levels:
  159. 'salt': 'warning'
  160. 'salt.modules': 'debug'
  161. 'salt.loader.saltmaster.ext.module.custom_module': 'all'
  162. .. conf_log:: log_fmt_jid
  163. ``log_fmt_jid``
  164. -------------------
  165. Default: ``[JID: %(jid)s]``
  166. The format of the JID when added to logging messages.
  167. .. code-block:: yaml
  168. log_fmt_jid: '[JID: %(jid)s]'
  169. External Logging Handlers
  170. -------------------------
  171. Besides the internal logging handlers used by salt, there are some external
  172. which can be used, see the :ref:`external logging handlers<external-logging-handlers>`
  173. document.