diff --git a/defaults/main.yml b/defaults/main.yml index edb6b09..5a18ec1 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -23,6 +23,10 @@ log_dir: /var/log/zookeeper zookeeper_dir: /opt/zookeeper-{{zookeeper_version}} zookeeper_tarball_dir: /opt/src +# Rolling file appender setttings +zookeeper_rolling_log_file_max_size: 10MB +zookeeper_max_rolling_log_file_count: 10 + # List of dict (i.e. {zookeeper_hosts:[{host:,id:},{host:,id:},...]}) zookeeper_hosts: - host: "{{inventory_hostname}}" # the machine running diff --git a/tasks/common-config.yml b/tasks/common-config.yml index f48ac38..ca8fdf4 100644 --- a/tasks/common-config.yml +++ b/tasks/common-config.yml @@ -6,6 +6,12 @@ - Restart zookeeper when: zookeeper_env is defined and zookeeper_env|length > 0 +- name: Update the log4j config with saner production values + template: src=log4j.properties.j2 dest={{ zookeeper_dir }}/conf/log4j.properties + tags: deploy + notify: + - Restart zookeeper + - name: Start zookeeper service service: name=zookeeper state=started enabled=yes tags: deploy diff --git a/templates/log4j.properties.j2 b/templates/log4j.properties.j2 new file mode 100644 index 0000000..9a995f4 --- /dev/null +++ b/templates/log4j.properties.j2 @@ -0,0 +1,58 @@ +# Define some default values that can be overridden by system properties +zookeeper.root.logger=INFO, CONSOLE, ROLLINGFILE +zookeeper.console.threshold=INFO +zookeeper.log.dir=. +zookeeper.log.file=zookeeper.log +zookeeper.log.threshold=DEBUG +zookeeper.tracelog.dir=. +zookeeper.tracelog.file=zookeeper_trace.log + +# +# ZooKeeper Logging Configuration +# + +# Format is " (, )+ + +# 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={{ zookeeper_rolling_log_file_max_size }} +# uncomment the next line to limit number of backup files +log4j.appender.ROLLINGFILE.MaxBackupIndex={{ zookeeper_max_rolling_log_file_count }} + +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