logging.rst 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. ~~~~~~~~~~~~~~~~~~~
  47. The below table describes the logging levels in more detail, ordered
  48. in highest priority to lowest. The "Config File Value" is the string
  49. provided to the ``loglevel`` parameter in the ``[supervisord]``
  50. section of configuration file and the "Output Code" is the code that
  51. shows up in activity log output lines.
  52. ================= =========== ============================================
  53. Config File Value Output Code Description
  54. ================= =========== ============================================
  55. critical CRIT Messages that indicate a condition that
  56. requires immediate user attention, a
  57. supervisor state change, or an error in
  58. supervisor itself.
  59. error ERRO Messages that indicate a potentially
  60. ignorable error condition (e.g. unable to
  61. clear a log directory).
  62. warn WARN Messages that indicate an anomalous
  63. condition which isn't an error.
  64. info INFO Normal informational output. This is the
  65. default log level if none is explicitly
  66. configured.
  67. debug DEBG Messages useful for users trying to debug
  68. process configuration and communications
  69. behavior (process output, listener state
  70. changes, event notifications).
  71. trace TRAC Messages useful for developers trying to
  72. debug supervisor plugins, and information
  73. about HTTP and RPC requests and responses.
  74. blather BLAT Messages useful for developers trying to
  75. debug supervisor itself.
  76. ================= =========== ============================================
  77. Activity Log Rotation
  78. ~~~~~~~~~~~~~~~~~~~~~
  79. The activity log is "rotated" by :program:`supervisord`` based on the
  80. combination of the ``logfile_maxbytes`` and the ``logfile_backups``
  81. parameters in the ``[supervisord]`` section of the configuration file.
  82. When the activity log reaches ``logfile_maxbytes`` bytes, the current
  83. log file is moved to a backup file and a new activity log file is
  84. created. When this happens, if the number of existing backup files is
  85. greater than or equal to ``logfile_backups``, the oldest backup file
  86. is removed and the backup files are renamed accordingly. If the file
  87. being written to is named :file:`supervisord.log`, when it exceeds
  88. ``logfile_maxbytes``, it is closed and renamed to
  89. :file:`supervisord.log.1`, and if files :file:`supervisord.log.1`,
  90. :file:`supervisord.log.2` etc. exist, then they are renamed to
  91. :file:`supervisord.log.2`, :file:`supervisord.log.3` etc.
  92. respectively. If ``logfile_maxbytes`` is 0, the logfile is never
  93. rotated (and thus backups are never made). If ``logfile_backups`` is
  94. 0, an unlimited number of backups is created.
  95. Child Process Logs
  96. ------------------
  97. The stdout of child processes spawned by supervisor, by default, is
  98. captured for redisplay to users of :program:`supervisorctl` and other
  99. clients. If no specific logfile-related configuration is performed in
  100. a ``[program:x]``, ``[fcgi-program:x]``, or ``[eventlistener:x]``
  101. section in the configuration file, the following is true:
  102. - :program:`supervisord` will capture the child process' stdout and
  103. stderr output into temporary files. Each stream is captured to a
  104. separate file. This is known as ``AUTO`` log mode.
  105. - ``AUTO`` log files are named automatically and placed in the
  106. directory configured as ``childlogdir`` of the ``[supervisord]``
  107. section of the config file.
  108. - The size of each ``AUTO`` log file is bounded by the
  109. ``{streamname}_logfile_maxbytes`` value of the program section
  110. (where {streamname} is "stdout" or "stderr"). When it reaches that
  111. number, it is rotated (like the activity log), based on the
  112. ``{streamname}_logfile_backups``.
  113. The configuration keys that influence child process logging in
  114. ``[program:x]`` and ``[fcgi-program:x]`` sections are these:
  115. ``redirect_stderr``, ``stdout_logfile``, ``stdout_logfile_maxbytes``,
  116. ``stdout_logfile_backups``, ``stdout_capture_maxbytes``,
  117. ``stderr_logfile``, ``stderr_logfile_maxbytes``,
  118. ``stderr_logfile_backups`` and ``stderr_capture_maxbytes``.
  119. ``[eventlistener:x]`` sections may not specify
  120. ``stdout_capture_maxbytes`` or ``stderr_capture_maxbytes``,
  121. but otherwise they accept the same values.
  122. The configuration keys tht influence child process logging in the
  123. ``[supervisord]`` config file section are these:
  124. ``childlogdir``, and ``nocleanup``.
  125. Capture Mode
  126. ~~~~~~~~~~~~
  127. Capture mode is an advanced feature of Supervisor. You needn't
  128. understand capture mode unless you want to take actions based on data
  129. parsed from subprocess output.
  130. If a ``[program:x]`` section in the configuration file defines a
  131. non-zero ``stdout_capture_maxbytes`` or ``stderr_capture_maxbytes``
  132. parameter, each process represented by the program section may emit
  133. special tokens on its stdout or stderr stream (respectively) which
  134. will effectively cause supervisor to emit a ``PROCESS_COMMUNICATION``
  135. event (see :ref:`supervisor_events` for a description of events).
  136. The process communications protocol relies on two tags, one which
  137. commands supervisor to enter "capture mode" for the stream and one
  138. which commands it to exit. When a process stream enters "capture
  139. mode", data sent to the stream will be sent to a separate buffer in
  140. memory, the "capture buffer", which is allowed to contain a maximum of
  141. ``capture_maxbytes`` bytes. During capture mode, when the buffer's
  142. length exceeds ``capture_maxbytes`` bytes, the earliest data in the
  143. buffer is discarded to make room for new data. When a process stream
  144. exits capture mode, a ``PROCESS_COMMUNICATION`` event subtype is
  145. emitted by supervisor, which may be intercepted by event listeners.
  146. The tag to begin "capture mode" in a process stream is
  147. ``<!--XSUPERVISOR:BEGIN-->``. The tag to exit capture mode is
  148. ``<!--XSUPERVISOR:END-->``. The data between these tags may be
  149. arbitrary, and forms the payload of the ``PROCESS_COMMUNICATION``
  150. event. For example, if a program is set up with a
  151. ``stdout_capture_maxbytes`` of "1MB", and it emits the following on
  152. its stdout stream:
  153. .. code-block:: text
  154. <!--XSUPERVISOR:BEGIN-->Hello!<!--XSUPERVISOR:END-->
  155. In this circumstance, :program:`supervisord` will emit a
  156. ``PROCESS_COMMUNICATIONS_STDOUT`` event with data in the payload of
  157. "Hello!".
  158. An example of a script (written in Python) which emits a process
  159. communication event is in the :file:`scripts` directory of the
  160. supervisor package, named :file:`sample_commevent.py`.
  161. The output of processes specified as "event listeners"
  162. (``[eventlistener:x]`` sections) is not processed this way.
  163. Output from these processes cannot enter capture mode.