Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #35699 - Introduce a parameter to configure logging #226

Merged
merged 1 commit into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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? -%>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am surprised this any? is needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly for a visual separation with an empty line between the groups.


# 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']