diff --git a/REFERENCE.md b/REFERENCE.md index c2b5a708..33125fd8 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -489,10 +489,11 @@ Default value: `$redis::params::log_dir_mode` ##### `log_file` -Data type: `String` +Data type: `Variant[Boolean[false], String[1]]` Specify file where to write log entries. Relative paths will be prepended -with log_dir but absolute paths are also accepted. +with log_dir but absolute paths are also accepted. Boolean false means only +log to systemd-journald. Default value: `'redis.log'` @@ -2270,10 +2271,11 @@ Default value: `$redis::log_dir_mode` ##### `log_file` -Data type: `String` +Data type: `Variant[Boolean[false], String[1]]` Specify file where to write log entries. Relative paths will be prepended -with log_dir but absolute paths are also accepted. +with log_dir but absolute paths are also accepted. Boolean false means only +log to systemd-journald. Default value: `"redis-server-${name}.log"` diff --git a/manifests/init.pp b/manifests/init.pp index e48ed67c..2dffd7af 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -85,7 +85,8 @@ # Adjust mode for directory containing log files. # @param log_file # Specify file where to write log entries. Relative paths will be prepended -# with log_dir but absolute paths are also accepted. +# with log_dir but absolute paths are also accepted. Boolean false means only +# log to systemd-journald. # @param log_level # Specify the server verbosity level. # @param manage_repo @@ -386,7 +387,7 @@ Integer[0] $list_max_ziplist_value = 64, Stdlib::Absolutepath $log_dir = $redis::params::log_dir, Stdlib::Filemode $log_dir_mode = $redis::params::log_dir_mode, - String $log_file = 'redis.log', + Variant[Boolean[false], String[1]] $log_file = 'redis.log', Redis::LogLevel $log_level = 'notice', Boolean $manage_service_file = false, Boolean $manage_package = true, diff --git a/manifests/instance.pp b/manifests/instance.pp index 3b18cfca..6996c449 100644 --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -66,7 +66,8 @@ # Adjust mode for directory containing log files. # @param log_file # Specify file where to write log entries. Relative paths will be prepended -# with log_dir but absolute paths are also accepted. +# with log_dir but absolute paths are also accepted. Boolean false means only +# log to systemd-journald. # @param log_level # Specify the server verbosity level. # @param managed_by_cluster_manager @@ -396,7 +397,7 @@ Optional[Integer[0]] $service_timeout_start = $redis::service_timeout_start, Optional[Integer[0]] $service_timeout_stop = $redis::service_timeout_stop, Boolean $manage_service_file = true, - String $log_file = "redis-server-${name}.log", + Variant[Boolean[false], String[1]] $log_file = "redis-server-${name}.log", Stdlib::Absolutepath $pid_file = "/var/run/${service_name}/redis.pid", Variant[Stdlib::Absolutepath, Enum['']] $unixsocket = "/var/run/${service_name}/redis.sock", Stdlib::Absolutepath $workdir = "${redis::workdir}/redis-server-${name}", @@ -496,6 +497,7 @@ $_real_log_file = $log_file ? { Stdlib::Absolutepath => $log_file, + Boolean => false, default => "${log_dir}/${log_file}", } diff --git a/spec/classes/redis_spec.rb b/spec/classes/redis_spec.rb index b0cae74a..7f4c98e6 100644 --- a/spec/classes/redis_spec.rb +++ b/spec/classes/redis_spec.rb @@ -451,6 +451,20 @@ class { 'redis': ) } end + + describe 'as false' do + let(:params) do + { + log_file: false + } + end + + it { + is_expected.to contain_file(config_file_orig).with( + 'content' => %r{^logfile ""$} + ) + } + end end describe 'with parameter log_level' do diff --git a/templates/redis.conf.epp b/templates/redis.conf.epp index a14f7060..6c3da502 100644 --- a/templates/redis.conf.epp +++ b/templates/redis.conf.epp @@ -10,7 +10,7 @@ Integer[0] $timeout, Integer[0] $tcp_keepalive, Redis::LogLevel $log_level, - Stdlib::Absolutepath $log_file, + Variant[Stdlib::Absolutepath, Boolean[false]] $log_file, Boolean $syslog_enabled, Optional[String[1]] $syslog_facility, Integer[1] $databases, @@ -304,7 +304,11 @@ loglevel <%= $log_level %> # Specify the log file name. Also 'stdout' can be used to force # Redis to log on the standard output. Note that if you use standard # output for logging but daemonize, logs will be sent to /dev/null -logfile <%= $log_file %> +logfile <% if $log_file { -%> +<%= $log_file %> +<% } else { -%> +"" +<% } -%> # To enable logging to the system logger, just set 'syslog-enabled' to yes, # and optionally update the other syslog parameters to suit your needs.