From 5c4d754381a7abb30eed73867f0ad4309d2e6236 Mon Sep 17 00:00:00 2001 From: Cory Ringdahl Date: Wed, 13 Mar 2019 14:18:52 -0700 Subject: [PATCH] Add compression to rotated logs. --- manifests/filter/container.pp | 16 ++++++++++++++++ manifests/params.pp | 3 +++ templates/log4j2.xml.erb | 8 ++++---- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/manifests/filter/container.pp b/manifests/filter/container.pp index f0d3132..acad7f3 100644 --- a/manifests/filter/container.pp +++ b/manifests/filter/container.pp @@ -92,6 +92,11 @@ # String. The max file size for the log4j RollingFileAppender. # Defaults to 100MB # +# [*log_local_compress*] +# String. Whether to compress the rotated log or not. +# Can be one of none,gz,zip +# Defaults to none +# # [*log_local_rotation_count*] # Integer. The number of backup files to keeo for the log4j RollingFileAppender # Defaults to 4 @@ -294,6 +299,7 @@ $log_level = $repose::params::log_level, $log_local_policy = $repose::params::log_local_policy, $log_local_size = $repose::params::log_local_size, + $log_local_compress = $repose::params::log_local_compress, $log_local_rotation_count = $repose::params::log_local_rotation_count, $log_repose_facility = $repose::params::log_repose_facility, $log_use_log4j2 = false, @@ -338,6 +344,16 @@ validate_array($ssl_exclude_cipher) } +## log_local_compress_ext + if ! ($log_local_compress in [ 'none', 'gz', 'zip' ]) { + fail("\"${log_local_compress}\" is not a valid log_local_compress parameter value") + } else { + $log_local_compress_ext = $log_local_compress ? { + 'none' => '', + 'gz' => '.gz', + 'zip' => '.zip', + } + ## ensure if ! ($ensure in [ present, absent ]) { fail("\"${ensure}\" is not a valid ensure parameter value") diff --git a/manifests/params.pp b/manifests/params.pp index 4824971..5e00ab0 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -179,6 +179,9 @@ ## default local log rotation count $log_local_rotation_count = 4 +## default log local compress is 'none' + $log_local_compress = 'none' + ## default repose.log syslog facility $log_repose_facility = 'local0' diff --git a/templates/log4j2.xml.erb b/templates/log4j2.xml.erb index 1d30445..764f34e 100644 --- a/templates/log4j2.xml.erb +++ b/templates/log4j2.xml.erb @@ -15,7 +15,7 @@ <%- if @log_local_policy == 'date' -%> + filePattern="<%= @log_dir-%>/<%= @app_name -%>.log.%d{yyyy-MM-dd}<%= @log_local_compress_ext -%>"> %d{yyyy-MM-dd HH:mm:ss} %-4r [%t] %-5p %c %x - %m%n @@ -26,7 +26,7 @@ <%- elsif @log_local_policy == 'size' -%> + filePattern="<%= @log_dir-%>/<%= @app_name -%>.log.%i<%= @log_local_compress_ext -%>"> %d{yyyy-MM-dd HH:mm:ss} %-4r [%t] %-5p %c %x - %m%n @@ -82,7 +82,7 @@ <%- if @log_local_policy == 'date' -%> + filePattern="<%= @log_dir-%>/<%= @log_access_local_name -%>.log.%d{yyyy-MM-dd}<%= @log_local_compress_ext -%>"> %m%n @@ -93,7 +93,7 @@ <%- elsif @log_local_policy == 'size' -%> + filePattern="<%= @log_dir-%>/<%= @log_access_local_name -%>.log.%i<%= @log_local_compress_ext -%>"> %m%n