Skip to content

Commit 9f28467

Browse files
authored
Merge pull request #1260 from voxpupuli/new-log4j-support
Add parameter to manage the content of log4j2.properties
2 parents 40e341b + 2e32949 commit 9f28467

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

REFERENCE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ The following parameters are available in the `elasticsearch` class:
129129
* [`license`](#-elasticsearch--license)
130130
* [`logdir`](#-elasticsearch--logdir)
131131
* [`logdir_mode`](#-elasticsearch--logdir_mode)
132+
* [`logging_content`](#-elasticsearch--logging_content)
132133
* [`manage_datadir`](#-elasticsearch--manage_datadir)
133134
* [`manage_logdir`](#-elasticsearch--manage_logdir)
134135
* [`manage_repo`](#-elasticsearch--manage_repo)
@@ -398,6 +399,14 @@ Mode directory that will be used for Elasticsearch logging (default 2750).
398399

399400
Default value: `'2750'`
400401

402+
##### <a name="-elasticsearch--logging_content"></a>`logging_content`
403+
404+
Data type: `Optional[Variant[String, Array]]`
405+
406+
Content to use for the logging configuration file (log4j2.properties).
407+
408+
Default value: `undef`
409+
401410
##### <a name="-elasticsearch--manage_datadir"></a>`manage_datadir`
402411

403412
Data type: `Boolean`

manifests/config.pp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,24 @@
141141
$_tls_config = {}
142142
}
143143

144+
# Logging file
145+
if ! ($elasticsearch::logging_content =~ Undef) {
146+
if $elasticsearch::logging_content =~ Array {
147+
$_log4j_content = $elasticsearch::logging_content.join("\n")
148+
} else {
149+
$_log4j_content = $elasticsearch::logging_content
150+
}
151+
file { "${elasticsearch::configdir}/log4j2.properties":
152+
ensure => file,
153+
content => $_log4j_content,
154+
notify => $elasticsearch::_notify_service,
155+
require => Class['elasticsearch::package'],
156+
owner => 'root',
157+
group => $elasticsearch::elasticsearch_group,
158+
mode => '0640',
159+
}
160+
}
161+
144162
# Generate Elasticsearch config
145163
$data =
146164
$elasticsearch::config + { 'path.data' => $elasticsearch::datadir } + { 'path.logs' => $elasticsearch::logdir } + $_tls_config
@@ -150,9 +168,9 @@
150168
content => template("${module_name}/etc/elasticsearch/elasticsearch.yml.erb"),
151169
notify => $elasticsearch::_notify_service,
152170
require => Class['elasticsearch::package'],
153-
owner => $elasticsearch::elasticsearch_user,
171+
owner => 'root',
154172
group => $elasticsearch::elasticsearch_group,
155-
mode => '0440',
173+
mode => '0640',
156174
}
157175

158176
file { "${elasticsearch::configdir}/jvm.options":

manifests/init.pp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@
133133
# @param logdir_mode
134134
# Mode directory that will be used for Elasticsearch logging (default 2750).
135135
#
136+
# @param logging_content
137+
# Content to use for the logging configuration file (log4j2.properties).
138+
#
136139
# @param manage_datadir
137140
# Enable datadir management (default true).
138141
#
@@ -375,6 +378,7 @@
375378
Optional[String] $keystore_password = undef,
376379
Optional[Stdlib::Absolutepath] $keystore_path = undef,
377380
Stdlib::Filemode $logdir_mode = '2750',
381+
Optional[Variant[String, Array]] $logging_content = undef,
378382
Boolean $package_hold = false,
379383
Optional[Stdlib::Absolutepath] $private_key = undef,
380384
Enum['rsa','dsa','ec'] $private_key_type = 'rsa',

spec/classes/000_elasticsearch_init_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@
7979
}
8080
end
8181

82+
it { expect(subject).not_to contain_file('/etc/elasticsearch/log4j2.properties') }
83+
8284
context 'java installation' do
8385
let(:pre_condition) do
8486
<<-MANIFEST
@@ -346,6 +348,35 @@
346348
expect(subject).not_to contain_file('/var/log/elasticsearch-log')
347349
}
348350
end
351+
352+
context 'When using custom logging_content String' do
353+
let(:params) do
354+
default_params.merge(
355+
logging_content: '# Content'
356+
)
357+
end
358+
359+
it {
360+
expect(subject).to contain_file('/etc/elasticsearch/log4j2.properties').
361+
with(ensure: 'file', content: '# Content')
362+
}
363+
end
364+
365+
context 'When using custom logging_content Array' do
366+
let(:params) do
367+
default_params.merge(
368+
logging_content: [
369+
'# Content Line 1',
370+
'# Content Line 2',
371+
]
372+
)
373+
end
374+
375+
it {
376+
expect(subject).to contain_file('/etc/elasticsearch/log4j2.properties').
377+
with(ensure: 'file', content: "# Content Line 1\n# Content Line 2")
378+
}
379+
end
349380
end
350381
end
351382
# rubocop:enable RSpec/MultipleMemoizedHelpers

0 commit comments

Comments
 (0)