Skip to content

Commit

Permalink
ensure compatibility with version 2.29.0 (log4j2)
Browse files Browse the repository at this point in the history
  • Loading branch information
fraenki committed Jul 12, 2023
1 parent 7a71d53 commit d2848f9
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 12 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added
* Ensure compatibility with version 2.29.0
* Add new parameter `$log4j_template`
* Add new instance parameter `$log4j_level`
* Add new default logging config for log4j2

### Changed
* Setup `log4j2.properties` on version 2.27.0 and later
* Setup `logging properties` only on versions before 2.27.0

## [v1.5.0] - 2022-10-24

### Fixed
Expand Down
9 changes: 9 additions & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ activemq::instance_defaults:
console: 'ERROR'
jetty: 'WARN'
root: 'INFO'
log4j_level:
analyzer: 'INFO'
artemis: 'INFO'
audit: 'OFF'
curator: 'WARN'
jetty: 'WARN'
root: 'INFO'
zookeeper: 'ERROR'
max_disk_usage: 90
max_hops: 0
message_load_balancing: 'on_demand'
Expand Down Expand Up @@ -253,6 +261,7 @@ activemq::java_args:
'Djolokia.policyLocation=${ARTEMIS_INSTANCE_ETC_URI}jolokia-access.xml': ''
activemq::java_xms: '512M'
activemq::java_xmx: '2G'
activemq::log4j_template: 'activemq/log4j2.properties.epp'
activemq::logging_template: 'activemq/logging.properties.epp'
activemq::login_template: 'activemq/login.config.epp'
activemq::manage_account: true
Expand Down
6 changes: 5 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@
# @param java_xmx
# The maximum Java heap size.
#
# @param log4j_template
# The template used to generate log4j2.properties (on version 2.27.0 and later).
#
# @param logging_template
# The template used to generate logging.properties.
# The template used to generate logging.properties (on versions before 2.27.0).
#
# @param login_template
# The template used to generate login.config.
Expand Down Expand Up @@ -174,6 +177,7 @@
Hash $java_args,
String $java_xms,
String $java_xmx,
String $log4j_template,
String $logging_template,
String $login_template,
Boolean $manage_account,
Expand Down
42 changes: 31 additions & 11 deletions manifests/instance.pp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@
# The type of journal to use.
#
# @param log_level
# The log levels to use for the various configured loggers.
# The log levels to use for the various configured loggers (on versions before 2.27.0).
#
# @param log4j_level
# The log levels to use for the various configured loggers (on version 2.27.0 and later).
#
# @param max_disk_usage
# The max percentage of data to use from disks. The broker will block while the disk is full. Disable by setting -1.
Expand Down Expand Up @@ -139,6 +142,7 @@
Integer $journal_max_io,
Enum['asyncio','mapped','nio'] $journal_type,
Hash $log_level,
Hash $log4j_level,
Integer $max_disk_usage,
Integer $max_hops,
Enum['off','strict','on_demand'] $message_load_balancing,
Expand Down Expand Up @@ -172,6 +176,7 @@
$bootstrap_xml = "${instance_dir}/etc/bootstrap.xml"
$broker_xml = "${instance_dir}/etc/broker.xml"
$management_xml = "${instance_dir}/etc/management.xml"
$log4j_properties = "${instance_dir}/etc/log4j2.properties"
$logging_properties = "${instance_dir}/etc/logging.properties"
$login_config = "${instance_dir}/etc/login.config"
$instance_service = "${activemq::service_name}@${name}"
Expand Down Expand Up @@ -398,16 +403,31 @@
],
}

