Currently the packaging of opendaylight is being done with the current
opendaylight default. This default does not always suits the needs of
every deployment and it is good to have this configurable.
This patch adds a `log_pattern` configuration that allows to specify the
logging pattern that will be used. At the same time, it also defines a
default that is non dependant on PaxOsgi on being enabled [1]. The new
default removes the '%X{bundle.id} - %X{bundle.name} -
%X{bundle.version}' bits that are PaxOsgin related, and to compensate
for that information removed it adds more context to the class name and
expands the clipping of the column to 60 characters.
[1] https://bugzilla.redhat.com/show_bug.cgi?id=
1650576
Change-Id: I923cd372c71ba5c04a27f6d4478ca7c511c14d2d
Signed-off-by: Michel Peterson <michel@redhat.com>
Valid options: `file`, `console`.
+##### `log_pattern`
+
+String that controls the log pattern used for logging.
+
+Default: `%d{ISO8601} | %-5p | %-16t | %-60c{6} | %m%n`
+
+Valid options: A valid string that is a valid log4j2 pattern.
+
##### `enable_ha`
Enable or disable ODL High Availablity.
}
}
+ file_line { 'logpattern':
+ ensure => present,
+ path => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
+ line => "log4j2.pattern = ${::opendaylight::log_pattern}",
+ match => '^log4j2.pattern.*$'
+ }
+
# Configure ODL HA if enabled
if $::opendaylight::enable_ha {
# Configure ODL OSVDB Clustering
# Defaults to 'min'.
# Other possible values: 'max', 'nomax'
# see https://logging.apache.org/log4j/2.x/manual/appenders.html#FileAppender for more info
+# [*log_pattern*]
+# Pattern to use for logging
# [*snat_mechanism*]
# Sets the mechanism to be used for SNAT (conntrack, controller)
# [*enable_tls*]
$log_max_size = $::opendaylight::params::log_max_size,
$log_max_rollover = $::opendaylight::params::log_max_rollover,
$log_rollover_fileindex = $::opendaylight::params::log_rollover_fileindex,
+ $log_pattern = $::opendaylight::params::log_pattern,
$snat_mechanism = $::opendaylight::params::snat_mechanism,
$enable_tls = $::opendaylight::params::enable_tls,
$tls_keystore_password = $::opendaylight::params::tls_keystore_password,
$log_max_size = '10GB'
$log_max_rollover = 2
$log_rollover_fileindex = 'min'
+ $log_pattern = '%d{ISO8601} | %-5p | %-16t | %-60c{6} | %m%n'
$snat_mechanism = 'controller'
$enable_tls = false
$tls_keystore_password = undef
log_rollover_fileIndex: 'min')
end
+ context 'log to file customizing pattern' do
+ # Call specialized helper fn to install OpenDaylight
+ install_odl(log_pattern: '%d{ISO8601} | %-5p | %-16t | %m%n')
+
+ # Call specialized helper fn for log settings validations
+ log_settings_validations(log_pattern: '%d{ISO8601} | %-5p | %-16t | %m%n')
+ end
+
context 'log to console' do
# Call specialized helper fn to install OpenDaylight
install_odl(log_mechanism: 'console')
# Call specialized helper fn for log settings validations
log_settings_validations(log_mechanism: 'console')
end
+
+ context 'log to console customizing pattern' do
+ # Call specialized helper fn to install OpenDaylight
+ install_odl(log_mechanism: 'console',
+ log_pattern: '%d{ISO8601} | %-5p | %-16t | %m%n')
+
+ # Call specialized helper fn for log settings validations
+ log_settings_validations(log_mechanism: 'console',
+ log_pattern: '%d{ISO8601} | %-5p | %-16t | %m%n')
+ end
end
describe 'testing REST port config file' do
log_rollover_fileindex: 'min')
end
+ context 'log to file customizing pattern' do
+ let(:facts) {{
+ :osfamily => osfamily,
+ :operatingsystem => operatingsystem,
+ :operatingsystemmajrelease => operatingsystemmajrelease,
+ }}
+
+ let(:params) {{
+ :log_pattern => '%d{ISO8601} | %-5p | %-16t | %m%n',
+ }}
+
+ # Run shared tests applicable to all supported OSs
+ # Note that this function is defined in spec_helper
+ generic_tests
+
+ # Run test specific to log settings
+ log_settings(log_pattern: '%d{ISO8601} | %-5p | %-16t | %m%n')
+ end
+
context 'log to console' do
let(:facts) {{
:osfamily => osfamily,
log_settings(log_mechanism: 'console')
end
+ context 'log to console customizing pattern' do
+ let(:facts) {{
+ :osfamily => osfamily,
+ :operatingsystem => operatingsystem,
+ :operatingsystemmajrelease => operatingsystemmajrelease,
+ }}
+
+ let(:params) {{
+ :log_mechanism => 'console',
+ :log_pattern => '%d{ISO8601} | %-5p | %-16t | %m%n',
+ }}
+
+ # Run shared tests applicable to all supported OSs
+ # Note that this function is defined in spec_helper
+ generic_tests
+
+ # Run test specific to log settings
+ log_settings(log_mechanism: 'console',
+ log_pattern: '%d{ISO8601} | %-5p | %-16t | %m%n')
+ end
+
context 'setting inactivity probe' do
let(:facts) {{
:osfamily => osfamily,
log_max_size = options.fetch(:log_max_size, '10GB')
log_max_rollover = options.fetch(:log_max_rollover, 2)
log_rollover_fileindex = options.fetch(:log_rollover_fileindex, 'min')
+ log_pattern = options.fetch(:log_pattern, '%d{ISO8601} | %-5p | %-16t | %-60c{6} | %m%n')
log_mechanism = options.fetch(:log_mechanism, 'file')
if log_mechanism == 'console'
)
}
end
+ it {
+ should contain_file_line('logpattern').with(
+ 'path' => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
+ 'line' => "log4j2.pattern = #{log_pattern}",
+ 'match' => '^log4j2.pattern.*$',
+ )
+ }
end
# Shared tests that specialize in testing Karaf feature installs
password = options.fetch(:password, 'admin')
log_max_size = options.fetch(:log_max_size, '10GB')
log_max_rollover = options.fetch(:log_max_rollover, 2)
+ log_pattern = options.fetch(:log_pattern, '%d{ISO8601} | %-5p | %-16t | %-60c{6} | %m%n')
log_rollover_fileindex = options.fetch(:log_rollover_fileindex, 'min')
snat_mechanism = options.fetch(:snat_mechanism, 'controller')
enable_tls = options.fetch(:enable_tls, false)
password => #{password},
log_max_size => '#{log_max_size}',
log_max_rollover => #{log_max_rollover},
+ log_pattern => '#{log_pattern}',
log_rollover_fileindex => #{log_rollover_fileindex},
snat_mechanism => #{snat_mechanism},
enable_tls => #{enable_tls},
# Should contain log level config file with correct file size and rollover values
log_max_size = options.fetch(:log_max_size, '10GB')
log_max_rollover = options.fetch(:log_max_rollover, 2)
+ log_pattern = options.fetch(:log_pattern, '%d{ISO8601} | %-5p | %-16t | %-60c{6} | %m%n')
log_rollover_fileindex = options.fetch(:log_rollover_fileindex, 'min')
log_mechanism = options.fetch(:log_mechanism, 'file')
its(:content) { should match /^log4j2.appender.rolling.strategy.fileIndex = #{log_rollover_fileindex}/ }
end
end
+ describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
+ its(:content) { should match /^log4j2.pattern = #{log_pattern}/ }
+ end
end
# Shared function for validations related to the Karaf config file