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

More flexible file logging channel options #270

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
27 changes: 12 additions & 15 deletions manifests/logging/channel.pp
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@
# @param syslog_facility
# The syslog facility to use when logging to a syslog log_type
define dns::logging::channel (
Optional[Stdlib::Absolutepath] $file_path = undef,
Optional[String] $file_size = undef,
Optional[Integer] $file_versions = undef,
Enum['file', 'null', 'stderr', 'syslog'] $log_type = undef,
Integer[51, 59] $order = 51,
Optional[Enum['no', 'yes']] $print_category = undef,
Optional[Enum['no', 'yes']] $print_severity = undef,
Optional[Enum['no', 'yes']] $print_time = undef,
Optional[String] $severity = undef,
Optional[String] $syslog_facility = undef,
Optional[Stdlib::Absolutepath] $file_path = undef,
Optional[String] $file_size = undef,
Optional[Variant[Enum['unlimited'],Integer]] $file_versions = undef,
Enum['file', 'null', 'stderr', 'syslog'] $log_type = undef,
Integer[51, 59] $order = 51,
Optional[Enum['no', 'yes']] $print_category = undef,
Optional[Enum['no', 'yes']] $print_severity = undef,
Optional[Enum['no', 'yes']] $print_time = undef,
Optional[String] $severity = undef,
Optional[String] $syslog_facility = undef,
) {
include dns::logging

Expand All @@ -55,11 +55,8 @@
if empty($file_path) {
fail('dns::logging::channel: "file_path" needs to be set with log type file')
}
if empty($file_size) {
fail('dns::logging::channel: "file_size" needs to be set with log type file')
}
if !$file_versions {
fail('dns::logging::channel: "file_versions" needs to be set with log type file')
if $file_versions and empty($file_size) {
fail('dns::logging::channel: "file_size" needs to be set if "file_version" is set')
}
}

Expand Down
13 changes: 12 additions & 1 deletion spec/defines/dns_logging_channel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@
it { is_expected.not_to compile }
end

describe 'with log_type = file and file_size and file_version not set' do
let(:params) do
{
'log_type' => 'file',
'file_path' => '/path/to/file.log',
}
end

it { is_expected.to compile.with_all_deps }
benjamin-robertson marked this conversation as resolved.
Show resolved Hide resolved
end

describe 'with log_type = file and file_versions not set' do
let(:params) do
{
Expand All @@ -163,7 +174,7 @@
}
end

it { is_expected.not_to compile }
it { is_expected.to compile.with_all_deps }
benjamin-robertson marked this conversation as resolved.
Show resolved Hide resolved
end

describe 'with log_type = syslog and all options set' do
Expand Down
6 changes: 6 additions & 0 deletions templates/log.channel.conf.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
channel <%= @channel_name %> {
<%- if @log_type == 'file' -%>
<%- if @file_versions and @file_size -%>
benjamin-robertson marked this conversation as resolved.
Show resolved Hide resolved
file "<%= @file_path -%>" versions <%= @file_versions -%> size <%= @file_size -%>;
<%- elsif @file_size -%>
file "<%= @file_path -%>" size <%= @file_size -%>;
<%- else -%>
benjamin-robertson marked this conversation as resolved.
Show resolved Hide resolved
file "<%= @file_path -%>";
<%- end -%>
<%- elsif @log_type == 'null' -%>
null;
<%- elsif @log_type == 'stderr' -%>
Expand Down
Loading