0
# Appender Factories
1
2
Comprehensive set of appender implementations for different output destinations including console, files, syslog, and network sockets with extensive configuration options. All appender factories support Jackson-based configuration and can be used both programmatically and via YAML configuration.
3
4
## Capabilities
5
6
### AppenderFactory Interface
7
8
Base SPI interface for creating Logback Appender instances with Jackson-based polymorphic configuration support.
9
10
```java { .api }
11
/**
12
* SPI for creating Logback Appender instances
13
*/
14
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
15
public interface AppenderFactory<E> extends Discoverable {
16
/**
17
* Build an appender instance
18
* @param context the Logback logger context
19
* @param applicationName the application name
20
* @param layoutFactory factory for creating layouts
21
* @param levelFilterFactory factory for creating level filters
22
* @param asyncAppenderFactory factory for creating async wrappers
23
* @return configured Appender instance
24
*/
25
Appender<E> build(LoggerContext context, String applicationName,
26
LayoutFactory<E> layoutFactory,
27
LevelFilterFactory<E> levelFilterFactory,
28
AsyncAppenderFactory<E> asyncAppenderFactory);
29
}
30
```
31
32
### AbstractAppenderFactory
33
34
Base implementation providing common appender configuration options including async support, filtering, and formatting.
35
36
```java { .api }
37
/**
38
* Base implementation with common appender configuration
39
*/
40
public abstract class AbstractAppenderFactory<E> implements AppenderFactory<E> {
41
protected Level threshold = Level.ALL;
42
protected String logFormat = null;
43
protected DiscoverableLayoutFactory<E> layout = null;
44
protected TimeZone timeZone = TimeZone.getTimeZone("UTC");
45
protected int queueSize = 256;
46
protected int discardingThreshold = -1;
47
protected Duration messageRate = null;
48
protected boolean includeCallerData = false;
49
protected List<FilterFactory<E>> filterFactories = new ArrayList<>();
50
protected boolean neverBlock = false;
51
52
/**
53
* Get the minimum event level for this appender
54
* @return the threshold level as string
55
*/
56
public String getThreshold();
57
58
/**
59
* Set the minimum event level for this appender
60
* @param threshold the minimum level
61
*/
62
public void setThreshold(Level threshold);
63
64
/**
65
* Get the log format pattern
66
* @return the pattern layout format string
67
*/
68
public String getLogFormat();
69
70
/**
71
* Set the log format pattern
72
* @param logFormat the pattern layout format string
73
*/
74
public void setLogFormat(String logFormat);
75
76
/**
77
* Get the custom layout factory
78
* @return the layout factory
79
*/
80
public DiscoverableLayoutFactory<?> getLayout();
81
82
/**
83
* Set a custom layout factory
84
* @param layout the layout factory
85
*/
86
public void setLayout(DiscoverableLayoutFactory<E> layout);
87
88
/**
89
* Get the timezone for timestamps
90
* @return the timezone
91
*/
92
public TimeZone getTimeZone();
93
94
/**
95
* Set the timezone for timestamps
96
* @param timeZone the timezone
97
*/
98
public void setTimeZone(TimeZone timeZone);
99
100
/**
101
* Get the async queue size
102
* @return the queue size for async appenders
103
*/
104
public int getQueueSize();
105
106
/**
107
* Set the async queue size
108
* @param queueSize the queue size for async appenders
109
*/
110
public void setQueueSize(int queueSize);
111
112
/**
113
* Get the async discarding threshold
114
* @return events below this level may be discarded when queue is full
115
*/
116
public int getDiscardingThreshold();
117
118
/**
119
* Set the async discarding threshold
120
* @param discardingThreshold events below this level may be discarded when queue is full
121
*/
122
public void setDiscardingThreshold(int discardingThreshold);
123
124
/**
125
* Get the message rate limiting duration
126
* @return maximum rate for log messages
127
*/
128
public Duration getMessageRate();
129
130
/**
131
* Set message rate limiting
132
* @param messageRate maximum rate for log messages
133
*/
134
public void setMessageRate(Duration messageRate);
135
136
/**
137
* Check if caller data is included in async logging
138
* @return true if caller information is included
139
*/
140
public boolean isIncludeCallerData();
141
142
/**
143
* Include caller data in async logging
144
* @param includeCallerData true to include caller information
145
*/
146
public void setIncludeCallerData(boolean includeCallerData);
147
148
/**
149
* Get additional filter factories
150
* @return list of filter factories
151
*/
152
public List<FilterFactory<E>> getFilterFactories();
153
154
/**
155
* Set additional filter factories
156
* @param filterFactories list of filter factories
157
*/
158
public void setFilterFactories(List<FilterFactory<E>> filterFactories);
159
160
/**
161
* Set non-blocking behavior for async appenders
162
* @param neverBlock true to never block on full queue
163
*/
164
public void setNeverBlock(boolean neverBlock);
165
166
/**
167
* Wrap appender in async wrapper if needed
168
* @param context the logger context
169
* @param asyncAppenderFactory factory for async appenders
170
* @param appender the appender to wrap
171
* @return the wrapped appender
172
*/
173
protected Appender<E> wrapAsync(LoggerContext context,
174
AsyncAppenderFactory<E> asyncAppenderFactory,
175
Appender<E> appender);
176
177
/**
178
* Build layout with timezone support
179
* @param context the logger context
180
* @param layoutFactory the layout factory
181
* @return configured layout
182
*/
183
protected Layout<E> buildLayout(LoggerContext context, LayoutFactory<E> layoutFactory);
184
}
185
```
186
187
### ConsoleAppenderFactory
188
189
Factory for creating console output appenders supporting both STDOUT and STDERR targets.
190
191
```java { .api }
192
/**
193
* Factory for console output appenders
194
*/
195
@JsonTypeName("console")
196
public class ConsoleAppenderFactory<E> extends AbstractOutputStreamAppenderFactory<E> {
197
private ConsoleStream target = ConsoleStream.STDOUT;
198
199
/**
200
* Set the console output target
201
* @param target STDOUT or STDERR
202
*/
203
public void setTarget(ConsoleStream target);
204
205
/**
206
* Get the console output target
207
* @return the current target
208
*/
209
public ConsoleStream getTarget();
210
211
/**
212
* Console output stream options
213
*/
214
public enum ConsoleStream {
215
STDOUT, STDERR
216
}
217
}
218
```
219
220
**Usage Example:**
221
222
```java
223
ConsoleAppenderFactory<ILoggingEvent> consoleAppender = new ConsoleAppenderFactory<>();
224
consoleAppender.setTarget(ConsoleAppenderFactory.ConsoleStream.STDOUT);
225
consoleAppender.setLogFormat("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n");
226
consoleAppender.setThreshold(Level.INFO);
227
```
228
229
### FileAppenderFactory
230
231
Factory for file-based appenders with comprehensive rotation and archiving capabilities.
232
233
```java { .api }
234
/**
235
* Factory for file-based appenders with rotation
236
*/
237
@JsonTypeName("file")
238
public class FileAppenderFactory<E> extends AbstractOutputStreamAppenderFactory<E> {
239
private String currentLogFilename;
240
private boolean archive = true;
241
private String archivedLogFilenamePattern;
242
private int archivedFileCount = 5;
243
private DataSize maxFileSize = DataSize.megabytes(10);
244
private DataSize totalSizeCap = DataSize.gigabytes(1);
245
private DataSize bufferSize = DataSize.kibibytes(8);
246
private boolean immediateFlush = true;
247
248
/**
249
* Set the current log file name
250
* @param currentLogFilename path to the current log file
251
*/
252
public void setCurrentLogFilename(String currentLogFilename);
253
254
/**
255
* Enable or disable log archiving
256
* @param archive true to enable archiving
257
*/
258
public void setArchive(boolean archive);
259
260
/**
261
* Set the archived log filename pattern
262
* @param archivedLogFilenamePattern pattern for archived files
263
*/
264
public void setArchivedLogFilenamePattern(String archivedLogFilenamePattern);
265
266
/**
267
* Set the number of archived files to keep
268
* @param archivedFileCount number of archive files
269
*/
270
public void setArchivedFileCount(int archivedFileCount);
271
272
/**
273
* Set the maximum file size before rotation
274
* @param maxFileSize maximum size per file
275
*/
276
public void setMaxFileSize(DataSize maxFileSize);
277
278
/**
279
* Set the total size cap for all log files
280
* @param totalSizeCap maximum total size
281
*/
282
public void setTotalSizeCap(DataSize totalSizeCap);
283
284
/**
285
* Set the output buffer size
286
* @param bufferSize buffer size for file operations
287
*/
288
public void setBufferSize(DataSize bufferSize);
289
290
/**
291
* Set immediate flush behavior
292
* @param immediateFlush true to flush immediately
293
*/
294
public void setImmediateFlush(boolean immediateFlush);
295
}
296
```
297
298
**Usage Example:**
299
300
```java
301
FileAppenderFactory<ILoggingEvent> fileAppender = new FileAppenderFactory<>();
302
fileAppender.setCurrentLogFilename("./logs/application.log");
303
fileAppender.setArchivedLogFilenamePattern("./logs/application-%d{yyyy-MM-dd}-%i.log.gz");
304
fileAppender.setMaxFileSize(DataSize.megabytes(50));
305
fileAppender.setArchivedFileCount(10);
306
fileAppender.setTotalSizeCap(DataSize.gigabytes(2));
307
```
308
309
### SyslogAppenderFactory
310
311
Factory for syslog appenders supporting standard syslog facilities and remote syslog servers.
312
313
```java { .api }
314
/**
315
* Factory for syslog appenders
316
*/
317
@JsonTypeName("syslog")
318
public class SyslogAppenderFactory extends AbstractAppenderFactory<ILoggingEvent> {
319
private String host = "localhost";
320
private int port = 514;
321
private Facility facility = Facility.LOCAL0;
322
private String stackTracePrefix = null;
323
private boolean includeStackTrace = true;
324
325
/**
326
* Set the syslog server host
327
* @param host hostname or IP address
328
*/
329
public void setHost(String host);
330
331
/**
332
* Set the syslog server port
333
* @param port port number
334
*/
335
public void setPort(int port);
336
337
/**
338
* Set the syslog facility
339
* @param facility the syslog facility
340
*/
341
public void setFacility(Facility facility);
342
343
/**
344
* Set the stack trace prefix
345
* @param stackTracePrefix prefix for stack trace lines
346
*/
347
public void setStackTracePrefix(String stackTracePrefix);
348
349
/**
350
* Include stack traces in syslog messages
351
* @param includeStackTrace true to include stack traces
352
*/
353
public void setIncludeStackTrace(boolean includeStackTrace);
354
355
/**
356
* Syslog facility options
357
*/
358
public enum Facility {
359
KERN, USER, MAIL, DAEMON, AUTH, SYSLOG, LPR, NEWS, UUCP, CRON,
360
AUTHPRIV, FTP, LOCAL0, LOCAL1, LOCAL2, LOCAL3, LOCAL4, LOCAL5, LOCAL6, LOCAL7
361
}
362
}
363
```
364
365
### TcpSocketAppenderFactory
366
367
Factory for TCP socket appenders enabling log forwarding over TCP connections.
368
369
```java { .api }
370
/**
371
* Factory for TCP socket appenders
372
*/
373
@JsonTypeName("tcp")
374
public class TcpSocketAppenderFactory<E> extends AbstractAppenderFactory<E> {
375
private String host = "localhost";
376
private int port = 4560;
377
private Duration connectionTimeout = Duration.milliseconds(500);
378
private boolean immediateFlush = true;
379
private DataSize sendBufferSize = DataSize.kibibytes(8);
380
381
/**
382
* Set the target host
383
* @param host hostname or IP address
384
*/
385
public void setHost(String host);
386
387
/**
388
* Set the target port
389
* @param port port number
390
*/
391
public void setPort(int port);
392
393
/**
394
* Set the connection timeout
395
* @param connectionTimeout timeout for connections
396
*/
397
public void setConnectionTimeout(Duration connectionTimeout);
398
399
/**
400
* Set immediate flush behavior
401
* @param immediateFlush true to flush immediately
402
*/
403
public void setImmediateFlush(boolean immediateFlush);
404
405
/**
406
* Set the send buffer size
407
* @param sendBufferSize buffer size for TCP sends
408
*/
409
public void setSendBufferSize(DataSize sendBufferSize);
410
411
/**
412
* Get socket factory for connection creation (extensible)
413
* @return socket factory instance
414
*/
415
protected SocketFactory socketFactory();
416
}
417
```
418
419
### UdpSocketAppenderFactory
420
421
Factory for UDP socket appenders enabling log forwarding over UDP datagrams.
422
423
```java { .api }
424
/**
425
* Factory for UDP socket appenders
426
*/
427
@JsonTypeName("udp")
428
public class UdpSocketAppenderFactory<E> extends AbstractAppenderFactory<E> {
429
private String host = "localhost";
430
private int port = 514;
431
432
/**
433
* Set the target host
434
* @param host hostname or IP address
435
*/
436
public void setHost(String host);
437
438
/**
439
* Set the target port
440
* @param port port number
441
*/
442
public void setPort(int port);
443
}
444
```
445
446
### TlsSocketAppenderFactory
447
448
Factory for TLS-encrypted socket appenders with comprehensive SSL/TLS configuration options.
449
450
```java { .api }
451
/**
452
* Factory for TLS-encrypted socket appenders
453
*/
454
@JsonTypeName("tls")
455
public class TlsSocketAppenderFactory<E> extends TcpSocketAppenderFactory<E> {
456
// Keystore configuration
457
private String keyStorePath;
458
private String keyStorePassword;
459
private String keyStoreType;
460
private String keyStoreProvider;
461
462
// Truststore configuration
463
private String trustStorePath;
464
private String trustStorePassword;
465
private String trustStoreType;
466
private String trustStoreProvider;
467
468
// Security settings
469
private String jceProvider;
470
private boolean validateCerts = false;
471
private boolean validatePeers = false;
472
473
// Protocol and cipher configuration
474
private List<String> supportedProtocols;
475
private List<String> excludedProtocols;
476
private List<String> supportedCipherSuites;
477
private List<String> excludedCipherSuites;
478
479
/**
480
* Set the keystore path
481
* @param keyStorePath path to keystore file
482
*/
483
public void setKeyStorePath(String keyStorePath);
484
485
/**
486
* Set the keystore password
487
* @param keyStorePassword keystore password
488
*/
489
public void setKeyStorePassword(String keyStorePassword);
490
491
/**
492
* Set the truststore path
493
* @param trustStorePath path to truststore file
494
*/
495
public void setTrustStorePath(String trustStorePath);
496
497
/**
498
* Set certificate validation
499
* @param validateCerts true to validate certificates
500
*/
501
public void setValidateCerts(boolean validateCerts);
502
503
/**
504
* Set peer validation
505
* @param validatePeers true to validate peers
506
*/
507
public void setValidatePeers(boolean validatePeers);
508
509
/**
510
* Set supported TLS protocols
511
* @param supportedProtocols list of protocol names
512
*/
513
public void setSupportedProtocols(List<String> supportedProtocols);
514
515
/**
516
* Set excluded TLS protocols
517
* @param excludedProtocols list of protocol names to exclude
518
*/
519
public void setExcludedProtocols(List<String> excludedProtocols);
520
521
// Additional getters and setters for all TLS configuration properties
522
}
523
```
524
525
**Usage Example:**
526
527
```java
528
TlsSocketAppenderFactory<ILoggingEvent> tlsAppender = new TlsSocketAppenderFactory<>();
529
tlsAppender.setHost("secure-log-server.example.com");
530
tlsAppender.setPort(6514);
531
tlsAppender.setKeyStorePath("/etc/ssl/keystore.jks");
532
tlsAppender.setKeyStorePassword("keystorepass");
533
tlsAppender.setTrustStorePath("/etc/ssl/truststore.jks");
534
tlsAppender.setValidateCerts(true);
535
tlsAppender.setSupportedProtocols(Arrays.asList("TLSv1.2", "TLSv1.3"));
536
```