Skip to content

Commit

Permalink
Fixes #35699 - Introduce a parameter to configure logging
Browse files Browse the repository at this point in the history
This also drops the Hibernate logger since it should have been resolved
by now.
  • Loading branch information
ekohl committed Nov 4, 2022
1 parent 3944348 commit 98f2a18
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 6 deletions.
11 changes: 11 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
# @param log_dir
# Directory for Candlepin logs
#
# @param loggers
# Set the log levels for loggers
#
# @param env_filtering_enabled
# If subscription filtering is done on a per environment basis
#
Expand Down Expand Up @@ -167,6 +170,13 @@
# Disable FIPS within the Java environment for Tomcat explicitly.
# When set to false, no flag is added. Then on FIPS enabled systems, a Candlepin build that supports FIPS is required.
#
# @example Set debug logging
# class { 'candlepin':
# loggers => {
# 'org.candlepin' => 'DEBUG',
# },
# }
#
class candlepin (
Boolean $manage_db = true,
Boolean $init_db = true,
Expand All @@ -181,6 +191,7 @@
Variant[Sensitive[String], String] $db_password = $candlepin::params::db_password,
Variant[Array[String], String] $user_groups = [],
Stdlib::Absolutepath $log_dir = '/var/log/candlepin',
Hash[String[1], Candlepin::LogLevel] $loggers = {},
String $oauth_key = 'candlepin',
String $oauth_secret = 'candlepin',
Boolean $env_filtering_enabled = true,
Expand Down
38 changes: 37 additions & 1 deletion spec/classes/candlepin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
'candlepin.auth.oauth.consumer.candlepin.secret=candlepin',
'candlepin.ca_key=/etc/candlepin/certs/candlepin-ca.key',
'candlepin.ca_cert=/etc/candlepin/certs/candlepin-ca.crt',
'log4j.logger.org.hibernate.internal.SessionImpl=ERROR',
'candlepin.async.jobs.ExpiredPoolsCleanupJob.schedule=0 0 0 * * ?',
'candlepin.audit.hornetq.config_path=/etc/candlepin/broker.xml',
])
Expand Down Expand Up @@ -242,6 +241,43 @@
end
end

describe 'with additional logging' do
describe 'with org.candlepin set to DEBUG' do
let(:params) do
{
loggers: {
'org.candlepin' => 'DEBUG',
},
}
end

it do
is_expected.to contain_concat__fragment('General Config')
.with_content(%r{^log4j\.logger\.org\.candlepin=DEBUG$})
end
end

describe 'with various loggers set' do
let(:params) do
{
loggers: {
'org.candlepin' => 'DEBUG',
'org.candlepin.resource.ConsumerResource' => 'WARN',
'org.candlepin.resource.HypervisorResource' => 'WARN',
'org.hibernate.internal.SessionImpl' => 'FATAL',
},
}
end

it do
is_expected.to contain_concat__fragment('General Config')
.with_content(%r{^log4j\.logger\.org\.candlepin=DEBUG$})
.with_content(%r{^log4j\.logger\.org\.candlepin\.resource\.ConsumerResource=WARN$})
.with_content(%r{^log4j\.logger\.org\.candlepin\.resource\.HypervisorResource=WARN$})
end
end
end

describe 'with custom adapter module' do
let :params do
{adapter_module: 'my.custom.adapter_module'}
Expand Down
10 changes: 5 additions & 5 deletions templates/candlepin.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ candlepin.ca_key_password=<%= scope['candlepin::ca_key_password_unsensitive'] %>
<%- end -%>

candlepin.async.jobs.ExpiredPoolsCleanupJob.schedule=<%= scope['candlepin::expired_pools_schedule'] %>
<% if scope['candlepin::loggers'].any? -%>

# Required for https://hibernate.atlassian.net/browse/HHH-12927
log4j.logger.org.hibernate.internal.SessionImpl=ERROR

# uncomment to enable debug logging in candlepin.log:
#log4j.logger.org.candlepin=DEBUG
<% scope['candlepin::loggers'].each do |logger, log_level| -%>
log4j.logger.<%= logger %>=<%= log_level %>
<% end -%>
<% end -%>
2 changes: 2 additions & 0 deletions types/loglevel.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# @summary A log4j log level
type Candlepin::LogLevel = Enum['ALL', 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL', 'OFF', 'TRACE']

0 comments on commit 98f2a18

Please sign in to comment.