# Create logging.properties configuration file.
file { "instance ${name} logging.properties":
path => $logging_properties,
mode => '0644',
content => epp($activemq::logging_template,{
'log_level' => $log_level,
}),
require => [
Exec["create instance ${name}"]
],
# Create appropiate logging configuration.
if (versioncmp($activemq::version, '2.27.0') >= 0) {
# Recent versions use the log4j2.properties configuration file.
file { "instance ${name} log4j2.properties":
path => $log4j_properties,
mode => '0644',
content => epp($activemq::logging_template,{
'log4j_level' => $log4j_level,
}),
require => [
Exec["create instance ${name}"]
],
}
} else {
# Older versions use the logging.properties configuration file.
file { "instance ${name} logging.properties":
path => $logging_properties,
mode => '0644',
content => epp($activemq::logging_template,{
'log_level' => $log_level,
}),
require => [
Exec["create instance ${name}"]
],
}
}

# Create login.config file.
Expand Down
91 changes: 91 additions & 0 deletions templates/log4j2.properties.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# 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.

# Log4J 2 configuration

# Monitor config file every X seconds for updates
monitorInterval = 5

rootLogger = <%= $log4j_level['root'] %>, console, log_file

logger.activemq.name=org.apache.activemq
logger.activemq.level=<%= $log4j_level['artemis'] %>

logger.artemis_server.name=org.apache.activemq.artemis.core.server
logger.artemis_server.level=<%= $log4j_level['artemis'] %>

logger.artemis_journal.name=org.apache.activemq.artemis.journal
logger.artemis_journal.level=<%= $log4j_level['artemis'] %>

logger.artemis_utils.name=org.apache.activemq.artemis.utils
logger.artemis_utils.level=<%= $log4j_level['artemis'] %>

# CriticalAnalyzer: If you have issues with the CriticalAnalyzer, setting this to TRACE would give
# you extra troubleshooting info, but do not use TRACE regularly as it would incur extra CPU usage.
logger.critical_analyzer.name=org.apache.activemq.artemis.utils.critical
logger.critical_analyzer.level=<%= $log4j_level['analyzer'] %>

# Audit loggers: to enable change levels from OFF to INFO
logger.audit_base = <%= $log4j_level['audit'] %>, audit_log_file
logger.audit_base.name = org.apache.activemq.audit.base
logger.audit_base.additivity = false

logger.audit_resource = <%= $log4j_level['audit'] %>, audit_log_file
logger.audit_resource.name = org.apache.activemq.audit.resource
logger.audit_resource.additivity = false

logger.audit_message = <%= $log4j_level['audit'] %>, audit_log_file
logger.audit_message.name = org.apache.activemq.audit.message
logger.audit_message.additivity = false

# Jetty logger levels
logger.jetty.name=org.eclipse.jetty
logger.jetty.level=<%= $log4j_level['jetty'] %>

# Quorum related logger levels
logger.curator.name=org.apache.curator
logger.curator.level=<%= $log4j_level['curator'] %>
logger.zookeeper.name=org.apache.zookeeper
logger.zookeeper.level=<%= $log4j_level['zookeeper'] %>

# Console appender
appender.console.type=Console
appender.console.name=console
appender.console.layout.type=PatternLayout
appender.console.layout.pattern=%d %-5level [%logger] %msg%n

# Log file appender
appender.log_file.type = RollingFile
appender.log_file.name = log_file
appender.log_file.fileName = ${sys:artemis.instance}/log/artemis.log
appender.log_file.filePattern = ${sys:artemis.instance}/log/artemis.log.%d{yyyy-MM-dd}
appender.log_file.layout.type = PatternLayout
appender.log_file.layout.pattern = %d %-5level [%logger] %msg%n
appender.log_file.policies.type = Policies
appender.log_file.policies.cron.type = CronTriggeringPolicy
appender.log_file.policies.cron.schedule = 0 0 0 * * ?
appender.log_file.policies.cron.evaluateOnStartup = true

# Audit log file appender
appender.audit_log_file.type = RollingFile
appender.audit_log_file.name = audit_log_file
appender.audit_log_file.fileName = ${sys:artemis.instance}/log/audit.log
appender.audit_log_file.filePattern = ${sys:artemis.instance}/log/audit.log.%d{yyyy-MM-dd}
appender.audit_log_file.layout.type = PatternLayout
appender.audit_log_file.layout.pattern = %d [AUDIT](%t) %msg%n
appender.audit_log_file.policies.type = Policies
appender.audit_log_file.policies.cron.type = CronTriggeringPolicy
appender.audit_log_file.policies.cron.schedule = 0 0 0 * * ?
appender.audit_log_file.policies.cron.evaluateOnStartup = true

0 comments on commit d2848f9

Please sign in to comment.