logging.rst 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. Logging
  2. =======
  3. One of the main tasks that :program:`supervisord` performs is logging.
  4. :program:`supervisord` logs an activity log detailing what it's doing
  5. as it runs. It also logs child process stdout and stderr output to
  6. other files if configured to do so.
  7. Activity Log
  8. ------------
  9. The activity log is the place where :program:`supervisord` logs
  10. messages about its own health, its subprocess' state changes, any
  11. messages that result from events, and debug and informational
  12. messages. The path to the activity log is configured via the
  13. ``logfile`` parameter in the ``[supervisord]`` section of the
  14. configuration file, defaulting to :file:`$CWD/supervisord.log`.
  15. Sample activity log traffic is shown in the example below. Some lines
  16. have been broken to better fit the screen.
  17. Sample Activity Log Output
  18. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  19. .. code-block:: text
  20. 2007-09-08 14:43:22,886 DEBG 127.0.0.1:Medusa (V1.11) started at Sat Sep 8 14:43:22 2007
  21. Hostname: kingfish
  22. Port:9001
  23. 2007-09-08 14:43:22,961 INFO RPC interface 'supervisor' initialized
  24. 2007-09-08 14:43:22,961 CRIT Running without any HTTP authentication checking
  25. 2007-09-08 14:43:22,962 INFO supervisord started with pid 27347
  26. 2007-09-08 14:43:23,965 INFO spawned: 'listener_00' with pid 27349
  27. 2007-09-08 14:43:23,970 INFO spawned: 'eventgen' with pid 27350
  28. 2007-09-08 14:43:23,990 INFO spawned: 'grower' with pid 27351
  29. 2007-09-08 14:43:24,059 DEBG 'listener_00' stderr output:
  30. /Users/chrism/projects/supervisor/supervisor2/dev-sandbox/bin/python:
  31. can't open file '/Users/chrism/projects/supervisor/supervisor2/src/supervisor/scripts/osx_eventgen_listener.py':
  32. [Errno 2] No such file or directory
  33. 2007-09-08 14:43:24,060 DEBG fd 7 closed, stopped monitoring <PEventListenerDispatcher at 19910168 for
  34. <Subprocess at 18892960 with name listener_00 in state STARTING> (stdout)>
  35. 2007-09-08 14:43:24,060 INFO exited: listener_00 (exit status 2; not expected)
  36. 2007-09-08 14:43:24,061 DEBG received SIGCHLD indicating a child quit
  37. The activity log "level" is configured in the config file via the
  38. ``loglevel`` parameter in the ``[supervisord]`` ini file section.
  39. When ``loglevel`` is set, messages of the specified priority, plus
  40. those with any higher priority are logged to the activity log. For
  41. example, if ``loglevel`` is ``error``, messages of ``error`` and
  42. ``critical`` priority will be logged. However, if loglevel is
  43. ``warn``, messages of ``warn``, ``error``, and ``critical`` will be
  44. logged.
  45. .. _activity_log_levels:
  46. Activity Log Levels
  47. ~~~~~~~~~~~~~~~~~~~
  48. The below table describes the logging levels in more detail, ordered
  49. in highest priority to lowest. The "Config File Value" is the string
  50. provided to the ``loglevel`` parameter in the ``[supervisord]``
  51. section of configuration file and the "Output Code" is the code that
  52. shows up in activity log output lines.
  53. ================= =========== ============================================
  54. Config File Value Output Code Description
  55. ================= =========== ============================================
  56. critical CRIT Messages that indicate a condition that
  57. requires immediate user attention, a
  58. supervisor state change, or an error in
  59. supervisor itself.
  60. error ERRO Messages that indicate a potentially
  61. ignorable error condition (e.g. unable to
  62. clear a log directory).
  63. warn WARN Messages that indicate an anomalous
  64. condition which isn't an error.
  65. info INFO Normal informational output. This is the
  66. default log level if none is explicitly
  67. configured.
  68. debug DEBG Messages useful for users trying to debug
  69. process configuration and communications
  70. behavior (process output, listener state
  71. changes, event notifications).
  72. trace TRAC Messages useful for developers trying to
  73. debug supervisor plugins, and information
  74. about HTTP and RPC requests and responses.
  75. blather BLAT Messages useful for developers trying to
  76. debug supervisor itself.
  77. ================= =========== ============================================
  78. Activity Log Rotation
  79. ~~~~~~~~~~~~~~~~~~~~~
  80. The activity log is "rotated" by :program:`supervisord` based on the
  81. combination of the ``logfile_maxbytes`` and the ``logfile_backups``
  82. parameters in the ``[supervisord]`` section of the configuration file.
  83. When the activity log reaches ``logfile_maxbytes`` bytes, the current
  84. log file is moved to a backup file and a new activity log file is
  85. created. When this happens, if the number of existing backup files is
  86. greater than or equal to ``logfile_backups``, the oldest backup file
  87. is removed and the backup files are renamed accordingly. If the file
  88. being written to is named :file:`supervisord.log`, when it exceeds
  89. ``logfile_maxbytes``, it is closed and renamed to
  90. :file:`supervisord.log.1`, and if files :file:`supervisord.log.1`,
  91. :file:`supervisord.log.2` etc. exist, then they are renamed to
  92. :file:`supervisord.log.2`, :file:`supervisord.log.3` etc.
  93. respectively. If ``logfile_maxbytes`` is 0, the logfile is never
  94. rotated (and thus backups are never made). If ``logfile_backups`` is
  95. 0, no backups will be kept.
  96. Child Process Logs
  97. ------------------
  98. The stdout of child processes spawned by supervisor, by default, is
  99. captured for redisplay to users of :program:`supervisorctl` and other
  100. clients. If no specific logfile-related configuration is performed in
  101. a ``[program:x]``, ``[fcgi-program:x]``, or ``[eventlistener:x]``
  102. section in the configuration file, the following is true:
  103. - :program:`supervisord` will capture the child process' stdout and
  104. stderr output into temporary files. Each stream is captured to a
  105. separate file. This is known as ``AUTO`` log mode.
  106. - ``AUTO`` log files are named automatically and placed in the
  107. directory configured as ``childlogdir`` of the ``[supervisord]``
  108. section of the config file.
  109. - The size of each ``AUTO`` log file is bounded by the
  110. ``{streamname}_logfile_maxbytes`` value of the program section
  111. (where {streamname} is "stdout" or "stderr"). When it reaches that
  112. number, it is rotated (like the activity log), based on the
  113. ``{streamname}_logfile_backups``.
  114. The configuration keys that influence child process logging in
  115. ``[program:x]`` and ``[fcgi-program:x]`` sections are these:
  116. ``redirect_stderr``, ``stdout_logfile``, ``stdout_logfile_maxbytes``,
  117. ``stdout_logfile_backups``, ``stdout_capture_maxbytes``, ``stdout_syslog``,
  118. ``stderr_logfile``, ``stderr_logfile_maxbytes``,
  119. ``stderr_logfile_backups``, ``stderr_capture_maxbytes``, and
  120. ``stderr_syslog``.
  121. ``[eventlistener:x]`` sections may not specify
  122. ``stdout_capture_maxbytes`` or ``stderr_capture_maxbytes``,
  123. but otherwise they accept the same values.
  124. The configuration keys that influence child process logging in the
  125. ``[supervisord]`` config file section are these:
  126. ``childlogdir``, and ``nocleanup``.
  127. .. _capture_mode:
  128. Capture Mode
  129. ~~~~~~~~~~~~
  130. Capture mode is an advanced feature of Supervisor. You needn't
  131. understand capture mode unless you want to take actions based on data
  132. parsed from subprocess output.
  133. If a ``[program:x]`` section in the configuration file defines a
  134. non-zero ``stdout_capture_maxbytes`` or ``stderr_capture_maxbytes``
  135. parameter, each process represented by the program section may emit
  136. special tokens on its stdout or stderr stream (respectively) which
  137. will effectively cause supervisor to emit a ``PROCESS_COMMUNICATION``
  138. event (see :ref:`events` for a description of events).
  139. The process communications protocol relies on two tags, one which
  140. commands supervisor to enter "capture mode" for the stream and one
  141. which commands it to exit. When a process stream enters "capture
  142. mode", data sent to the stream will be sent to a separate buffer in
  143. memory, the "capture buffer", which is allowed to contain a maximum of
  144. ``capture_maxbytes`` bytes. During capture mode, when the buffer's
  145. length exceeds ``capture_maxbytes`` bytes, the earliest data in the
  146. buffer is discarded to make room for new data. When a process stream
  147. exits capture mode, a ``PROCESS_COMMUNICATION`` event subtype is
  148. emitted by supervisor, which may be intercepted by event listeners.
  149. The tag to begin "capture mode" in a process stream is
  150. ``<!--XSUPERVISOR:BEGIN-->``. The tag to exit capture mode is
  151. ``<!--XSUPERVISOR:END-->``. The data between these tags may be
  152. arbitrary, and forms the payload of the ``PROCESS_COMMUNICATION``
  153. event. For example, if a program is set up with a
  154. ``stdout_capture_maxbytes`` of "1MB", and it emits the following on
  155. its stdout stream:
  156. .. code-block:: text
  157. <!--XSUPERVISOR:BEGIN-->Hello!<!--XSUPERVISOR:END-->
  158. In this circumstance, :program:`supervisord` will emit a
  159. ``PROCESS_COMMUNICATIONS_STDOUT`` event with data in the payload of
  160. "Hello!".
  161. An example of a script (written in Python) which emits a process
  162. communication event is in the :file:`scripts` directory of the
  163. supervisor package, named :file:`sample_commevent.py`.
  164. The output of processes specified as "event listeners"
  165. (``[eventlistener:x]`` sections) is not processed this way.
  166. Output from these processes cannot enter capture mode.