Parametrize the logging pattern to use 54/78054/4
authorMichel Peterson <michel@redhat.com>
Thu, 22 Nov 2018 14:44:57 +0000 (16:44 +0200)
committerMichel Peterson <michel@redhat.com>
Tue, 27 Nov 2018 15:00:23 +0000 (17:00 +0200)
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>
README.markdown
manifests/config.pp
manifests/init.pp
manifests/params.pp
spec/acceptance/class_spec.rb
spec/classes/opendaylight_spec.rb
spec/spec_helper.rb
spec/spec_helper_acceptance.rb

index 184d700c78d342c5e89b3a73dc89bce8c5ffdbe4..070ca6248e0dd89b4f79c64edc78d82c49484009 100644 (file)
@@ -351,6 +351,14 @@ Default: `file`
 
 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.
index c834d5e7c85b0f6aaa2461406bed74fdbc43295d..e024a30dbcef5d1386247c3084a7d3912599b73d 100644 (file)
@@ -298,6 +298,13 @@ class opendaylight::config {
     }
   }
 
+  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
index 94c80bb3abf28e105221e05223f29729ac55a1b9..75c4c1743f1868b13313c5873fbc493ce89a079a 100644 (file)
@@ -44,6 +44,8 @@
 #   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*]
@@ -101,6 +103,7 @@ class opendaylight (
   $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,
index 7f1142b2a643d7bc9d453fe274ad45e3e9da5c61..5a9e86a6d56ea1a5957b1f929ca8456286bdf26b 100644 (file)
@@ -27,6 +27,7 @@ class opendaylight::params {
   $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
index 7117fb71a7ca7df108c60258953e077535f44b63..6a1a0ddd400844bc226da84838ad90eb300c5b4d 100644 (file)
@@ -111,6 +111,14 @@ describe 'opendaylight class' do
                                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')
@@ -118,6 +126,16 @@ describe 'opendaylight class' do
       # 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
index b9a2970f878ff2ad782e233b6a33aa7290c992b4..fb3dfdd97a88b9729f30e54c798eb79c8615557a 100644 (file)
@@ -532,6 +532,25 @@ describe 'opendaylight' 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,
@@ -551,6 +570,27 @@ describe 'opendaylight' do
       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,
index de4a25195efb6a7df225a23cca1e3b0a69a1ca9f..69f23606f60ece770f44b33044fc826dd45c449b 100644 (file)
@@ -120,6 +120,7 @@ def log_settings(options = {})
   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'
@@ -169,6 +170,13 @@ def log_settings(options = {})
       )
     }
   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
index 60d62500052e91bc3657126eaba4b8a05efc6707..33793a798aa2582f93dcbb34f1f428ced6af4527 100644 (file)
@@ -69,6 +69,7 @@ def install_odl(options = {})
   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)
@@ -98,6 +99,7 @@ def install_odl(options = {})
       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},
@@ -250,6 +252,7 @@ def log_settings_validations(options = {})
   # 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')
 
@@ -272,6 +275,9 @@ def log_settings_validations(options = {})
       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