logging-config.asciidoc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. [[logging]]
  2. == Elasticsearch application 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-ref-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. [[logging-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. Log4J 2 log messages include a _level_ field, which is one of the following (in
  124. order of increasing verbosity):
  125. * `FATAL`
  126. * `ERROR`
  127. * `WARN`
  128. * `INFO`
  129. * `DEBUG`
  130. * `TRACE`
  131. By default {es} includes all messages at levels `INFO`, `WARN`, `ERROR` and
  132. `FATAL` in its logs, but filters out messages at levels `DEBUG` and `TRACE`.
  133. This is the recommended configuration. Do not filter out messages at `INFO` or
  134. higher log levels or else you may not be able to understand your cluster's
  135. behaviour or troubleshoot common problems. Do not enable logging at levels
  136. `DEBUG` or `TRACE` unless you are following instructions elsewhere in this
  137. manual which call for more detailed logging, or you are an expert user who will
  138. be reading the {es} source code to determine the meaning of the logs.
  139. Messages are logged by a hierarchy of loggers which matches the hierarchy of
  140. Java packages and classes in the {es-repo}[{es} source code]. Every logger has
  141. a corresponding <<cluster-update-settings,dynamic setting>> which can be used
  142. to control the verbosity of its logs. The setting's name is the fully-qualified
  143. name of the package or class, prefixed with `logger.`.
  144. You may set each logger's verbosity to the name of a log level, for instance
  145. `DEBUG`, which means that messages from this logger at levels up to the
  146. specified one will be included in the logs. You may also use the value `OFF` to
  147. suppress all messages from the logger.
  148. For example, the `org.elasticsearch.discovery` package contains functionality
  149. related to the <<discovery-hosts-providers,discovery>> process, and you can
  150. control the verbosity of its logs with the `logger.org.elasticsearch.discovery`
  151. setting. To enable `DEBUG` logging for this package, use the
  152. <<cluster-update-settings,Cluster update settings API>> as follows:
  153. [source,console]
  154. ----
  155. PUT /_cluster/settings
  156. {
  157. "persistent": {
  158. "logger.org.elasticsearch.discovery": "DEBUG"
  159. }
  160. }
  161. ----
  162. To reset this package's log verbosity to its default level, set the logger
  163. setting to `null`:
  164. [source,console]
  165. ----
  166. PUT /_cluster/settings
  167. {
  168. "persistent": {
  169. "logger.org.elasticsearch.discovery": null
  170. }
  171. }
  172. ----
  173. Other ways to change log levels include:
  174. 1. `elasticsearch.yml`:
  175. +
  176. --
  177. [source,yaml]
  178. ----
  179. logger.org.elasticsearch.discovery: DEBUG
  180. ----
  181. This is most appropriate when debugging a problem on a single node.
  182. --
  183. 2. `log4j2.properties`:
  184. +
  185. --
  186. [source,properties]
  187. ----
  188. logger.discovery.name = org.elasticsearch.discovery
  189. logger.discovery.level = debug
  190. ----
  191. This is most appropriate when you already need to change your Log4j 2
  192. configuration for other reasons. For example, you may want to send logs for a
  193. particular logger to another file. However, these use cases are rare.
  194. --
  195. IMPORTANT: {es}'s application logs are intended for humans to read and
  196. interpret. Different versions of {es} may report information in these logs in
  197. different ways, perhaps adding extra detail, removing unnecessary information,
  198. formatting the same information in different ways, renaming the logger or
  199. adjusting the log level for specific messages. Do not rely on the contents of
  200. the application logs remaining precisely the same between versions.
  201. NOTE: To prevent leaking sensitive information in logs, {es} suppresses certain
  202. log messages by default even at the highest verbosity levels. To disable this
  203. protection on a node, set the Java system property
  204. `es.insecure_network_trace_enabled` to `true`. This feature is primarily
  205. intended for test systems which do not contain any sensitive information. If you
  206. set this property on a system which contains sensitive information, you must
  207. protect your logs from unauthorized access.
  208. [discrete]
  209. [[deprecation-logging]]
  210. === Deprecation logging
  211. {es} also writes deprecation logs to the log directory. These logs record a
  212. message when you use deprecated {es} functionality. You can use the deprecation
  213. logs to update your application before upgrading {es} to a new major version.
  214. By default, {es} rolls and compresses deprecation logs at 1GB. The default
  215. configuration preserves a maximum of five log files: four rolled logs and an
  216. active log.
  217. {es} emits deprecation log messages at the `CRITICAL` level. Those messages
  218. are indicating that a used deprecation feature will be removed in a next major
  219. version. Deprecation log messages at the `WARN` level indicates that a less
  220. critical feature was used, it won't be removed in next major version, but might
  221. be removed in the future.
  222. To stop writing deprecation log messages, set `logger.deprecation.level`
  223. to `OFF` in `log4j2.properties` :
  224. [source,properties]
  225. ----
  226. logger.deprecation.level = OFF
  227. ----
  228. Alternatively, you can change the logging level dynamically:
  229. [source,console]
  230. ----
  231. PUT /_cluster/settings
  232. {
  233. "persistent": {
  234. "logger.org.elasticsearch.deprecation": "OFF"
  235. }
  236. }
  237. ----
  238. Refer to <<configuring-logging-levels,Configuring logging levels>>.
  239. You can identify what is triggering deprecated functionality if `X-Opaque-Id` was used as an HTTP header.
  240. The user ID is included in the `X-Opaque-ID` field in deprecation JSON logs.
  241. [source,js]
  242. ---------------------------
  243. {
  244. "type": "deprecation",
  245. "timestamp": "2019-08-30T12:07:07,126+02:00",
  246. "level": "WARN",
  247. "component": "o.e.d.r.a.a.i.RestCreateIndexAction",
  248. "cluster.name": "distribution_run",
  249. "node.name": "node-0",
  250. "message": "[types removal] Using include_type_name in create index requests is deprecated. The parameter will be removed in the next major version.",
  251. "x-opaque-id": "MY_USER_ID",
  252. "cluster.uuid": "Aq-c-PAeQiK3tfBYtig9Bw",
  253. "node.id": "D7fUYfnfTLa2D7y-xw6tZg"
  254. }
  255. ---------------------------
  256. // NOTCONSOLE
  257. Deprecation logs can be indexed into `.logs-deprecation.elasticsearch-default` data stream
  258. `cluster.deprecation_indexing.enabled` setting is set to true.
  259. [discrete]
  260. ==== Deprecation logs throttling
  261. :es-rate-limiting-filter-java-doc: {elasticsearch-javadoc}/org/elasticsearch/common/logging/RateLimitingFilter.html
  262. Deprecation logs are deduplicated based on a deprecated feature key
  263. and x-opaque-id so that if a feature is repeatedly used, it will not overload the deprecation logs.
  264. This applies to both indexed deprecation logs and logs emitted to log files.
  265. You can disable the use of `x-opaque-id` in throttling by changing
  266. `cluster.deprecation_indexing.x_opaque_id_used.enabled` to false,
  267. refer to this class {es-rate-limiting-filter-java-doc}[javadoc] for more details.
  268. [discrete]
  269. [[json-logging]]
  270. === JSON log format
  271. To make parsing Elasticsearch logs easier, logs are now printed in a JSON format.
  272. This is configured by a Log4J layout property `appender.rolling.layout.type = ECSJsonLayout`.
  273. This layout requires a `dataset` attribute to be set which is used to distinguish
  274. logs streams when parsing.
  275. [source,properties]
  276. --------------------------------------------------
  277. appender.rolling.layout.type = ECSJsonLayout
  278. appender.rolling.layout.dataset = elasticsearch.server
  279. --------------------------------------------------
  280. :es-json-layout-java-doc: {elasticsearch-javadoc}/org/elasticsearch/common/logging/ESJsonLayout.html
  281. Each line contains a single JSON document with the properties configured in `ECSJsonLayout`.
  282. See this class {es-json-layout-java-doc}[javadoc] for more details.
  283. However if a JSON document contains an exception, it will be printed over multiple lines.
  284. The first line will contain regular properties and subsequent lines will contain the
  285. stacktrace formatted as a JSON array.
  286. NOTE: You can still use your own custom layout. To do that replace the line
  287. `appender.rolling.layout.type` with a different layout. See sample below:
  288. [source,properties]
  289. --------------------------------------------------
  290. appender.rolling.type = RollingFile
  291. appender.rolling.name = rolling
  292. appender.rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_server.log
  293. appender.rolling.layout.type = PatternLayout
  294. appender.rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] [%node_name]%marker %.-10000m%n
  295. appender.rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-%d{yyyy-MM-dd}-%i.log.gz
  296. --------------------------------------------------