blob: 0d04b4cf981cba668cbbf0281b09e8d6441b5e1a (
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.logserver.handlers.archive;
import java.util.logging.Logger;
import com.yahoo.logserver.Server;
import com.yahoo.plugin.Config;
import com.yahoo.plugin.Plugin;
public class ArchiverPlugin implements Plugin
{
/**
* Default log archive dir (relative to current directory
* at startup).
*/
private static final String DEFAULT_DIR = "logarchive";
/**
* Default max file size for archived log files.
*/
private static final String DEFAULT_MAXFILESIZE = "20971520";
private final Server server = Server.getInstance();
private static final Logger log =
Logger.getLogger(ArchiverPlugin.class.getName());
private ArchiverHandler archiver;
/**
* @return the name of this plugin
*/
public String getPluginName() {
return "logarchive";
}
/** Initialize the archiver plugin
*
* Config keys used:
*
* maxfilesize
* dir The root of the logarchive, make sure this does
* <b>not</b> end with a '/' character.
*/
public void initPlugin(Config config) {
if (archiver != null) {
log.finer("ArchivePlugin doubly initialized");
throw new IllegalStateException("plugin already initialized: "
+ getPluginName());
}
// Possible to disable logarchive for testing
String rootDir = config.get("dir", DEFAULT_DIR);
int maxFileSize = config.getInt("maxfilesize", DEFAULT_MAXFILESIZE);
String threadName = config.get("thread", getPluginName());
// register log handler and flusher
archiver = new ArchiverHandler(rootDir, maxFileSize);
server.registerLogHandler(archiver, threadName);
server.registerFlusher(archiver);
}
/**
* Shut down the archiver plugin.
*/
public void shutdownPlugin() {
if (archiver == null) {
log.finer("ArchiverPlugin shutdown before initialize");
throw new IllegalStateException("plugin not initialized: "
+ getPluginName());
}
server.unregisterLogHandler(archiver);
server.unregisterFlusher(archiver);
archiver.close();
archiver = null;
}
}
|