Add ODL log configuration 28/73628/14
authorTaseer Ahmed <taseer94@gmail.com>
Sun, 1 Jul 2018 18:41:37 +0000 (23:41 +0500)
committerTaseer Ahmed <taseer94@gmail.com>
Wed, 22 Aug 2018 15:54:26 +0000 (20:54 +0500)
JIRA: INTPAK-40

Parallels the Puppet logic. Initially log levels is an empty
dictionary of the 'logger name' and 'log level'. The user can
set the logger name and log level by their choice.
Ansible implements a similar approach. By default, log_levels
is empty, but can be over written in the vars.

This patch also sets the logging mechanism, either file or console.
Default mechanism is set to console. In case of file, the log
rotation strategy is also configured.

Change-Id: Ifa39927bc77b47490d3e1b56f23aa359316bc3bf
Signed-off-by: Taseer Ahmed <taseer94@gmail.com>
tasks/configure_odl_logs.yml [new file with mode: 0644]
tasks/main.yml
vars/main.yml

diff --git a/tasks/configure_odl_logs.yml b/tasks/configure_odl_logs.yml
new file mode 100644 (file)
index 0000000..3d651d8
--- /dev/null
@@ -0,0 +1,45 @@
+---
+
+- name: set log levels
+  lineinfile:
+    path: /opt/opendaylight/etc/org.ops4j.pax.logging.cfg
+    regexp: "^log4j2.{{ item.value.log_name }}.level.*s"
+    line: "log4j2.{{ item.value.log_name }}.level = {{ item.value.log_level }}"
+  with_dict: "{{ log_levels }}"
+
+- name: configure console logging
+  block:
+    - name: make ODL log to console
+      lineinfile:
+        path: /opt/opendaylight/etc/org.ops4j.pax.logging.cfg
+        regexp: '^karaf.log.console.*$'
+        line: 'karaf.log.console=INFO'
+        insertafter: 'log4j2.rootLogger.appenderRef.Console.filter.threshold.type = ThresholdFilter'
+
+    - name: optimize console logging
+      lineinfile:
+        path: /opt/opendaylight/etc/org.ops4j.pax.logging.cfg
+        line: log4j2.appender.console.direct = true
+        regexp: '^log4j2.appender.console.direct.*$'
+        insertafter: karaf.log.console=INFO
+  when: "log_mechanism == 'console'"
+
+- name: configure logging to file
+  block:
+    - name: set log max size
+      lineinfile:
+        path: /opt/opendaylight/etc/org.ops4j.pax.logging.cfg
+        line: "log4j2.appender.rolling.policies.size.size = {{ log_max_size }}"
+        regexp: "^log4j2.appender.rolling.policies.size.size.*$"
+
+    - name: set rollover strategy
+      lineinfile:
+        path: /opt/opendaylight/etc/org.ops4j.pax.logging.cfg
+        line: log4j2.appender.rolling.strategy.type = DefaultRolloverStrategy
+
+    - name: set maximum number of ODL log rollovers
+      lineinfile:
+        path: /opt/opendaylight/etc/org.ops4j.pax.logging.cfg
+        line: "log4j2.appender.rolling.strategy.max = {{ log_max_rollover }}"
+        regexp: "^log4j2.appender.rolling.s"
+  when: "log_mechanism == 'file'"
index 69dde826a167944aa10a78bb9869d2828a2eddbd..9fd6457b83a39c1137facde1e8f7dbf0616dff9c 100644 (file)
@@ -10,6 +10,7 @@
 - include_tasks: configure_genius_tunnels.yml
   when: "'odl-netvirt-sfc' in features"
 - include_tasks: configure_odl_user.yml
+- include_tasks: configure_odl_logs.yml
 - include_tasks: start_odl.yml
 - include_tasks: configure_quagga.yml
   when:
index 65c2423f8daf630c0ea5bade57eb6555239d8b41..365ff9ab04baeba43295729ee68bbc75d04572e5 100755 (executable)
@@ -123,6 +123,16 @@ odl_bgp_speaker_host_ip_address: "{{ hostvars[inventory_hostname]['ansible_defau
 # thrift connection.
 bgp_config_server_port: 7644
 
+# Configure Log settings
+log_levels:
+  root:
+    log_name:
+    log_level:
+
+log_max_size: '10GB'
+log_max_rollover: 2
+log_mechanism: file
+
 # Quagga packages to be installed
 quagga_dependencies:
   - thrift