Skip to content

Commit f0dd522

Browse files
committed
Merge branch 'master' of github.com:medcl/elasticsearch-analysis-ik
2 parents 9eaa2b9 + 9495315 commit f0dd522

File tree

6 files changed

+109
-32
lines changed

6 files changed

+109
-32
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<inceptionYear>2011</inceptionYear>
1313

1414
<properties>
15-
<elasticsearch.version>6.3.0</elasticsearch.version>
15+
<elasticsearch.version>6.5.0</elasticsearch.version>
1616
<maven.compiler.target>1.8</maven.compiler.target>
1717
<elasticsearch.assembly.descriptor>${project.basedir}/src/main/assemblies/plugin.xml</elasticsearch.assembly.descriptor>
1818
<elasticsearch.plugin.name>analysis-ik</elasticsearch.plugin.name>

src/main/java/org/wltea/analyzer/dic/Dictionary.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@
5353
import org.apache.http.impl.client.HttpClients;
5454
import org.elasticsearch.SpecialPermission;
5555
import org.elasticsearch.common.io.PathUtils;
56-
import org.elasticsearch.common.logging.ESLoggerFactory;
5756
import org.elasticsearch.plugin.analysis.ik.AnalysisIkPlugin;
5857
import org.wltea.analyzer.cfg.Configuration;
5958
import org.apache.logging.log4j.Logger;
59+
import org.wltea.analyzer.help.ESPluginLoggerFactory;
6060

6161

6262
/**
@@ -80,7 +80,7 @@ public class Dictionary {
8080
*/
8181
private Configuration configuration;
8282

83-
private static final Logger logger = ESLoggerFactory.getLogger(Monitor.class.getName());
83+
private static final Logger logger = ESPluginLoggerFactory.getLogger(Monitor.class.getName());
8484

8585
private static ScheduledExecutorService pool = Executors.newScheduledThreadPool(1);
8686

src/main/java/org/wltea/analyzer/dic/Monitor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
import org.apache.http.impl.client.HttpClients;
1212
import org.apache.logging.log4j.Logger;
1313
import org.elasticsearch.SpecialPermission;
14-
import org.elasticsearch.common.logging.ESLoggerFactory;
14+
import org.wltea.analyzer.help.ESPluginLoggerFactory;
1515

1616
public class Monitor implements Runnable {
1717

18-
private static final Logger logger = ESLoggerFactory.getLogger(Monitor.class.getName());
18+
private static final Logger logger = ESPluginLoggerFactory.getLogger(Monitor.class.getName());
1919

2020
private static CloseableHttpClient httpclient = HttpClients.createDefault();
2121
/*
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.wltea.analyzer.help;
2+
3+
import org.apache.logging.log4j.LogManager;
4+
import org.apache.logging.log4j.Logger;
5+
import org.apache.logging.log4j.spi.ExtendedLogger;
6+
7+
public class ESPluginLoggerFactory {
8+
9+
private ESPluginLoggerFactory() {
10+
}
11+
12+
static public Logger getLogger(String name) {
13+
return getLogger("", LogManager.getLogger(name));
14+
}
15+
16+
static public Logger getLogger(String prefix, String name) {
17+
return getLogger(prefix, LogManager.getLogger(name));
18+
}
19+
20+
static public Logger getLogger(String prefix, Class<?> clazz) {
21+
return getLogger(prefix, LogManager.getLogger(clazz.getName()));
22+
}
23+
24+
static public Logger getLogger(String prefix, Logger logger) {
25+
return (Logger)(prefix != null && prefix.length() != 0 ? new PrefixPluginLogger((ExtendedLogger)logger, logger.getName(), prefix) : logger);
26+
}
27+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package org.wltea.analyzer.help;
2+
3+
import org.apache.logging.log4j.Level;
4+
import org.apache.logging.log4j.Marker;
5+
import org.apache.logging.log4j.MarkerManager;
6+
import org.apache.logging.log4j.message.Message;
7+
import org.apache.logging.log4j.message.MessageFactory;
8+
import org.apache.logging.log4j.spi.ExtendedLogger;
9+
import org.apache.logging.log4j.spi.ExtendedLoggerWrapper;
10+
11+
import java.util.WeakHashMap;
12+
13+
public class PrefixPluginLogger extends ExtendedLoggerWrapper {
14+
private static final WeakHashMap<String, Marker> markers = new WeakHashMap();
15+
private final Marker marker;
16+
17+
static int markersSize() {
18+
return markers.size();
19+
}
20+
21+
public String prefix() {
22+
return this.marker.getName();
23+
}
24+
25+
PrefixPluginLogger(ExtendedLogger logger, String name, String prefix) {
26+
super(logger, name, (MessageFactory) null);
27+
String actualPrefix = prefix == null ? "" : prefix;
28+
WeakHashMap var6 = markers;
29+
MarkerManager.Log4jMarker actualMarker;
30+
synchronized (markers) {
31+
MarkerManager.Log4jMarker maybeMarker = (MarkerManager.Log4jMarker) markers.get(actualPrefix);
32+
if (maybeMarker == null) {
33+
actualMarker = new MarkerManager.Log4jMarker(actualPrefix);
34+
markers.put(new String(actualPrefix), actualMarker);
35+
} else {
36+
actualMarker = maybeMarker;
37+
}
38+
}
39+
40+
this.marker = (Marker) actualMarker;
41+
}
42+
43+
public void logMessage(String fqcn, Level level, Marker marker, Message message, Throwable t) {
44+
assert marker == null;
45+
46+
super.logMessage(fqcn, level, this.marker, message, t);
47+
}
48+
}
Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
11
package org.wltea.analyzer.help;
22

33
import org.apache.logging.log4j.Logger;
4-
import org.elasticsearch.common.logging.ESLoggerFactory;
54

65
public class Sleep {
76

8-
private static final Logger logger = ESLoggerFactory.getLogger(Sleep.class.getName());
9-
10-
public enum Type{MSEC,SEC,MIN,HOUR};
11-
public static void sleep(Type type,int num){
12-
try {
13-
switch(type){
14-
case MSEC:
15-
Thread.sleep(num);
16-
return;
17-
case SEC:
18-
Thread.sleep(num*1000);
19-
return;
20-
case MIN:
21-
Thread.sleep(num*60*1000);
22-
return;
23-
case HOUR:
24-
Thread.sleep(num*60*60*1000);
25-
return;
26-
default:
27-
System.err.println("输入类型错误,应为MSEC,SEC,MIN,HOUR之一");
28-
return;
29-
}
30-
} catch (InterruptedException e) {
31-
logger.error(e.getMessage(), e);
32-
}
33-
}
7+
private static final Logger logger = ESPluginLoggerFactory.getLogger(Sleep.class.getName());
8+
9+
public enum Type {MSEC, SEC, MIN, HOUR}
10+
11+
;
12+
13+
public static void sleep(Type type, int num) {
14+
try {
15+
switch (type) {
16+
case MSEC:
17+
Thread.sleep(num);
18+
return;
19+
case SEC:
20+
Thread.sleep(num * 1000);
21+
return;
22+
case MIN:
23+
Thread.sleep(num * 60 * 1000);
24+
return;
25+
case HOUR:
26+
Thread.sleep(num * 60 * 60 * 1000);
27+
return;
28+
default:
29+
System.err.println("输入类型错误,应为MSEC,SEC,MIN,HOUR之一");
30+
return;
31+
}
32+
} catch (InterruptedException e) {
33+
logger.error(e.getMessage(), e);
34+
}
35+
}
3436

3537

3638
}

0 commit comments

Comments
 (0)