Logging in ZooKeeper

Overview

ZooKeeper records file system processes output and events in text logs. This information can be useful when diagnosing technical issues.

Each ZooKeeper component stores logs locally, on the host it occupies. The logs have the .log extension and are located in the /var/log/zookeeper/ directory. In the same directory, you can find .out files that contain component restart information.

The logs naming convention is zookeeper-<user>-<component>-<host>.log.

Where:

  • <user> — user running ZooKeeper;

  • <component> — component name, for example, ZooKeeper server;

  • <host> — FQDN of the component host.

The ZooKeeper uses for logging SLF4J and Log4J frameworks.

Grep logs

You can search through the logs for a specific information, like error messages. To do this, connect to the host with the component whose logs you want to inspect, and use a grep command.

For example:

$ cat /var/log/zookeeper/zookeeper-zookeeper-cli-elenas-adh3.ru-central1.internal.log | grep -i -A3 -B1 error

This command searches for messages containing the word error in the CLI log, located on the elenas-adh3.ru-central1.internal host. The i option allows you to ignore case distinctions. The -A3 -B1 options expand the output to one line before and three lines after the line containing the error.

The example output:

2023-11-28 12:39:02,986 [myid:] - INFO  [main:ClientCnxn@1681] - zookeeper.request.timeout value is 0. feature enabled=
2023-11-28 12:39:02,991 [myid:elenas-adh3.ru-central1.internal:2181] - INFO  [main-SendThread(elenas-adh3.ru-central1.internal:2181):ClientCnxn$SendThread@1125] - Opening socket connection to server elenas-adh3.ru-central1.internal/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
2023-11-28 12:39:03,041 [myid:elenas-adh3.ru-central1.internal:2181] - INFO  [main-SendThread(elenas-adh3.ru-central1.internal:2181):ClientCnxn$SendThread@972] - Socket connection established, initiating session, client: /127.0.0.1:53166, server: elenas-adh3.ru-central1.internal/127.0.0.1:2181
2023-11-28 12:39:03,065 [myid:elenas-adh3.ru-central1.internal:2181] - INFO  [main-SendThread(elenas-adh3.ru-central1.internal:2181):ClientCnxn$SendThread@1415] - Session establishment complete on server elenas-adh3.ru-central1.internal/127.0.0.1:2181, sessionid = 0x1000010f7e50000, negotiated timeout = 30000
2023-11-28 12:39:03,855 [myid:] - INFO  [main:Environment@109] - Client environment:zookeeper.version=3.5.10-c4d50586fc8f6fdbdc95b05e9b21b49ec0bd8566, built on 11/03/2022 08:23 GM

Logging levels

ZooKeeper supports the following logging levels (from least to most informative):

  1. FATAL — indicates that an operation can’t continue execution and will terminate.

  2. ERROR — notifies that a program is not working correctly or has stopped.

  3. WARN — warns about potential problems. This doesn’t mean that a program is not working, but raises a concern.

  4. INFO — informs regarding the program lifecycle or state.

  5. DEBUG — prints debugging information about internal states of the program.

  6. TRACE — prints messages tracing the execution flow of a program.

The Log4j loggers also accept logging level values: OFF — for switching off the logging, and ALL — for allowing all types of messages.

Enabling one level of logging will enable this level and all levels above it. For example, if you set the logging level to WARN, then only warnings, errors, and fatal messages would get into the log files, but not INFO, DEBUG, and TRACE.

Logging configuration

You can configure logging settings for ZooKeeper via the log4j.properties configuration file located on each ZooKeeper server host at etc/zookeeper/conf/.

The log4j.properties file contains logger settings, appender settings, and other logging properties. The parameters you set for a logger influence what a program reports to the system. The parameters you set for the appenders influence the information from loggers that ends up in the log files or console.

The configuration file begins with root logger default properties. This logger processes all messages in ZooKeeper since it’s the only logger configured. The default settings are: INFO, CONSOLE, ROLLINGFILE. This means that messages below the INFO level are discarded and the rest of the messages will end up in both console and log files.

