Add option to configure karaf logging 39/66639/6
authorJanki Chhatbar <jchhatba@redhat.com>
Wed, 20 Dec 2017 08:22:44 +0000 (13:52 +0530)
committerJanki Chhatbar <jchhatba@redhat.com>
Thu, 4 Jan 2018 08:16:36 +0000 (13:46 +0530)
Add an option to enable karaf logs to be logged either to file or
console. Default setting is to log to file as karaf.log. There
would be 2 files generated with size 10GB each.

Change-Id: Iba97982e331c4ddd18eafbe65c80acf7f1f5a151
Signed-Off-By: Janki Chhatbar <jchhatba@redhat.com>
Signed-off-by: Daniel Farrell <dfarrell@redhat.com>
CHANGELOG
README.markdown
manifests/config.pp
manifests/init.pp
manifests/params.pp
metadata.json
spec/acceptance/class_spec.rb
spec/classes/opendaylight_spec.rb
spec/spec_helper.rb
spec/spec_helper_acceptance.rb

index 285d7adc1185cf2a2bd46cb3d83515e920e78343..e74875b17c3c11f5b0f2ff4111a5ee4771441888 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -54,3 +54,5 @@
 - Configure websocket address
 2017-01-02 Release 6.2.0
 - Adds SSL/TLS support
+2017-01-03 Release 6.3.0
+- Add param to log karaf logs to either file or console
index 4fbd3336ae287409f11c4350f324eff8b29b2dc5..13603999525cdbf817ca9779d7a0d7d271054c84 100644 (file)
@@ -321,6 +321,16 @@ Default: `2`
 
 Valid options: An integer greater than 0.
 
+##### `log_mechanism`
+
+Logging mechanism for karaf logs. They are logged either to a file or console.
+When `log_mechanism` is `file`, log files are configured as per `log_max_size`
+and `log_max_rollover`.
+
+Default: `file`
+
+Valid options: `file`, `console`.
+
 ##### `enable_ha`
 
 Enable or disable ODL High Availablity.
index 824829e510f1e3c0d4568091bf602ca366abe1ec..7e9e5e0b018acc4071d26e7aef6d24bc2bb6fa28 100644 (file)
@@ -182,6 +182,23 @@ class opendaylight::config {
     }
   }
 
