Skip to content

Commit

Permalink
Allow no logfile to log to systemd-journald only
Browse files Browse the repository at this point in the history
  • Loading branch information
Lennart Betz committed Sep 24, 2024
1 parent fd9cb3f commit b77093a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
10 changes: 6 additions & 4 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,11 @@ Default value: `$redis::params::log_dir_mode`

##### <a name="-redis--log_file"></a>`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'`

Expand Down Expand Up @@ -2270,10 +2271,11 @@ Default value: `$redis::log_dir_mode`

##### <a name="-redis--instance--log_file"></a>`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"`

Expand Down
5 changes: 3 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions manifests/instance.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}",
Expand Down Expand Up @@ -496,6 +497,7 @@

$_real_log_file = $log_file ? {
Stdlib::Absolutepath => $log_file,
Boolean => false,
default => "${log_dir}/${log_file}",
}

Expand Down
14 changes: 14 additions & 0 deletions spec/classes/redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions templates/redis.conf.epp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit b77093a

Please sign in to comment.