The default appenders are:

  • CONSOLE — responsible for the console output, e.g., command output information;

  • ROLLINGFILE — responsible for updating log files instead of appending to a single log.

You can use appenders layout class to change the log messages format. The default pattern layout describes: message level, date, thread information, and caller information in addition to the message itself.

For more detailed information on Log4j architecture, see the Apache Logging Services documentation.

The default ZooKeeper log4j.properties file
# Define some default values that can be overridden by system properties
zookeeper.root.logger="{{ services.zookeeper.config['zookeeper_env_content']['ZOO_LOG4J_PROP'] }}"
zookeeper.console.threshold=INFO
zookeeper.log.dir="{{ services.zookeeper.config['zookeeper_env_content']['ZOO_LOG_DIR'] }}"
zookeeper.log.file=zookeeper.log
zookeeper.log.threshold=INFO
zookeeper.tracelog.dir="{{ services.zookeeper.config['zookeeper_env_content']['ZOO_LOG_DIR'] }}"
zookeeper.tracelog.file=zookeeper.log

#
# ZooKeeper Logging Configuration
#

# Format is "<default threshold> (, <appender>)+

# DEFAULT: console appender only
log4j.rootLogger=${zookeeper.root.logger}

# Example with rolling log file
#log4j.rootLogger=DEBUG, CONSOLE, ROLLINGFILE

# Example with rolling log file and tracing
#log4j.rootLogger=TRACE, CONSOLE, ROLLINGFILE, TRACEFILE

#
# Log INFO level and above messages to the console
#
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=${zookeeper.console.threshold}
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n

#
# Add ROLLINGFILE to rootLogger to get log file output
#    Log DEBUG level and above messages to a log file
log4j.appender.ROLLINGFILE=org.apache.log4j.RollingFileAppender
log4j.appender.ROLLINGFILE.Threshold=${zookeeper.log.threshold}
log4j.appender.ROLLINGFILE.File=${zookeeper.log.dir}/${zookeeper.log.file}

# Max log file size of 10MB
log4j.appender.ROLLINGFILE.MaxFileSize=10MB
# uncomment the next line to limit number of backup files
#log4j.appender.ROLLINGFILE.MaxBackupIndex=10

log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.ROLLINGFILE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n


#
# Add TRACEFILE to rootLogger to get log file output
#    Log DEBUG level and above messages to a log file
log4j.appender.TRACEFILE=org.apache.log4j.FileAppender
log4j.appender.TRACEFILE.Threshold=TRACE
log4j.appender.TRACEFILE.File=${zookeeper.tracelog.dir}/${zookeeper.tracelog.file}

log4j.appender.TRACEFILE.layout=org.apache.log4j.PatternLayout
### Notice we are including log4j's NDC here (%x)
log4j.appender.TRACEFILE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L][%x] - %m%n

To edit log4j.properties on all hosts at once, use ADCM:

  1. On the Clusters page, select the desired cluster.

  2. Go to the Services tab and click at ZooKeeper.

  3. Select Components and click on Zookeeper Server.

  4. Toggle the Show advanced option and find the log4j.properties template field.

  5. Make the necessary changes to the default file.

  6. Confirm changes to ZooKeeper configuration by clicking Save.

  7. In the Actions drop-down menu, select Restart, make sure the Apply configs from ADCM option is set to true, and click Run.

NOTE

The log4j.properties file contains default values for logging parameters and they can be overwritten by ZooKeeper daemons on restart. If it happens, you can set the parameters using environmental variables in the zookeeper-env.sh file.

To change logging properties in the zookeeper-env.sh file via ADCM:

  1. On the Clusters page, select the desired cluster.

  2. Go to the Services tab and click at ZooKeeper.

  3. Toggle the Show advanced option and find the zookeeper-env.sh field.

  4. Select the required parameter for example, ZOO_LOG4J_PROP, and make the necessary changes.

  5. Confirm changes to ZooKeeper configuration by clicking Save.

  6. In the Actions drop-down menu, select Restart, make sure the Apply configs from ADCM option is set to true, and click Run.

Found a mistake? Seleсt text and press Ctrl+Enter to report it