logging-config.asciidoc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. [[logging]]
  2. === Logging
  3. You can use {es}'s application logs to monitor your cluster and diagnose issues.
  4. If you run {es} as a service, the default location of the logs varies based on
  5. your platform and installation method:
  6. include::{es-repo-dir}/tab-widgets/logging-widget.asciidoc[]
  7. If you run {es} from the command line, {es} prints logs to the standard output
  8. (`stdout`).
  9. [discrete]
  10. [[loggin-configuration]]
  11. === Logging configuration
  12. IMPORTANT: Elastic strongly recommends using the Log4j 2 configuration that is shipped by default.
  13. Elasticsearch uses https://logging.apache.org/log4j/2.x/[Log4j 2] for
  14. logging. Log4j 2 can be configured using the log4j2.properties
  15. file. Elasticsearch exposes three properties, `${sys:es.logs.base_path}`,
  16. `${sys:es.logs.cluster_name}`, and `${sys:es.logs.node_name}` that can be
  17. referenced in the configuration file to determine the location of the log
  18. files. The property `${sys:es.logs.base_path}` will resolve to the log directory,
  19. `${sys:es.logs.cluster_name}` will resolve to the cluster name (used as the
  20. prefix of log filenames in the default configuration), and
  21. `${sys:es.logs.node_name}` will resolve to the node name (if the node name is
  22. explicitly set).
  23. For example, if your log directory (`path.logs`) is `/var/log/elasticsearch` and
  24. your cluster is named `production` then `${sys:es.logs.base_path}` will resolve
  25. to `/var/log/elasticsearch` and
  26. `${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}.log`
  27. will resolve to `/var/log/elasticsearch/production.log`.
  28. [source,properties]
  29. --------------------------------------------------
  30. ######## Server JSON ############################
  31. appender.rolling.type = RollingFile <1>
  32. appender.rolling.name = rolling
  33. appender.rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_server.json <2>
  34. appender.rolling.layout.type = ECSJsonLayout <3>
  35. appender.rolling.layout.dataset = elasticsearch.server <4>
  36. appender.rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-%d{yyyy-MM-dd}-%i.json.gz <5>
  37. appender.rolling.policies.type = Policies
  38. appender.rolling.policies.time.type = TimeBasedTriggeringPolicy <6>
  39. appender.rolling.policies.time.interval = 1 <7>
  40. appender.rolling.policies.time.modulate = true <8>
  41. appender.rolling.policies.size.type = SizeBasedTriggeringPolicy <9>
  42. appender.rolling.policies.size.size = 256MB <10>
  43. appender.rolling.strategy.type = DefaultRolloverStrategy
  44. appender.rolling.strategy.fileIndex = nomax
  45. appender.rolling.strategy.action.type = Delete <11>
  46. appender.rolling.strategy.action.basepath = ${sys:es.logs.base_path}
  47. appender.rolling.strategy.action.condition.type = IfFileName <12>
  48. appender.rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}-* <13>
  49. appender.rolling.strategy.action.condition.nested_condition.type = IfAccumulatedFileSize <14>
  50. appender.rolling.strategy.action.condition.nested_condition.exceeds = 2GB <15>
  51. ################################################
  52. --------------------------------------------------
  53. <1> Configure the `RollingFile` appender
  54. <2> Log to `/var/log/elasticsearch/production_server.json`
  55. <3> Use JSON layout.
  56. <4> `dataset` is a flag populating the `event.dataset` field in a `ECSJsonLayout`.
  57. It can be used to distinguish different types of logs more easily when parsing them.
  58. <5> Roll logs to `/var/log/elasticsearch/production-yyyy-MM-dd-i.json`; logs
  59. will be compressed on each roll and `i` will be incremented
  60. <6> Use a time-based roll policy
  61. <7> Roll logs on a daily basis
  62. <8> Align rolls on the day boundary (as opposed to rolling every twenty-four
  63. hours)
  64. <9> Using a size-based roll policy
  65. <10> Roll logs after 256 MB
  66. <11> Use a delete action when rolling logs
  67. <12> Only delete logs matching a file pattern
  68. <13> The pattern is to only delete the main logs
  69. <14> Only delete if we have accumulated too many compressed logs
  70. <15> The size condition on the compressed logs is 2 GB
  71. [source,properties]
  72. --------------------------------------------------
  73. ######## Server - old style pattern ###########
  74. appender.rolling_old.type = RollingFile
  75. appender.rolling_old.name = rolling_old
  76. appender.rolling_old.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_server.log <1>
  77. appender.rolling_old.layout.type = PatternLayout
  78. appender.rolling_old.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] [%node_name]%marker %m%n
  79. appender.rolling_old.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-%d{yyyy-MM-dd}-%i.old_log.gz
  80. --------------------------------------------------
  81. <1> The configuration for `old style` pattern appenders. These logs will be saved in `*.log` files and if archived will be in `*
  82. .log.gz` files. Note that these should be considered deprecated and will be removed in the future.
  83. NOTE: Log4j's configuration parsing gets confused by any extraneous whitespace;
  84. if you copy and paste any Log4j settings on this page, or enter any Log4j
  85. configuration in general, be sure to trim any leading and trailing whitespace.
  86. Note than you can replace `.gz` by `.zip` in `appender.rolling.filePattern` to
  87. compress the rolled logs using the zip format. If you remove the `.gz`
  88. extension then logs will not be compressed as they are rolled.
  89. If you want to retain log files for a specified period of time, you can use a
  90. rollover strategy with a delete action.
  91. [source,properties]
  92. --------------------------------------------------
  93. appender.rolling.strategy.type = DefaultRolloverStrategy <1>
  94. appender.rolling.strategy.action.type = Delete <2>
  95. appender.rolling.strategy.action.basepath = ${sys:es.logs.base_path} <3>
  96. appender.rolling.strategy.action.condition.type = IfFileName <4>
  97. appender.rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}-* <5>
  98. appender.rolling.strategy.action.condition.nested_condition.type = IfLastModified <6>
  99. appender.rolling.strategy.action.condition.nested_condition.age = 7D <7>
  100. --------------------------------------------------
  101. <1> Configure the `DefaultRolloverStrategy`
  102. <2> Configure the `Delete` action for handling rollovers
  103. <3> The base path to the Elasticsearch logs
  104. <4> The condition to apply when handling rollovers
  105. <5> Delete files from the base path matching the glob
  106. `${sys:es.logs.cluster_name}-*`; this is the glob that log files are rolled
  107. to; this is needed to only delete the rolled Elasticsearch logs but not also
  108. delete the deprecation and slow logs
  109. <6> A nested condition to apply to files matching the glob
  110. <7> Retain logs for seven days
  111. Multiple configuration files can be loaded (in which case they will get merged)
  112. as long as they are named `log4j2.properties` and have the Elasticsearch config
  113. directory as an ancestor; this is useful for plugins that expose additional
  114. loggers. The logger section contains the java packages and their corresponding
  115. log level. The appender section contains the destinations for the logs.
  116. Extensive information on how to customize logging and all the supported
  117. appenders can be found on the
  118. https://logging.apache.org/log4j/2.x/manual/configuration.html[Log4j
  119. documentation].
  120. [discrete]
  121. [[configuring-logging-levels]]
  122. === Configuring logging levels
  123. Each Java package in the {es-repo}[{es} source code] has a related logger. For
  124. example, the `org.elasticsearch.discovery` package has
  125. `logger.org.elasticsearch.discovery` for logs related to the
  126. <<discovery-hosts-providers,discovery>> process.
  127. To get more or less verbose logs, use the <<cluster-update-settings,cluster
  128. update settings API>> to change the related logger's log level. Each logger
  129. accepts Log4j 2's built-in log levels, from least to most verbose: `OFF`,
  130. `FATAL`, `ERROR`, `WARN`, `INFO`, `DEBUG`, and `TRACE`. The default log level is
  131. `INFO`. Messages logged at higher verbosity levels (`DEBUG` and `TRACE`) are
  132. only intended for expert use.
  133. [source,console]
  134. ----
  135. PUT /_cluster/settings
  136. {
  137. "persistent": {
  138. "logger.org.elasticsearch.discovery": "DEBUG"
  139. }
  140. }
  141. ----
  142. To reset a logger's verbosity to its default level, set the logger setting to
  143. `null`:
  144. [source,console]
  145. ----
  146. PUT /_cluster/settings
  147. {
  148. "persistent": {
  149. "logger.org.elasticsearch.discovery": null
  150. }
  151. }
  152. ----
  153. Other ways to change log levels include:
  154. 1. `elasticsearch.yml`:
  155. +
  156. --
  157. [source,yaml]
  158. ----
  159. logger.org.elasticsearch.discovery: DEBUG
  160. ----
  161. This is most appropriate when debugging a problem on a single node.
  162. --
  163. 2. `log4j2.properties`:
  164. +
  165. --
  166. [source,properties]
  167. ----
  168. logger.discovery.name = org.elasticsearch.discovery
  169. logger.discovery.level = debug
  170. ----
  171. This is most appropriate when you already need to change your Log4j 2
  172. configuration for other reasons. For example, you may want to send logs for a
  173. particular logger to another file. However, these use cases are rare.
  174. --
  175. [discrete]
  176. [[deprecation-logging]]
  177. === Deprecation logging
  178. {es} also writes deprecation logs to the log directory. These logs record a
  179. message when you use deprecated {es} functionality. You can use the deprecation
  180. logs to update your application before upgrading {es} to a new major version.
  181. By default, {es} rolls and compresses deprecation logs at 1GB. The default
  182. configuration preserves a maximum of five log files: four rolled logs and an
  183. active log.
  184. {es} emits deprecation log messages at the `CRITICAL` level. Those messages
  185. are indicating that a used deprecation feature will be removed in a next major
  186. version. Deprecation log messages at the `WARN` level indicates that a less
  187. critical feature was used, it won't be removed in next major version, but might
  188. be removed in the future.
  189. To stop writing deprecation log messages, set `logger.deprecation.level`
  190. to `OFF` in `log4j2.properties` :
  191. [source,properties]
  192. ----
  193. logger.deprecation.level = OFF
  194. ----
  195. Alternatively, you can change the logging level dynamically:
  196. [source,console]
  197. ----
  198. PUT /_cluster/settings
  199. {
  200. "persistent": {
  201. "logger.org.elasticsearch.deprecation": "OFF"
  202. }
  203. }
  204. ----
  205. Refer to <<configuring-logging-levels,Configuring logging levels>>.
  206. You can identify what is triggering deprecated functionality if `X-Opaque-Id` was used as an HTTP header.
  207. The user ID is included in the `X-Opaque-ID` field in deprecation JSON logs.
  208. [source,js]
  209. ---------------------------
  210. {
  211. "type": "deprecation",
  212. "timestamp": "2019-08-30T12:07:07,126+02:00",
  213. "level": "WARN",
  214. "component": "o.e.d.r.a.a.i.RestCreateIndexAction",
  215. "cluster.name": "distribution_run",
  216. "node.name": "node-0",
  217. "message": "[types removal] Using include_type_name in create index requests is deprecated. The parameter will be removed in the next major version.",
  218. "x-opaque-id": "MY_USER_ID",
  219. "cluster.uuid": "Aq-c-PAeQiK3tfBYtig9Bw",
  220. "node.id": "D7fUYfnfTLa2D7y-xw6tZg"
  221. }
  222. ---------------------------
  223. // NOTCONSOLE
  224. Deprecation logs can be indexed into `.logs-deprecation.elasticsearch-default` data stream
  225. `cluster.deprecation_indexing.enabled` setting is set to true.
  226. ==== Deprecation logs throttling
  227. :es-rate-limiting-filter-java-doc: {elasticsearch-javadoc}/org/elasticsearch/common/logging/RateLimitingFilter.html
  228. Deprecation logs are deduplicated based on a deprecated feature key
  229. and x-opaque-id so that if a feature is repeatedly used, it will not overload the deprecation logs.
  230. This applies to both indexed deprecation logs and logs emitted to log files.
  231. You can disable the use of `x-opaque-id` in throttling by changing
  232. `cluster.deprecation_indexing.x_opaque_id_used.enabled` to false,
  233. refer to this class {es-rate-limiting-filter-java-doc}[javadoc] for more details.
  234. [discrete]
  235. [[json-logging]]
  236. === JSON log format
  237. To make parsing Elasticsearch logs easier, logs are now printed in a JSON format.
  238. This is configured by a Log4J layout property `appender.rolling.layout.type = ECSJsonLayout`.
  239. This layout requires a `dataset` attribute to be set which is used to distinguish
  240. logs streams when parsing.
  241. [source,properties]
  242. --------------------------------------------------
  243. appender.rolling.layout.type = ECSJsonLayout
  244. appender.rolling.layout.dataset = elasticsearch.server
  245. --------------------------------------------------
  246. :es-json-layout-java-doc: {elasticsearch-javadoc}/org/elasticsearch/common/logging/ESJsonLayout.html
  247. Each line contains a single JSON document with the properties configured in `ECSJsonLayout`.
  248. See this class {es-json-layout-java-doc}[javadoc] for more details.
  249. However if a JSON document contains an exception, it will be printed over multiple lines.
  250. The first line will contain regular properties and subsequent lines will contain the
  251. stacktrace formatted as a JSON array.
  252. NOTE: You can still use your own custom layout. To do that replace the line
  253. `appender.rolling.layout.type` with a different layout. See sample below:
  254. [source,properties]
  255. --------------------------------------------------
  256. appender.rolling.type = RollingFile
  257. appender.rolling.name = rolling
  258. appender.rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_server.log
  259. appender.rolling.layout.type = PatternLayout
  260. appender.rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] [%node_name]%marker %.-10000m%n
  261. appender.rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-%d{yyyy-MM-dd}-%i.log.gz
  262. --------------------------------------------------