logging-config.asciidoc 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. [[logging]]
  2. === Logging configuration
  3. Elasticsearch uses https://logging.apache.org/log4j/2.x/[Log4j 2] for
  4. logging. Log4j 2 can be configured using the log4j2.properties
  5. file. Elasticsearch exposes three properties, `${sys:es.logs.base_path}`,
  6. `${sys:es.logs.cluster_name}`, and `${sys:es.logs.node_name}` (if the node name
  7. is explicitly set via `node.name`) that can be referenced in the configuration
  8. file to determine the location of the log files. The property
  9. `${sys:es.logs.base_path}` will resolve to the log directory,
  10. `${sys:es.logs.cluster_name}` will resolve to the cluster name (used as the
  11. prefix of log filenames in the default configuration), and
  12. `${sys:es.logs.node_name}` will resolve to the node name (if the node name is
  13. explicitly set).
  14. For example, if your log directory (`path.logs`) is `/var/log/elasticsearch` and
  15. your cluster is named `production` then `${sys:es.logs.base_path}` will resolve
  16. to `/var/log/elasticsearch` and
  17. `${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}.log`
  18. will resolve to `/var/log/elasticsearch/production.log`.
  19. [source,properties]
  20. --------------------------------------------------
  21. appender.rolling.type = RollingFile <1>
  22. appender.rolling.name = rolling
  23. appender.rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}.log <2>
  24. appender.rolling.layout.type = PatternLayout
  25. appender.rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] [%node_name]%marker %.-10000m%n
  26. appender.rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-%d{yyyy-MM-dd}-%i.log.gz <3>
  27. appender.rolling.policies.type = Policies
  28. appender.rolling.policies.time.type = TimeBasedTriggeringPolicy <4>
  29. appender.rolling.policies.time.interval = 1 <5>
  30. appender.rolling.policies.time.modulate = true <6>
  31. appender.rolling.policies.size.type = SizeBasedTriggeringPolicy <7>
  32. appender.rolling.policies.size.size = 256MB <8>
  33. appender.rolling.strategy.type = DefaultRolloverStrategy
  34. appender.rolling.strategy.fileIndex = nomax
  35. appender.rolling.strategy.action.type = Delete <9>
  36. appender.rolling.strategy.action.basepath = ${sys:es.logs.base_path}
  37. appender.rolling.strategy.action.condition.type = IfFileName <10>
  38. appender.rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}-* <11>
  39. appender.rolling.strategy.action.condition.nested_condition.type = IfAccumulatedFileSize <12>
  40. appender.rolling.strategy.action.condition.nested_condition.exceeds = 2GB <13>
  41. --------------------------------------------------
  42. <1> Configure the `RollingFile` appender
  43. <2> Log to `/var/log/elasticsearch/production.log`
  44. <3> Roll logs to `/var/log/elasticsearch/production-yyyy-MM-dd-i.log`; logs
  45. will be compressed on each roll and `i` will be incremented
  46. <4> Use a time-based roll policy
  47. <5> Roll logs on a daily basis
  48. <6> Align rolls on the day boundary (as opposed to rolling every twenty-four
  49. hours)
  50. <7> Using a size-based roll policy
  51. <8> Roll logs after 256 MB
  52. <9> Use a delete action when rolling logs
  53. <10> Only delete logs matching a file pattern
  54. <11> The pattern is to only delete the main logs
  55. <12> Only delete if we have accumulated too many compressed logs
  56. <13> The size condition on the compressed logs is 2 GB
  57. NOTE: Log4j's configuration parsing gets confused by any extraneous whitespace;
  58. if you copy and paste any Log4j settings on this page, or enter any Log4j
  59. configuration in general, be sure to trim any leading and trailing whitespace.
  60. Note than you can replace `.gz` by `.zip` in `appender.rolling.filePattern` to
  61. compress the rolled logs using the zip format. If you remove the `.gz`
  62. extension then logs will not be compressed as they are rolled.
  63. If you want to retain log files for a specified period of time, you can use a
  64. rollover strategy with a delete action.
  65. [source,properties]
  66. --------------------------------------------------
  67. appender.rolling.strategy.type = DefaultRolloverStrategy <1>
  68. appender.rolling.strategy.action.type = Delete <2>
  69. appender.rolling.strategy.action.basepath = ${sys:es.logs.base_path} <3>
  70. appender.rolling.strategy.action.condition.type = IfFileName <4>
  71. appender.rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}-* <5>
  72. appender.rolling.strategy.action.condition.nested_condition.type = IfLastModified <6>
  73. appender.rolling.strategy.action.condition.nested_condition.age = 7D <7>
  74. --------------------------------------------------
  75. <1> Configure the `DefaultRolloverStrategy`
  76. <2> Configure the `Delete` action for handling rollovers
  77. <3> The base path to the Elasticsearch logs
  78. <4> The condition to apply when handling rollovers
  79. <5> Delete files from the base path matching the glob
  80. `${sys:es.logs.cluster_name}-*`; this is the glob that log files are rolled
  81. to; this is needed to only delete the rolled Elasticsearch logs but not also
  82. delete the deprecation and slow logs
  83. <6> A nested condition to apply to files matching the glob
  84. <7> Retain logs for seven days
  85. Multiple configuration files can be loaded (in which case they will get merged)
  86. as long as they are named `log4j2.properties` and have the Elasticsearch config
  87. directory as an ancestor; this is useful for plugins that expose additional
  88. loggers. The logger section contains the java packages and their corresponding
  89. log level. The appender section contains the destinations for the logs.
  90. Extensive information on how to customize logging and all the supported
  91. appenders can be found on the
  92. http://logging.apache.org/log4j/2.x/manual/configuration.html[Log4j
  93. documentation].
  94. [float]
  95. [[configuring-logging-levels]]
  96. === Configuring logging levels
  97. There are four ways to configuring logging levels, each having situations in which they are appropriate to use.
  98. 1. Via the command-line: `-E <name of logging hierarchy>=<level>` (e.g.,
  99. `-E logger.org.elasticsearch.transport=trace`). This is most appropriate when
  100. you are temporarily debugging a problem on a single node (for example, a
  101. problem with startup, or during development).
  102. 2. Via `elasticsearch.yml`: `<name of logging hierarchy>: <level>` (e.g.,
  103. `logger.org.elasticsearch.transport: trace`). This is most appropriate when
  104. you are temporarily debugging a problem but are not starting Elasticsearch
  105. via the command-line (e.g., via a service) or you want a logging level
  106. adjusted on a more permanent basis.
  107. 3. Via <<cluster-logger,cluster settings>>:
  108. +
  109. --
  110. [source,js]
  111. -------------------------------
  112. PUT /_cluster/settings
  113. {
  114. "transient": {
  115. "<name of logging hierarchy>": "<level>"
  116. }
  117. }
  118. -------------------------------
  119. // NOTCONSOLE
  120. For example:
  121. [source,js]
  122. -------------------------------
  123. PUT /_cluster/settings
  124. {
  125. "transient": {
  126. "logger.org.elasticsearch.transport": "trace"
  127. }
  128. }
  129. -------------------------------
  130. // CONSOLE
  131. This is most appropriate when you need to dynamically need to adjust a logging
  132. level on an actively-running cluster.
  133. --
  134. 4. Via the `log4j2.properties`:
  135. +
  136. --
  137. [source,properties]
  138. --------------------------------------------------
  139. logger.<unique_identifier>.name = <name of logging hierarchy>
  140. logger.<unique_identifier>.level = <level>
  141. --------------------------------------------------
  142. For example:
  143. [source,properties]
  144. --------------------------------------------------
  145. logger.transport.name = org.elasticsearch.transport
  146. logger.transport.level = trace
  147. --------------------------------------------------
  148. This is most appropriate when you need fine-grained control over the logger (for
  149. example, you want to send the logger to another file, or manage the logger
  150. differently; this is a rare use-case).
  151. --
  152. [float]
  153. [[deprecation-logging]]
  154. === Deprecation logging
  155. In addition to regular logging, Elasticsearch allows you to enable logging
  156. of deprecated actions. For example this allows you to determine early, if
  157. you need to migrate certain functionality in the future. By default,
  158. deprecation logging is enabled at the WARN level, the level at which all
  159. deprecation log messages will be emitted.
  160. [source,properties]
  161. --------------------------------------------------
  162. logger.deprecation.level = warn
  163. --------------------------------------------------
  164. This will create a daily rolling deprecation log file in your log directory.
  165. Check this file regularly, especially when you intend to upgrade to a new
  166. major version.
  167. The default logging configuration has set the roll policy for the deprecation
  168. logs to roll and compress after 1 GB, and to preserve a maximum of five log
  169. files (four rolled logs, and the active log).
  170. You can disable it in the `config/log4j2.properties` file by setting the deprecation
  171. log level to `error`.