| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 | [[logging]]=== Logging configurationElasticsearch uses https://logging.apache.org/log4j/2.x/[Log4j 2] forlogging. Log4j 2 can be configured using the log4j2.propertiesfile. Elasticsearch exposes three properties, `${sys:es.logs.base_path}`,`${sys:es.logs.cluster_name}`, and `${sys:es.logs.node_name}` that can bereferenced in the configuration file to determine the location of the logfiles. The property `${sys:es.logs.base_path}` will resolve to the log directory,`${sys:es.logs.cluster_name}` will resolve to the cluster name (used as theprefix of log filenames in the default configuration), and`${sys:es.logs.node_name}` will resolve to the node name (if the node name isexplicitly set).For example, if your log directory (`path.logs`) is `/var/log/elasticsearch` andyour cluster is named `production` then `${sys:es.logs.base_path}` will resolveto `/var/log/elasticsearch` and`${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}.log`will resolve to `/var/log/elasticsearch/production.log`.[source,properties]--------------------------------------------------######## Server JSON ############################appender.rolling.type = RollingFile <1>appender.rolling.name = rollingappender.rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_server.json <2>appender.rolling.layout.type = ESJsonLayout <3>appender.rolling.layout.type_name = server <4>appender.rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-%d{yyyy-MM-dd}-%i.json.gz <5>appender.rolling.policies.type = Policiesappender.rolling.policies.time.type = TimeBasedTriggeringPolicy <6>appender.rolling.policies.time.interval = 1 <7>appender.rolling.policies.time.modulate = true <8>appender.rolling.policies.size.type = SizeBasedTriggeringPolicy <9>appender.rolling.policies.size.size = 256MB <10>appender.rolling.strategy.type = DefaultRolloverStrategyappender.rolling.strategy.fileIndex = nomaxappender.rolling.strategy.action.type = Delete <11>appender.rolling.strategy.action.basepath = ${sys:es.logs.base_path}appender.rolling.strategy.action.condition.type = IfFileName <12>appender.rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}-* <13>appender.rolling.strategy.action.condition.nested_condition.type = IfAccumulatedFileSize <14>appender.rolling.strategy.action.condition.nested_condition.exceeds = 2GB <15>################################################--------------------------------------------------<1> Configure the `RollingFile` appender<2> Log to `/var/log/elasticsearch/production.json`<3> Use JSON layout.<4> `type_name` is a flag populating the `type` field in a `ESJsonLayout`. It can be used to distinguish different types of logs more easily when parsing them.<5> Roll logs to `/var/log/elasticsearch/production-yyyy-MM-dd-i.json`; logs    will be compressed on each roll and `i` will be incremented<6> Use a time-based roll policy<7> Roll logs on a daily basis<8> Align rolls on the day boundary (as opposed to rolling every twenty-four    hours)<9> Using a size-based roll policy<10> Roll logs after 256 MB<11> Use a delete action when rolling logs<12> Only delete logs matching a file pattern<13> The pattern is to only delete the main logs<14> Only delete if we have accumulated too many compressed logs<15> The size condition on the compressed logs is 2 GB[source,properties]--------------------------------------------------######## Server -  old style pattern ###########appender.rolling_old.type = RollingFileappender.rolling_old.name = rolling_oldappender.rolling_old.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_server.log <1>appender.rolling_old.layout.type = PatternLayoutappender.rolling_old.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] [%node_name]%marker %m%nappender.rolling_old.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-%d{yyyy-MM-dd}-%i.old_log.gz--------------------------------------------------<1> The configuration for `old style` pattern appenders. These logs will be saved in `*.log` files and if archived will be in `*.log.gz` files. Note that these should be considered deprecated and will be removed in the future.NOTE: Log4j's configuration parsing gets confused by any extraneous whitespace;if you copy and paste any Log4j settings on this page, or enter any Log4jconfiguration in general, be sure to trim any leading and trailing whitespace.Note than you can replace `.gz` by `.zip` in `appender.rolling.filePattern` tocompress the rolled logs using the zip format. If you remove the `.gz`extension then logs will not be compressed as they are rolled.If you want to retain log files for a specified period of time, you can use arollover strategy with a delete action.[source,properties]--------------------------------------------------appender.rolling.strategy.type = DefaultRolloverStrategy <1>appender.rolling.strategy.action.type = Delete <2>appender.rolling.strategy.action.basepath = ${sys:es.logs.base_path} <3>appender.rolling.strategy.action.condition.type = IfFileName <4>appender.rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}-* <5>appender.rolling.strategy.action.condition.nested_condition.type = IfLastModified <6>appender.rolling.strategy.action.condition.nested_condition.age = 7D <7>--------------------------------------------------<1> Configure the `DefaultRolloverStrategy`<2> Configure the `Delete` action for handling rollovers<3> The base path to the Elasticsearch logs<4> The condition to apply when handling rollovers<5> Delete files from the base path matching the glob    `${sys:es.logs.cluster_name}-*`; this is the glob that log files are rolled    to; this is needed to only delete the rolled Elasticsearch logs but not also    delete the deprecation and slow logs<6> A nested condition to apply to files matching the glob<7> Retain logs for seven daysMultiple configuration files can be loaded (in which case they will get merged)as long as they are named `log4j2.properties` and have the Elasticsearch configdirectory as an ancestor; this is useful for plugins that expose additionalloggers. The logger section contains the java packages and their correspondinglog level. The appender section contains the destinations for the logs.Extensive information on how to customize logging and all the supportedappenders can be found on thehttp://logging.apache.org/log4j/2.x/manual/configuration.html[Log4jdocumentation].[float][[configuring-logging-levels]]=== Configuring logging levelsThere are four ways to configuring logging levels, each having situations in which they are appropriate to use.1. Via the command-line: `-E <name of logging hierarchy>=<level>` (e.g.,   `-E logger.org.elasticsearch.transport=trace`). This is most appropriate when   you are temporarily debugging a problem on a single node (for example, a   problem with startup, or during development).2. Via `elasticsearch.yml`: `<name of logging hierarchy>: <level>` (e.g.,   `logger.org.elasticsearch.transport: trace`). This is most appropriate when   you are temporarily debugging a problem but are not starting Elasticsearch   via the command-line (e.g., via a service) or you want a logging level   adjusted on a more permanent basis.3. Via <<cluster-logger,cluster settings>>:+--[source,js]-------------------------------PUT /_cluster/settings{  "transient": {    "<name of logging hierarchy>": "<level>"  }}-------------------------------// NOTCONSOLEFor example:[source,console]-------------------------------PUT /_cluster/settings{  "transient": {    "logger.org.elasticsearch.transport": "trace"  }}-------------------------------This is most appropriate when you need to dynamically need to adjust a logginglevel on an actively-running cluster.--4. Via the `log4j2.properties`:+--[source,properties]--------------------------------------------------logger.<unique_identifier>.name = <name of logging hierarchy>logger.<unique_identifier>.level = <level>--------------------------------------------------For example:[source,properties]--------------------------------------------------logger.transport.name = org.elasticsearch.transportlogger.transport.level = trace--------------------------------------------------This is most appropriate when you need fine-grained control over the logger (forexample, you want to send the logger to another file, or manage the loggerdifferently; this is a rare use-case).--[float][[deprecation-logging]]=== Deprecation loggingIn addition to regular logging, Elasticsearch allows you to enable loggingof deprecated actions. For example this allows you to determine early, ifyou need to migrate certain functionality in the future. By default,deprecation logging is enabled at the WARN level, the level at which alldeprecation log messages will be emitted.[source,properties]--------------------------------------------------logger.deprecation.level = warn--------------------------------------------------This will create a daily rolling deprecation log file in your log directory.Check this file regularly, especially when you intend to upgrade to a newmajor version.The default logging configuration has set the roll policy for the deprecationlogs to roll and compress after 1 GB, and to preserve a maximum of five logfiles (four rolled logs, and the active log).You can disable it in the `config/log4j2.properties` file by setting the deprecationlog level to `error`.You can identify what is triggering deprecated functionality if `X-Opaque-Id` was used as an HTTP header.The user ID is included in the `X-Opaque-ID` field in deprecation JSON logs.[source,js]---------------------------{  "type": "deprecation",  "timestamp": "2019-08-30T12:07:07,126+02:00",  "level": "WARN",  "component": "o.e.d.r.a.a.i.RestCreateIndexAction",  "cluster.name": "distribution_run",  "node.name": "node-0",  "message": "[types removal] Using include_type_name in create index requests is deprecated. The parameter will be removed in the next major version.",  "x-opaque-id": "MY_USER_ID",  "cluster.uuid": "Aq-c-PAeQiK3tfBYtig9Bw",  "node.id": "D7fUYfnfTLa2D7y-xw6tZg"}---------------------------// NOTCONSOLE[float][[json-logging]]=== JSON log formatTo make parsing Elasticsearch logs easier, logs are now printed in a JSON format.This is configured by a Log4J layout property `appender.rolling.layout.type = ESJsonLayout`.This layout requires a `type_name` attribute to be set which is used to distinguishlogs streams when parsing.[source,properties]--------------------------------------------------appender.rolling.layout.type = ESJsonLayoutappender.rolling.layout.type_name = server--------------------------------------------------:es-json-layout-java-doc: {elasticsearch-javadoc}/org/elasticsearch/common/logging/ESJsonLayout.htmlEach line contains a single JSON document with the properties configured in `ESJsonLayout`.See this class {es-json-layout-java-doc}[javadoc] for more details.However if a JSON document contains an exception, it will be printed over multiple lines.The first line will contain regular properties and subsequent lines will contain thestacktrace formatted as a JSON array.NOTE: You can still use your own custom layout. To do that replace the line`appender.rolling.layout.type` with a different layout. See sample below:[source,properties]--------------------------------------------------appender.rolling.type = RollingFileappender.rolling.name = rollingappender.rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_server.logappender.rolling.layout.type = PatternLayoutappender.rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] [%node_name]%marker %.-10000m%nappender.rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-%d{yyyy-MM-dd}-%i.log.gz--------------------------------------------------
 |