@@ -117,28 +117,47 @@ appender.rolling.type = RollingFile <1>
117
117
appender.rolling.name = rolling
118
118
appender.rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}.log <2>
119
119
appender.rolling.layout.type = PatternLayout
120
- appender.rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c] %. 10000m%n
121
- appender.rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-%d{yyyy-MM-dd}.log <3>
120
+ appender.rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.} ] %marker%.- 10000m%n
121
+ appender.rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-%d{yyyy-MM-dd}-%i .log.gz <3>
122
122
appender.rolling.policies.type = Policies
123
123
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy <4>
124
124
appender.rolling.policies.time.interval = 1 <5>
125
125
appender.rolling.policies.time.modulate = true <6>
126
+ appender.rolling.policies.size.type = SizeBasedTriggeringPolicy <7>
127
+ appender.rolling.policies.size.size = 256MB <8>
128
+ appender.rolling.strategy.type = DefaultRolloverStrategy
129
+ appender.rolling.strategy.fileIndex = nomax
130
+ appender.rolling.strategy.action.type = Delete <9>
131
+ appender.rolling.strategy.action.basepath = ${sys:es.logs.base_path}
132
+ appender.rolling.strategy.action.condition.type = IfFileName <10>
133
+ appender.rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}-* <11>
134
+ appender.rolling.strategy.action.condition.nested_condition.type = IfAccumulatedFileSize <12>
135
+ appender.rolling.strategy.action.condition.nested_condition.exceeds = 2GB <13>
126
136
--------------------------------------------------
127
137
128
138
<1> Configure the `RollingFile` appender
129
139
<2> Log to `/var/log/elasticsearch/production.log`
130
- <3> Roll logs to `/var/log/elasticsearch/production-yyyy-MM-dd.log`
131
- <4> Using a time-based roll policy
140
+ <3> Roll logs to `/var/log/elasticsearch/production-yyyy-MM-dd-i.log`; logs
141
+ will be compressed on each roll and `i` will be incremented
142
+ <4> Use a time-based roll policy
132
143
<5> Roll logs on a daily basis
133
144
<6> Align rolls on the day boundary (as opposed to rolling every twenty-four
134
145
hours)
146
+ <7> Using a size-based roll policy
147
+ <8> Roll logs after 256 MB
148
+ <9> Use a delete action when rolling logs
149
+ <10> Only delete logs matching a file pattern
150
+ <11> The pattern is to only delete the main logs
151
+ <12> Only delete if we have accumulated too many compressed logs
152
+ <13> The size condition on the compressed logs is 2 GB
135
153
136
154
NOTE: Log4j's configuration parsing gets confused by any extraneous whitespace;
137
155
if you copy and paste any Log4j settings on this page, or enter any Log4j
138
156
configuration in general, be sure to trim any leading and trailing whitespace.
139
157
140
- If you append `.gz` or `.zip` to `appender.rolling.filePattern`, then the logs
141
- will be compressed as they are rolled.
158
+ Note than you can replace `.gz` by `.zip` in `appender.rolling.filePattern` to
159
+ compress the rolled logs using the zip format. If you remove the `.gz`
160
+ extension then logs will not be compressed as they are rolled.
142
161
143
162
If you want to retain log files for a specified period of time, you can use a
144
163
rollover strategy with a delete action.
@@ -148,22 +167,22 @@ rollover strategy with a delete action.
148
167
appender.rolling.strategy.type = DefaultRolloverStrategy <1>
149
168
appender.rolling.strategy.action.type = Delete <2>
150
169
appender.rolling.strategy.action.basepath = ${sys:es.logs.base_path} <3>
151
- appender.rolling.strategy.action.condition.type = IfLastModified <4>
152
- appender.rolling.strategy.action.condition.age = 7D <5>
153
- appender.rolling.strategy.action.PathConditions. type = IfFileName <6>
154
- appender.rolling.strategy.action.PathConditions.glob = ${sys:es.logs.cluster_name}-* <7>
170
+ appender.rolling.strategy.action.condition.type = IfFileName <4>
171
+ appender.rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}-* <5>
172
+ appender.rolling.strategy.action.condition.nested_condition. type = IfLastModified <6>
173
+ appender.rolling.strategy.action.condition.nested_condition.age = 7D <7>
155
174
--------------------------------------------------
156
175
157
176
<1> Configure the `DefaultRolloverStrategy`
158
177
<2> Configure the `Delete` action for handling rollovers
159
178
<3> The base path to the Elasticsearch logs
160
179
<4> The condition to apply when handling rollovers
161
- <5> Retain logs for seven days
162
- <6> Only delete files older than seven days if they match the specified glob
163
- <7> Delete files from the base path matching the glob
180
+ <5> Delete files from the base path matching the glob
164
181
`${sys:es.logs.cluster_name}-*`; this is the glob that log files are rolled
165
182
to; this is needed to only delete the rolled Elasticsearch logs but not also
166
183
delete the deprecation and slow logs
184
+ <6> A nested condition to apply to files matching the glob
185
+ <7> Retain logs for seven days
167
186
168
187
Multiple configuration files can be loaded (in which case they will get merged)
169
188
as long as they are named `log4j2.properties` and have the Elasticsearch config
0 commit comments