Skip to content

Commit

Permalink
manage logback.xml (#197)
Browse files Browse the repository at this point in the history
* also manager logback.xml (this is required, since zookeeper 3.8 switched from log4j to logback)
* restart service on logback.xml change
  • Loading branch information
mlausch authored Feb 5, 2024
1 parent 15bb845 commit a42780d
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 0 deletions.
7 changes: 7 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@
content => template("${module_name}/conf/log4j.properties.erb"),
}

file { "${zookeeper::cfg_dir}/logback.xml":
owner => $zookeeper::user,
group => $zookeeper::group,
mode => '0644',
content => template("${module_name}/conf/logback.xml.erb"),
}

# Initialize the datastore if required
if $zookeeper::initialize_datastore {
exec { 'initialize_datastore':
Expand Down
1 change: 1 addition & 0 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
File["${zookeeper::cfg_dir}/zoo.cfg"] ~> Service[$zookeeper::service_name]
File["${zookeeper::cfg_dir}/${zookeeper::environment_file}"] ~> Service[$zookeeper::service_name]
File["${zookeeper::cfg_dir}/log4j.properties"] ~> Service[$zookeeper::service_name]
File["${zookeeper::cfg_dir}/logback.xml"] ~> Service[$zookeeper::service_name]

if $zookeeper::manage_service_file and $zookeeper::service_provider == 'systemd' {
Exec['systemctl daemon-reload # for zookeeper'] ~> Service[$zookeeper::service_name]
Expand Down
117 changes: 117 additions & 0 deletions templates/conf/logback.xml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<!--
Copyright 2022 The Apache Software Foundation
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Define some default values that can be overridden by system properties
-->
<configuration>
<!-- Uncomment this if you would like to expose Logback JMX beans -->
<!--jmxConfigurator /-->

<property name="zookeeper.console.threshold" value="<%= scope.lookupvar("zookeeper::console_threshold") %>" />

<property name="zookeeper.log.dir" value="<%= scope.lookupvar("zookeeper::log_dir") %>" />
<property name="zookeeper.log.file" value="zookeeper.log" />
<property name="zookeeper.log.threshold" value="<%= scope.lookupvar("zookeeper::rollingfile_threshold") %>" />
<property name="zookeeper.log.maxfilesize" value="<%= scope.lookupvar("zookeeper::maxfilesize") %>" />
<property name="zookeeper.log.maxbackupindex" value="<%= scope.lookupvar("zookeeper::maxbackupindex") %>" />

<!--
console
Add "console" to root logger if you want to use this
-->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>${zookeeper.console.threshold}</level>
</filter>
</appender>

<!--
Add ROLLINGFILE to root logger to get log file output
-->
<appender name="ROLLINGFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${zookeeper.log.dir}/${zookeeper.log.file}</File>
<encoder>
<pattern>%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>${zookeeper.log.threshold}</level>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<maxIndex>${zookeeper.log.maxbackupindex}</maxIndex>
<FileNamePattern>${zookeeper.log.dir}/${zookeeper.log.file}.%i</FileNamePattern>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>${zookeeper.log.maxfilesize}</MaxFileSize>
</triggeringPolicy>
</appender>

<!--
Add TRACEFILE to root logger to get log file output
Log TRACE level and above messages to a log file
-->
<!--property name="zookeeper.tracelog.dir" value="${zookeeper.log.dir}" />
<property name="zookeeper.tracelog.file" value="zookeeper_trace.log" />
<appender name="TRACEFILE" class="ch.qos.logback.core.FileAppender">
<File>${zookeeper.tracelog.dir}/${zookeeper.tracelog.file}</File>
<encoder>
<pattern>%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>TRACE</level>
</filter>
</appender-->

<% if @audit_enable -%>
<!--
zk audit logging
-->
<property name="zookeeper.auditlog.file" value="zookeeper_audit.log" />
<property name="zookeeper.auditlog.threshold" value="<%= scope.lookupvar("zookeeper::audit_threshold") %>" />
<property name="audit.logger" value="INFO, RFAAUDIT" />

<appender name="RFAAUDIT" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${zookeeper.log.dir}/${zookeeper.auditlog.file}</File>
<encoder>
<pattern>%d{ISO8601} %p %c{2}: %m%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>${zookeeper.auditlog.threshold}</level>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<maxIndex><%= scope.lookupvar("zookeeper::audit_maxbackupindex") %></maxIndex>
<FileNamePattern>${zookeeper.log.dir}/${zookeeper.auditlog.file}.%i</FileNamePattern>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize><%= scope.lookupvar("zookeeper::audit_maxfilesize") %></MaxFileSize>
</triggeringPolicy>
</appender>

<logger name="org.apache.zookeeper.audit.Slf4jAuditLogger" additivity="false" level="${audit.logger}">
<appender-ref ref="RFAAUDIT" />
</logger>
<% end -%>

<root level="INFO">
<appender-ref ref="ROLLINGFILE" />
</root>
</configuration>

0 comments on commit a42780d

Please sign in to comment.