Skip to content

Commit f3ba264

Browse files
committed
new parameters logging support
1 parent 543c582 commit f3ba264

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

REFERENCE.md

+27
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,14 @@ The following parameters are available in the `elasticsearch` class:
135135
* [`logdir`](#-elasticsearch--logdir)
136136
* [`logdir_mode`](#-elasticsearch--logdir_mode)
137137
* [`logging_config`](#-elasticsearch--logging_config)
138+
* [`logging_content`](#-elasticsearch--logging_content)
138139
* [`logging_file`](#-elasticsearch--logging_file)
139140
* [`logging_level`](#-elasticsearch--logging_level)
141+
* [`logging_path`](#-elasticsearch--logging_path)
140142
* [`logging_template`](#-elasticsearch--logging_template)
141143
* [`manage_datadir`](#-elasticsearch--manage_datadir)
142144
* [`manage_logdir`](#-elasticsearch--manage_logdir)
145+
* [`manage_logging`](#-elasticsearch--manage_logging)
143146
* [`manage_repo`](#-elasticsearch--manage_repo)
144147
* [`oss`](#-elasticsearch--oss)
145148
* [`package_dir`](#-elasticsearch--package_dir)
@@ -451,6 +454,14 @@ Data type: `Hash`
451454

452455
Representation of information to be included in the log4j.properties file.
453456

457+
##### <a name="-elasticsearch--logging_content"></a>`logging_content`
458+
459+
Data type: `Optional[String]`
460+
461+
Representation of content to be included in the log4j2.properties file.
462+
463+
Default value: `undef`
464+
454465
##### <a name="-elasticsearch--logging_file"></a>`logging_file`
455466

456467
Data type: `Optional[String]`
@@ -464,6 +475,14 @@ Data type: `String`
464475

465476
Default logging level for Elasticsearch.
466477

478+
##### <a name="-elasticsearch--logging_path"></a>`logging_path`
479+
480+
Data type: `Stdlib::Absolutepath`
481+
482+
Custom path to the logging file.
483+
484+
Default value: `"${configdir}/log4j2.properties"`
485+
467486
##### <a name="-elasticsearch--logging_template"></a>`logging_template`
468487

469488
Data type: `Optional[String]`
@@ -483,6 +502,14 @@ Data type: `Boolean`
483502

484503
Enable logdir management (default true).
485504

505+
##### <a name="-elasticsearch--manage_logging"></a>`manage_logging`
506+
507+
Data type: `Boolean`
508+
509+
Enable logging (log4j) management (default false).
510+
511+
Default value: `false`
512+
486513
##### <a name="-elasticsearch--manage_repo"></a>`manage_repo`
487514

488515
Data type: `Boolean`

manifests/config.pp

+14
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,20 @@
163163
# before => Class['elasticsearch::service'],
164164
# }
165165

166+
# Logging file
167+
if $elasticsearch::manage_logging and !empty($elasticsearch::logging_content) {
168+
file { $elasticsearch::logging_path:
169+
ensure => file,
170+
content => $elasticsearch::logging_content,
171+
group => $elasticsearch::elasticsearch_group,
172+
owner => $elasticsearch::elasticsearch_user,
173+
mode => '0644',
174+
notify => $elasticsearch::_notify_service,
175+
require => File[$elasticsearch::configdir],
176+
before => Class['elasticsearch::service'],
177+
}
178+
}
179+
166180
# Generate Elasticsearch config
167181
$data =
168182
$elasticsearch::config + { 'path.data' => $elasticsearch::datadir } + { 'path.logs' => $elasticsearch::logdir } + $_tls_config

manifests/init.pp

+12
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,19 @@
154154
# @param logging_config
155155
# Representation of information to be included in the log4j.properties file.
156156
#
157+
# @param logging_content
158+
# Representation of content to be included in the log4j2.properties file.
159+
#
157160
# @param logging_file
158161
# Instead of a hash, you may supply a `puppet://` file source for the
159162
# log4j.properties file.
160163
#
161164
# @param logging_level
162165
# Default logging level for Elasticsearch.
163166
#
167+
# @param logging_path
168+
# Custom path to the logging file.
169+
#
164170
# @param logging_template
165171
# Use a custom logging template - just supply the relative path, i.e.
166172
# `$module/elasticsearch/logging.yml.erb`
@@ -171,6 +177,9 @@
171177
# @param manage_logdir
172178
# Enable logdir management (default true).
173179
#
180+
# @param manage_logging
181+
# Enable logging (log4j) management (default false).
182+
#
174183
# @param manage_repo
175184
# Enable repo management by enabling official Elastic repositories.
176185
#
@@ -430,6 +439,9 @@
430439
String $default_logging_level = $logging_level,
431440
Optional[String] $keystore_password = undef,
432441
Optional[Stdlib::Absolutepath] $keystore_path = undef,
442+
Optional[String] $logging_content = undef,
443+
Stdlib::Absolutepath $logging_path = "${configdir}/log4j2.properties",
444+
Boolean $manage_logging = false,
433445
Optional[Stdlib::Absolutepath] $private_key = undef,
434446
Enum['rsa','dsa','ec'] $private_key_type = 'rsa',
435447
Boolean $restart_config_change = $restart_on_change,

spec/classes/000_elasticsearch_init_spec.rb

+53
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,59 @@
515515
}
516516
end
517517

518+
context 'When managing the logging file (with content)' do
519+
let(:params) do
520+
default_params.merge(
521+
logging_content: '# Content',
522+
manage_logging: true
523+
)
524+
end
525+
526+
it {
527+
expect(subject).to contain_file('/etc/elasticsearch/log4j2.properties').
528+
with(ensure: 'file', content: '# Content')
529+
}
530+
end
531+
532+
context 'When managing the logging file (with content and specific path)' do
533+
let(:params) do
534+
default_params.merge(
535+
logging_content: '# Content',
536+
logging_path: '/etc/elasticsearch/log4j.properties',
537+
manage_logging: true
538+
)
539+
end
540+
541+
it {
542+
expect(subject).to contain_file('/etc/elasticsearch/log4j.properties').
543+
with(ensure: 'file', content: '# Content')
544+
}
545+
end
546+
547+
context 'When managing the logging file (with no content)' do
548+
let(:params) do
549+
default_params.merge(
550+
manage_logging: true
551+
)
552+
end
553+
554+
it {
555+
expect(subject).not_to contain_file('/etc/elasticsearch/log4j2.properties')
556+
}
557+
end
558+
559+
context 'When not managing the logging file' do
560+
let(:params) do
561+
default_params.merge(
562+
manage_logging: false
563+
)
564+
end
565+
566+
it {
567+
expect(subject).not_to contain_file('/etc/elasticsearch/log4j2.properties')
568+
}
569+
end
570+
518571
context 'with restart_on_change => true' do
519572
let(:params) do
520573
default_params.merge(

0 commit comments

Comments
 (0)