+  # set logging mechanism
+  if $opendaylight::log_mechanism == 'console' {
+    file_line {'rootlogger':
+      ensure => present,
+      path   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
+      line   => 'log4j.rootLogger=INFO, stdout, osgi:*',
+      match  => '^log4j.rootLogger.*$'
+    }
+    file_line { 'logappender':
+      ensure             => present,
+      path               => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
+      line               => 'log4j.appender.stdout.direct=true',
+      after              => 'log4j.appender.stdout=org.apache.log4j.ConsoleAppender',
+      match              => '^log4j.appender.stdout.direct.*$',
+      append_on_no_match => true
+    }
+  }
   # Set maximum ODL log file size
   file_line { 'logmaxsize':
     ensure => present,
index 5eb08bc86e0f16055f10e2b93673de7248f23347..e2b76de059828912ff42b7a3ae1cac27a4706e83 100644 (file)
@@ -59,6 +59,9 @@
 #   Full path to a public CA authority certificate file which signed
 #   OpenDaylight's certificate.  Not needed if ODL certificate is self-signed.
 #   Optional.  Defaults to undef.
+# [*log_mechanism*]
+#   Sets logging mechanism for karaf logs
+#
 # === Deprecated Parameters
 #
 # [*ha_node_index*]
@@ -89,7 +92,8 @@ class opendaylight (
   $tls_trusted_certs     = $::opendaylight::params::tls_trusted_certs,
   $tls_key_file          = $::opendaylight::params::tls_key_file,
   $tls_cert_file         = $::opendaylight::params::tls_cert_file,
-  $tls_ca_cert_file      = $::opendaylight::params::tls_ca_cert_file
+  $tls_ca_cert_file      = $::opendaylight::params::tls_ca_cert_file,
+  $log_mechanism         = $::opendaylight::params::log_mechanism,
 ) inherits ::opendaylight::params {
 
   # Validate OS family
index 9623e891929cd2018e182a501d1b4a2e54be6217..6d2f43f2df4c6ba2bb39825139acacbf34ba5d08 100644 (file)
@@ -33,4 +33,5 @@ class opendaylight::params {
   $tls_cert_file = undef
   $tls_ca_cert_file = undef
   $tls_trusted_certs = []
+  $log_mechanism = 'file'
 }
index a17a66ff0eb17182152dca37158da846aa7cc240..607a1496a5ce608389d2e1bc501c54a449fb0e05 100644 (file)
@@ -1,6 +1,6 @@
 {
     "name": "opendaylight-opendaylight",
-    "version": "6.2.0",
+    "version": "6.3.0",
     "author": "Daniel Farrell",
     "summary": "Puppet module that installs and configures the OpenDaylight SDN controller",
     "license": "BSD-2-Clause",
index e2d8bfc596ca8b2c299e88fc95c5262d68dfc911..29da2181b3c0cd938fc9c0f8e98e7c293fab5675 100644 (file)
@@ -74,40 +74,48 @@ describe 'opendaylight class' do
     end
   end
 
-  describe 'log file size and rollover' do
-    context 'using default size and rollover' do
+  describe 'logging mechanism' do
+    context 'log to file using default size and rollover' do
       # Call specialized helper fn to install OpenDaylight
       install_odl
 
-      # Call specialized helper fn for log file settings validations
-      log_file_settings_validations
+      # Call specialized helper fn for log settings validations
+      log_settings_validations
     end
 
-    context 'customising size' do
+    context 'log to file customising size' do
       # Call specialized helper fn to install OpenDaylight
       install_odl(log_max_size: '1GB')
 
-      # Call specialized helper fn for log file settings validations
-      log_file_settings_validations(log_max_size: '1GB')
+      # Call specialized helper fn for log settings validations
+      log_settings_validations(log_max_size: '1GB')
     end
 
-    context 'customising rollover' do
+    context 'log to file customising rollover' do
       # Call specialized helper fn to install OpenDaylight
       install_odl(log_max_rollover: 3)
 
-      # Call specialized helper fn for log file settings validations
-      log_file_settings_validations(log_max_rollover: 3)
+      # Call specialized helper fn for log settings validations
+      log_settings_validations(log_max_rollover: 3)
     end
 
-    context 'customising size and rollover' do
+    context 'log to file customising size and rollover' do
       # Call specialized helper fn to install OpenDaylight
       install_odl(log_max_size: '1GB',
                   log_max_rollover: 3)
 
-      # Call specialized helper fn for log file settings validations
-      log_file_settings_validations(log_max_size: '1GB',
+      # Call specialized helper fn for log settings validations
+      log_settings_validations(log_max_size: '1GB',
                                     log_max_rollover: 3)
     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
   end
 
   describe 'testing REST port config file' do
index 1ce50988b41f18b3b79d3c99bd0644727531aa54..abc824f37ed10367cf8d06ee67f58476d3bd3070 100644 (file)
@@ -50,7 +50,7 @@ describe 'opendaylight' do
             # Run tests that specialize in checking log file settings
             # NB: Only testing defaults here, specialized log file settings tests elsewhere
             # Note that this function is defined in spec_helper
-            log_file_settings
+            log_settings
           end
         end
 
@@ -114,7 +114,7 @@ describe 'opendaylight' do
             # Run tests that specialize in checking log file settings
             # NB: Only testing defaults here, specialized log file settings tests elsewhere
             # Note that this function is defined in spec_helper
-            log_file_settings
+            log_settings
           end
         end
 
@@ -188,7 +188,7 @@ describe 'opendaylight' do
             # Run tests that specialize in checking log file settings
             # NB: Only testing defaults here, specialized log file settings tests elsewhere
             # Note that this function is defined in spec_helper
-            log_file_settings
+            log_settings
           end
         end
 
@@ -445,15 +445,16 @@ describe 'opendaylight' do
     end
   end
 
-  # All custom log file size and rollover tests
-  describe 'log file size and rollover' do
+  describe 'log mechanism settings' do
     # Non-OS-type tests assume CentOS 7
     #   See issue #43 for reasoning:
     #   https://github.com/dfarrell07/puppet-opendaylight/issues/43#issue-57343159
     osfamily = 'RedHat'
     operatingsystem = 'CentOS'
     operatingsystemmajrelease = '7'
-    context 'using default size and rollover' do
+
+    # All custom log file size and rollover tests
+    context 'log to file using default size and rollover' do
       let(:facts) {{
         :osfamily => osfamily,
         :operatingsystem => operatingsystem,
@@ -466,11 +467,11 @@ describe 'opendaylight' do
       # Note that this function is defined in spec_helper
       generic_tests
 
-      # Run test specific to log file settings
-      log_file_settings
+      # Run test specific to log settings
+      log_settings
     end
 
-    context 'customizing size' do
+    context 'log to file customizing size' do
       let(:facts) {{
         :osfamily => osfamily,
         :operatingsystem => operatingsystem,
@@ -485,11 +486,11 @@ describe 'opendaylight' do
       # Note that this function is defined in spec_helper
       generic_tests
 
-      # Run test specific to log file settings
-      log_file_settings(log_max_size: '1GB')
+      # Run test specific to log settings
+      log_settings(log_max_size: '1GB')
     end
 
-    context 'customizing rollover' do
+    context 'log to file customizing rollover' do
       let(:facts) {{
         :osfamily => osfamily,
         :operatingsystem => operatingsystem,
@@ -504,11 +505,11 @@ describe 'opendaylight' do
       # Note that this function is defined in spec_helper
       generic_tests
 
-      # Run test specific to log file settings
-      log_file_settings(log_max_rollover: 3)
+      # Run test specific to log settings
+      log_settings(log_max_rollover: 3)
     end
 
-    context 'customizing size and rollover' do
+    context 'log to file customizing size and rollover' do
       let(:facts) {{
         :osfamily => osfamily,
         :operatingsystem => operatingsystem,
@@ -524,10 +525,29 @@ describe 'opendaylight' do
       # Note that this function is defined in spec_helper
       generic_tests
 
-      # Run test specific to log file settings
-      log_file_settings(log_max_size: '1GB',
+      # Run test specific to log settings
+      log_settings(log_max_size: '1GB',
                         log_max_rollover: 3)
     end
+
+    context 'log to console' do
+      let(:facts) {{
+        :osfamily => osfamily,
+        :operatingsystem => operatingsystem,
+        :operatingsystemmajrelease => operatingsystemmajrelease,
+      }}
+
+      let(:params) {{
+        :log_mechanism => 'console',
+      }}
+
+      # 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')
+    end
   end
 
   # All OVSDB HA enable/disable tests
index 18717c236c1b684591370d1217ceed67ddb08bbe..d0a2acb5322219364d78a6fabf0f75e7c5f8143a 100644 (file)
@@ -62,25 +62,45 @@ def generic_tests()
 end
 
 # Shared tests that specialize in testing log file size and rollover
-def log_file_settings(options = {})
+def log_settings(options = {})
   # Extraxt params. The dafault value should be same as in opendaylight::params
   log_max_size = options.fetch(:log_max_size, '10GB')
   log_max_rollover = options.fetch(:log_max_rollover, 2)
+  log_mechanism = options.fetch(:log_mechanism, 'file')
 
-  it {
-    should contain_file_line('logmaxsize').with(
-      'path'   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
-      'line'   => "log4j.appender.out.maxFileSize=#{log_max_size}",
-      'match'  => '^log4j.appender.out.maxFileSize.*$',
-    )
-  }
-  it {
-    should contain_file_line('logmaxrollover').with(
-      'path'   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
-      'line'   => "log4j.appender.out.maxBackupIndex=#{log_max_rollover}",
-      'match'  => '^log4j.appender.out.maxBackupIndex.*$',
-    )
-  }
+  if log_mechanism == 'console'
+    it {
+      should contain_file_line('rootlogger').with(
+        'path'  => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
+        'line'  => 'log4j.rootLogger=INFO, stdout, osgi:*',
+        'match' => '^log4j.rootLogger.*$',
+      )
+    }
+    it {
+      should contain_file_line('logappender').with(
+        'path'               => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
+        'line'               => 'log4j.appender.stdout.direct=true',
+        'after'              => 'log4j.appender.stdout=org.apache.log4j.ConsoleAppender',
+        'match'              => '^log4j.appender.stdout.direct.*$',
+        'append_on_no_match' => true
+      )
+    }
+  else
+    it {
+      should contain_file_line('logmaxsize').with(
+        'path'   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
+        'line'   => "log4j.appender.out.maxFileSize=#{log_max_size}",
+        'match'  => '^log4j.appender.out.maxFileSize.*$',
+      )
+    }
+    it {
+      should contain_file_line('logmaxrollover').with(
+        'path'   => '/opt/opendaylight/etc/org.ops4j.pax.logging.cfg',
+        'line'   => "log4j.appender.out.maxBackupIndex=#{log_max_rollover}",
+        'match'  => '^log4j.appender.out.maxBackupIndex.*$',
+      )
+    }
+  end
 end
 
 # Shared tests that specialize in testing Karaf feature installs
index d4607fecc89ed26e5e4c44e426e251424d6acbdc..0f3d80738b7d86bba7ae3e642a34d6f4da7d79fb 100644 (file)
@@ -67,6 +67,7 @@ def install_odl(options = {})
   snat_mechanism = options.fetch(:snat_mechanism, 'controller')
   enable_tls = options.fetch(:enable_tls, false)
   tls_keystore_password = options.fetch(:tls_keystore_password, 'dummypass')
+  log_mechanism = options.fetch(:log_mechanism, 'file')
 
   # Build script for consumption by Puppet apply
   it 'should work idempotently with no errors' do
@@ -90,6 +91,7 @@ def install_odl(options = {})
       snat_mechanism => #{snat_mechanism},
       enable_tls => #{enable_tls},
       tls_keystore_password => #{tls_keystore_password},
+      log_mechanism => #{log_mechanism},
     }
     EOS
 
@@ -209,17 +211,28 @@ def generic_validations()
 end
 
 # Shared function for validations related to log file settings
-def log_file_settings_validations(options = {})
+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_mechanism = options.fetch(:log_mechanism, 'file')
 
-  describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
-    it { should be_file }
-    it { should be_owned_by 'odl' }
-    it { should be_grouped_into 'odl' }
-    its(:content) { should match /^log4j.appender.out.maxFileSize=#{log_max_size}/ }
-    its(:content) { should match /^log4j.appender.out.maxBackupIndex=#{log_max_rollover}/ }
+  if log_mechanism == 'console'
+    describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
+      it { should be_file }
+      it { should be_owned_by 'odl' }
+      it { should be_grouped_into 'odl' }
+      its(:content) { should match /log4j.rootLogger=INFO, stdout, osgi:*/ }
+      its(:content) { should match /log4j.appender.stdout.direct=true/ }
+    end
+  else
+    describe file('/opt/opendaylight/etc/org.ops4j.pax.logging.cfg') do
+      it { should be_file }
+      it { should be_owned_by 'odl' }
+      it { should be_grouped_into 'odl' }
+      its(:content) { should match /^log4j.appender.out.maxFileSize=#{log_max_size}/ }
+      its(:content) { should match /^log4j.appender.out.maxBackupIndex=#{log_max_rollover}/ }
+    end
   end
 end