Skip to content
This repository was archived by the owner on Jan 6, 2023. It is now read-only.

Commit 8e9956c

Browse files
committed
genericizing some params to prepare for later support of other destinations
1 parent c9d2414 commit 8e9956c

File tree

3 files changed

+61
-33
lines changed

3 files changed

+61
-33
lines changed

samples/weblogicLoggingExporter.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
# and gives a warning.
1717
weblogicLoggingIndexName: wls
1818

19-
# The host that Elastic Search is running on. Default to localhost
20-
ElasticSearchHost: localhost
19+
# The host that Elastic Search is running on. Defaults to localhost.
20+
publishHost: localhost
2121

22-
# The port that Elastic Search is listening to. Default to 9200
23-
ElasticSearchPort: 9200
22+
# The port that Elastic Search is listening to. Defaults to 9200.
23+
publishPort: 9200
2424

2525
# The "domainUID" used to uniquely identify this domain. This is used to filter logs in Kibana by the domain they came
2626
# from. You should use a unique value for each domain. If you are using the WebLogic Kubernetes Operator, it is

src/main/java/weblogic/logging/exporter/LogExportHandler.java

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,23 @@ class LogExportHandler extends Handler {
3333
private static final String INDEX = " { \"index\" : { }} ";
3434
private static final int offValue = Level.OFF.intValue();
3535

36-
private String indexName = Config.DEFAULT_INDEX_NAME;
37-
private String elasticSearchHost = Config.DEFAULT_ES_HOST;
38-
private int elasticSearchPort = Config.DEFAULT_ES_PORT;
39-
private int bulkSize = Config.DEFAULT_BULK_SIZE;
40-
41-
private String httpHostPort = "http://" + elasticSearchHost + ":" + elasticSearchPort;
42-
private String singleURL = httpHostPort + "/" + indexName + "/" + DOC_TYPE + "/?pretty";
43-
private String bulkURL = httpHostPort + "/" + indexName + "/" + DOC_TYPE + "/_bulk?pretty";
44-
4536
private final Client httpClient = ClientBuilder.newClient();
4637
private List<FilterConfig> filterConfigs = new ArrayList<>();
4738
private final List<String> payloadBulkList = new ArrayList<>();
4839

49-
private String domainUID = null;
40+
//
41+
// These will all be set by initialize()
42+
//
43+
private String indexName;
44+
private String publishHost;
45+
private int publishPort;
46+
private int bulkSize;
47+
private String httpHostPort;
48+
private String singleURL;
49+
private String bulkURL;
50+
private String fluentdURL;
51+
private String domainUID;
52+
private String destination;
5053

5154
public LogExportHandler(Config config) {
5255
initialize(config);
@@ -215,8 +218,8 @@ private String recordToPayload(WLLogRecord wlLogRecord) {
215218

216219
private void initialize(Config config) {
217220

218-
elasticSearchHost = config.getHost();
219-
elasticSearchPort = config.getPort();
221+
publishHost = config.getHost();
222+
publishPort = config.getPort();
220223
@SuppressWarnings("unused")
221224
boolean enabled = config.getEnabled();
222225
String severity = config.getSeverity();
@@ -226,10 +229,19 @@ private void initialize(Config config) {
226229
indexName = config.getIndexName();
227230
bulkSize = config.getBulkSize();
228231
filterConfigs = config.getFilterConfigs();
229-
httpHostPort = "http://" + elasticSearchHost + ":" + elasticSearchPort;
232+
httpHostPort = "http://" + publishHost + ":" + publishPort;
230233
singleURL = httpHostPort + "/" + indexName + "/" + DOC_TYPE + "/?pretty";
231234
bulkURL = httpHostPort + "/" + indexName + "/" + DOC_TYPE + "/_bulk?pretty";
232235
domainUID = config.getDomainUID();
236+
237+
//
238+
// Set up the publishing variables...
239+
//
240+
241+
httpHostPort = "http://" + publishHost + ":" + publishPort;
242+
singleURL = httpHostPort + "/" + indexName + "/" + DOC_TYPE + "/?pretty";
243+
bulkURL = httpHostPort + "/" + indexName + "/" + DOC_TYPE + "/_bulk?pretty";
244+
fluentdURL = httpHostPort + "/" + indexName;
233245
}
234246

235247
private void createMappings() {

src/main/java/weblogic/logging/exporter/config/Config.java

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@
1919

2020
public class Config {
2121

22-
public static final String DEFAULT_ES_HOST = "localhost";
23-
public static final int DEFAULT_ES_PORT = 9200;
22+
public static final String DEFAULT_HOST = "localhost";
23+
public static final int DEFAULT_PORT = 9200;
2424
public static final String DEFAULT_INDEX_NAME = "wls";
2525
public static final int DEFAULT_BULK_SIZE = 1;
2626
private static final String DEFAULT_DOMAIN_UID = "unknown";
2727

28-
private static final String HOST = "ElasticSearchHost";
29-
private static final String PORT = "ElasticSearchPort";
28+
private static final String HOST = "publishHost";
29+
private static final String PORT = "publishPort";
3030
private static final String FILTERS = "weblogicLoggingExporterFilters";
3131
private static final String ENABLED = "weblogicLoggingExporterEnabled";
3232
private static final String SEVERITY = "weblogicLoggingExporterSeverity";
3333
private static final String BULK_SIZE = "weblogicLoggingExporterBulkSize";
3434
private static final String INDEX_NAME = "weblogicLoggingIndexName";
3535
private static final String DOMAIN_UID = "domainUID";
3636

37-
private String host = DEFAULT_ES_HOST;
38-
private int port = DEFAULT_ES_PORT;
37+
private String host = DEFAULT_HOST;
38+
private int port = DEFAULT_PORT;
3939
private String indexName = DEFAULT_INDEX_NAME;
4040
private int bulkSize = DEFAULT_BULK_SIZE;
4141
private boolean enabled = true;
@@ -46,18 +46,34 @@ public class Config {
4646
private Config() {}
4747

4848
private Config(Map<String, Object> yaml) {
49-
if (yaml.containsKey(HOST)) host = MapUtils.getStringValue(yaml, HOST);
50-
if (yaml.containsKey(PORT)) port = MapUtils.getIntegerValue(yaml, PORT);
51-
if (yaml.containsKey(ENABLED)) enabled = MapUtils.getBooleanValue(yaml, ENABLED);
52-
if (yaml.containsKey(SEVERITY)) severity = MapUtils.getStringValue(yaml, SEVERITY);
53-
if (yaml.containsKey(BULK_SIZE)) bulkSize = MapUtils.getIntegerValue(yaml, BULK_SIZE);
54-
if (yaml.containsKey(INDEX_NAME)) indexName = MapUtils.getStringValue(yaml, INDEX_NAME);
55-
if (yaml.containsKey(DOMAIN_UID)) domainUID = MapUtils.getStringValue(yaml, DOMAIN_UID);
49+
if (yaml.containsKey(HOST)) {
50+
host = MapUtils.getStringValue(yaml, HOST);
51+
}
52+
if (yaml.containsKey(PORT)) {
53+
port = MapUtils.getIntegerValue(yaml, PORT);
54+
}
55+
if (yaml.containsKey(ENABLED)) {
56+
enabled = MapUtils.getBooleanValue(yaml, ENABLED);
57+
}
58+
if (yaml.containsKey(SEVERITY)) {
59+
severity = MapUtils.getStringValue(yaml, SEVERITY);
60+
}
61+
if (yaml.containsKey(BULK_SIZE)) {
62+
bulkSize = MapUtils.getIntegerValue(yaml, BULK_SIZE);
63+
}
64+
if (yaml.containsKey(INDEX_NAME)) {
65+
indexName = MapUtils.getStringValue(yaml, INDEX_NAME);
66+
}
67+
if (yaml.containsKey(DOMAIN_UID)) {
68+
domainUID = MapUtils.getStringValue(yaml, DOMAIN_UID);
69+
}
5670
if (bulkSize <= 1) {
5771
bulkSize = 1;
5872
}
5973
// index name needs to be all lowercase.
60-
if (yaml.containsKey(INDEX_NAME)) indexName = MapUtils.getStringValue(yaml, INDEX_NAME);
74+
if (yaml.containsKey(INDEX_NAME)) {
75+
indexName = MapUtils.getStringValue(yaml, INDEX_NAME);
76+
}
6177
if (!(indexName.toLowerCase().equals(indexName))) {
6278
indexName = indexName.toLowerCase();
6379
System.out.println("Index name is converted to all lower case : " + indexName);
@@ -136,10 +152,10 @@ public String toString() {
136152
+ "weblogicLoggingIndexName='"
137153
+ indexName
138154
+ '\''
139-
+ ", ElasticSearchHost='"
155+
+ ", publishHost='"
140156
+ host
141157
+ '\''
142-
+ ", ElasticSearchPort="
158+
+ ", publishPort="
143159
+ port
144160
+ ", weblogicLoggingExporterSeverity='"
145161
+ severity

0 commit comments

Comments
 (0)