blob: 488a6137cc2fa466ac1895c0529c256f4132875f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.logging;
import com.yahoo.container.core.AccessLogConfig;
import java.util.logging.Logger;
/**
* @author Bjorn Borud
*/
class AccessLogHandler {
public Logger access = Logger.getAnonymousLogger();
private LogFileHandler logFileHandler;
public AccessLogHandler(AccessLogConfig.FileHandler config) {
access.setUseParentHandlers(false);
logFileHandler = new LogFileHandler(config.compressOnRotation());
logFileHandler.setFilePattern(config.pattern());
logFileHandler.setRotationTimes(config.rotation());
createSymlink(config, logFileHandler);
LogFormatter lf = new LogFormatter();
lf.messageOnly(true);
this.logFileHandler.setFormatter(lf);
access.addHandler(this.logFileHandler);
}
private void createSymlink(AccessLogConfig.FileHandler config, LogFileHandler handler) {
if (!config.symlink().isEmpty())
handler.setSymlinkName(config.symlink());
}
public void shutdown() {
logFileHandler.close();
access.removeHandler(logFileHandler);
if (logFileHandler!=null)
logFileHandler.shutdown();
}
void rotateNow() {
logFileHandler.rotateNow();
}
}
|