From 0c2c4ee75f0b2ed69af07609057dffdea323fcdd Mon Sep 17 00:00:00 2001 From: Elad Amit Date: Thu, 29 Sep 2016 11:25:55 +0300 Subject: [PATCH 1/3] added saner production rolling log file options --- defaults/main.yml | 4 +++ tasks/common-config.yml | 6 ++++ templates/log4j.properties.j2 | 58 +++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 templates/log4j.properties.j2 diff --git a/defaults/main.yml b/defaults/main.yml index edb6b09..902b81c 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 +rolling_log_file_max_size: 10MB +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..83f0e24 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..d5e5828 --- /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={{ rolling_log_file_max_size }} +# uncomment the next line to limit number of backup files +log4j.appender.ROLLINGFILE.MaxBackupIndex={{ 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 From 28f43d6f5a424f90905d878b81ca027aeafdbfe5 Mon Sep 17 00:00:00 2001 From: Elad Amit Date: Sun, 9 Oct 2016 17:12:14 +0300 Subject: [PATCH 2/3] prefixed new vars with zookeeper uppercased first word of new task --- defaults/main.yml | 4 ++-- tasks/common-config.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 902b81c..5a18ec1 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -24,8 +24,8 @@ zookeeper_dir: /opt/zookeeper-{{zookeeper_version}} zookeeper_tarball_dir: /opt/src # Rolling file appender setttings -rolling_log_file_max_size: 10MB -max_rolling_log_file_count: 10 +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: diff --git a/tasks/common-config.yml b/tasks/common-config.yml index 83f0e24..ca8fdf4 100644 --- a/tasks/common-config.yml +++ b/tasks/common-config.yml @@ -6,7 +6,7 @@ - Restart zookeeper when: zookeeper_env is defined and zookeeper_env|length > 0 -- name: update the log4j config with saner production values +- name: Update the log4j config with saner production values template: src=log4j.properties.j2 dest={{ zookeeper_dir }}/conf/log4j.properties tags: deploy notify: From 26a07b067d1606ceda87f2e6e6fed57ba429cb05 Mon Sep 17 00:00:00 2001 From: Elad Amit Date: Sun, 9 Oct 2016 17:16:32 +0300 Subject: [PATCH 3/3] prefixed new vars with zookeeper --- templates/log4j.properties.j2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/log4j.properties.j2 b/templates/log4j.properties.j2 index d5e5828..9a995f4 100644 --- a/templates/log4j.properties.j2 +++ b/templates/log4j.properties.j2 @@ -38,9 +38,9 @@ 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={{ rolling_log_file_max_size }} +log4j.appender.ROLLINGFILE.MaxFileSize={{ zookeeper_rolling_log_file_max_size }} # uncomment the next line to limit number of backup files -log4j.appender.ROLLINGFILE.MaxBackupIndex={{ max_rolling_log_file_count }} +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