Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow no logfile to log to systemd-journald only #534

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please add a unit test that sets this to false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grrr. Done.

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 @@ -61,7 +61,7 @@
PUPPET
end

it { is_expected.to compile.with_all_deps }

Check failure on line 64 in spec/classes/redis_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

redis on redhat-8-x86_64 without parameters with manage_dnf_module true is expected to compile into a catalogue without dependency cycles Failure/Error: it { is_expected.to compile.with_all_deps } ArgumentError: Cannot alias Package[redis dnf module] to [nil, "redis", :dnfmodule] at (file: /home/runner/work/puppet-redis/puppet-redis/spec/fixtures/modules/redis/manifests/dnfmodule.pp, line: 18); resource ["Package", nil, "redis", :dnfmodule] already declared (file: /home/runner/work/puppet-redis/puppet-redis/spec/fixtures/modules/redis/manifests/install.pp, line: 5)

Check failure on line 64 in spec/classes/redis_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

redis on almalinux-8-x86_64 without parameters with manage_dnf_module true is expected to compile into a catalogue without dependency cycles Failure/Error: it { is_expected.to compile.with_all_deps } ArgumentError: Cannot alias Package[redis dnf module] to [nil, "redis", :dnfmodule] at (file: /home/runner/work/puppet-redis/puppet-redis/spec/fixtures/modules/redis/manifests/dnfmodule.pp, line: 18); resource ["Package", nil, "redis", :dnfmodule] already declared (file: /home/runner/work/puppet-redis/puppet-redis/spec/fixtures/modules/redis/manifests/install.pp, line: 5)

Check failure on line 64 in spec/classes/redis_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

redis on rocky-8-x86_64 without parameters with manage_dnf_module true is expected to compile into a catalogue without dependency cycles Failure/Error: it { is_expected.to compile.with_all_deps } ArgumentError: Cannot alias Package[redis dnf module] to [nil, "redis", :dnfmodule] at (file: /home/runner/work/puppet-redis/puppet-redis/spec/fixtures/modules/redis/manifests/dnfmodule.pp, line: 18); resource ["Package", nil, "redis", :dnfmodule] already declared (file: /home/runner/work/puppet-redis/puppet-redis/spec/fixtures/modules/redis/manifests/install.pp, line: 5)
it { is_expected.to contain_package('redis dnf module').with_ensure('6').that_comes_before('Package[redis]') }
it { is_expected.to contain_package('redis').with_name('redis') }
end
Expand Down Expand Up @@ -451,6 +451,20 @@
)
}
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
Loading