0
# JULI Logging
1
2
Tomcat's Java Util Logging Implementation providing per-classloader log isolation, configurable handlers and formatters, bridge to java.util.logging API, and support for file rotation and console output. Enables independent logging configuration for each web application.
3
4
## Capabilities
5
6
### Log Interface
7
8
Commons-logging compatible logging interface.
9
10
```java { .api }
11
public interface Log {
12
// Log level checks
13
boolean isDebugEnabled();
14
boolean isErrorEnabled();
15
boolean isFatalEnabled();
16
boolean isInfoEnabled();
17
boolean isTraceEnabled();
18
boolean isWarnEnabled();
19
20
// Trace
21
void trace(Object message);
22
void trace(Object message, Throwable t);
23
24
// Debug
25
void debug(Object message);
26
void debug(Object message, Throwable t);
27
28
// Info
29
void info(Object message);
30
void info(Object message, Throwable t);
31
32
// Warn
33
void warn(Object message);
34
void warn(Object message, Throwable t);
35
36
// Error
37
void error(Object message);
38
void error(Object message, Throwable t);
39
40
// Fatal
41
void fatal(Object message);
42
void fatal(Object message, Throwable t);
43
}
44
```
45
46
### LogFactory
47
48
Factory for obtaining Log instances.
49
50
```java { .api }
51
public class LogFactory {
52
// Static methods - obtain log instances
53
public static Log getLog(Class<?> clazz);
54
public static Log getLog(String name);
55
56
// Static methods - factory management
57
public static LogFactory getFactory() throws LogConfigurationException;
58
public static void release(ClassLoader classLoader);
59
60
// Instance methods - obtain log instances
61
public Log getInstance(String name) throws LogConfigurationException;
62
public Log getInstance(Class<?> clazz) throws LogConfigurationException;
63
}
64
```
65
66
### ClassLoaderLogManager
67
68
LogManager implementation providing per-classloader log isolation for web applications.
69
70
```java { .api }
71
public class ClassLoaderLogManager extends LogManager {
72
public ClassLoaderLogManager();
73
74
// Override LogManager methods for per-classloader isolation
75
public Logger getLogger(String name);
76
public Enumeration<String> getLoggerNames();
77
public boolean addLogger(Logger logger);
78
79
// Property reading from per-classloader sources
80
public String getProperty(String name);
81
public void readConfiguration() throws IOException;
82
public void readConfiguration(InputStream ins) throws IOException;
83
84
// Classloader management
85
public synchronized void setUseShutdownHook(boolean useShutdownHook);
86
public boolean isUseShutdownHook();
87
}
88
```
89
90
### FileHandler
91
92
Log handler that writes log messages to a file with rotation support.
93
94
```java { .api }
95
public class FileHandler extends Handler {
96
// Constructors
97
public FileHandler();
98
public FileHandler(String directory, String prefix, String suffix);
99
public FileHandler(String directory, String prefix, String suffix, Integer maxDays);
100
public FileHandler(String directory, String prefix, String suffix, Integer maxDays, Boolean rotatable, Integer bufferSize);
101
102
// Handler methods
103
public void publish(LogRecord record);
104
public void close();
105
public void flush();
106
107
// Configuration
108
public void setDirectory(String directory);
109
public String getDirectory();
110
public void setPrefix(String prefix);
111
public String getPrefix();
112
public void setSuffix(String suffix);
113
public String getSuffix();
114
public void setRotatable(boolean rotatable);
115
public boolean isRotatable();
116
public void setBuffered(boolean buffered);
117
118
// Rotation
119
protected void open();
120
protected void rotate();
121
}
122
```
123
124
### AsyncFileHandler
125
126
Asynchronous file handler that writes log messages in a separate thread for improved performance.
127
128
```java { .api }
129
public class AsyncFileHandler extends FileHandler {
130
public AsyncFileHandler();
131
public AsyncFileHandler(String directory, String prefix, String suffix);
132
public AsyncFileHandler(String directory, String prefix, String suffix, Integer maxDays);
133
134
// Asynchronous publishing
135
public void publish(LogRecord record);
136
public void close();
137
}
138
```
139
140
### OneLineFormatter
141
142
Formatter that outputs log records as a single line.
143
144
```java { .api }
145
public class OneLineFormatter extends Formatter {
146
public OneLineFormatter();
147
148
public String format(LogRecord record);
149
150
// Configuration
151
public void setTimeFormat(String format);
152
public String getTimeFormat();
153
}
154
```
155
156
### VerbatimFormatter
157
158
Formatter that outputs only the log message without any additional formatting.
159
160
```java { .api }
161
public class VerbatimFormatter extends Formatter {
162
public VerbatimFormatter();
163
164
public String format(LogRecord record);
165
}
166
```
167
168
### JsonFormatter
169
170
Formatter that outputs log records in JSON format for structured logging.
171
172
```java { .api }
173
public class JsonFormatter extends Formatter {
174
public JsonFormatter();
175
176
public String format(LogRecord record);
177
}
178
```
179
180
### JdkLoggerFormatter
181
182
Formatter compatible with JDK logger output format.
183
184
```java { .api }
185
public class JdkLoggerFormatter extends Formatter {
186
public JdkLoggerFormatter();
187
188
public String format(LogRecord record);
189
}
190
```
191
192
### LogConfigurationException
193
194
Exception thrown when log configuration fails.
195
196
```java { .api }
197
public class LogConfigurationException extends RuntimeException {
198
public LogConfigurationException();
199
public LogConfigurationException(String message);
200
public LogConfigurationException(Throwable cause);
201
public LogConfigurationException(String message, Throwable cause);
202
}
203
```
204
205
### DateFormatCache
206
207
Thread-safe date format cache for improved logging performance.
208
209
```java { .api }
210
public class DateFormatCache {
211
public DateFormatCache(int size, String format, DateFormatCache parent);
212
213
public String getFormat(long time);
214
public String getTimeFormat();
215
}
216
```
217
218
## Usage Examples
219
220
### Basic Logging
221
222
```java
223
import org.apache.juli.logging.Log;
224
import org.apache.juli.logging.LogFactory;
225
226
public class LoggingExample {
227
private static final Log log = LogFactory.getLog(LoggingExample.class);
228
229
public void doSomething() {
230
log.info("Starting operation");
231
232
try {
233
// Perform operation
234
if (log.isDebugEnabled()) {
235
log.debug("Operation details...");
236
}
237
log.info("Operation completed successfully");
238
} catch (Exception e) {
239
log.error("Operation failed", e);
240
}
241
}
242
}
243
```
244