forked from infinilabs/analysis-ik
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:medcl/elasticsearch-analysis-ik
- Loading branch information
Showing
6 changed files
with
109 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/org/wltea/analyzer/help/ESPluginLoggerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.wltea.analyzer.help; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.logging.log4j.spi.ExtendedLogger; | ||
|
||
public class ESPluginLoggerFactory { | ||
|
||
private ESPluginLoggerFactory() { | ||
} | ||
|
||
static public Logger getLogger(String name) { | ||
return getLogger("", LogManager.getLogger(name)); | ||
} | ||
|
||
static public Logger getLogger(String prefix, String name) { | ||
return getLogger(prefix, LogManager.getLogger(name)); | ||
} | ||
|
||
static public Logger getLogger(String prefix, Class<?> clazz) { | ||
return getLogger(prefix, LogManager.getLogger(clazz.getName())); | ||
} | ||
|
||
static public Logger getLogger(String prefix, Logger logger) { | ||
return (Logger)(prefix != null && prefix.length() != 0 ? new PrefixPluginLogger((ExtendedLogger)logger, logger.getName(), prefix) : logger); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/org/wltea/analyzer/help/PrefixPluginLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.wltea.analyzer.help; | ||
|
||
import org.apache.logging.log4j.Level; | ||
import org.apache.logging.log4j.Marker; | ||
import org.apache.logging.log4j.MarkerManager; | ||
import org.apache.logging.log4j.message.Message; | ||
import org.apache.logging.log4j.message.MessageFactory; | ||
import org.apache.logging.log4j.spi.ExtendedLogger; | ||
import org.apache.logging.log4j.spi.ExtendedLoggerWrapper; | ||
|
||
import java.util.WeakHashMap; | ||
|
||
public class PrefixPluginLogger extends ExtendedLoggerWrapper { | ||
private static final WeakHashMap<String, Marker> markers = new WeakHashMap(); | ||
private final Marker marker; | ||
|
||
static int markersSize() { | ||
return markers.size(); | ||
} | ||
|
||
public String prefix() { | ||
return this.marker.getName(); | ||
} | ||
|
||
PrefixPluginLogger(ExtendedLogger logger, String name, String prefix) { | ||
super(logger, name, (MessageFactory) null); | ||
String actualPrefix = prefix == null ? "" : prefix; | ||
WeakHashMap var6 = markers; | ||
MarkerManager.Log4jMarker actualMarker; | ||
synchronized (markers) { | ||
MarkerManager.Log4jMarker maybeMarker = (MarkerManager.Log4jMarker) markers.get(actualPrefix); | ||
if (maybeMarker == null) { | ||
actualMarker = new MarkerManager.Log4jMarker(actualPrefix); | ||
markers.put(new String(actualPrefix), actualMarker); | ||
} else { | ||
actualMarker = maybeMarker; | ||
} | ||
} | ||
|
||
this.marker = (Marker) actualMarker; | ||
} | ||
|
||
public void logMessage(String fqcn, Level level, Marker marker, Message message, Throwable t) { | ||
assert marker == null; | ||
|
||
super.logMessage(fqcn, level, this.marker, message, t); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,38 @@ | ||
package org.wltea.analyzer.help; | ||
|
||
import org.apache.logging.log4j.Logger; | ||
import org.elasticsearch.common.logging.ESLoggerFactory; | ||
|
||
public class Sleep { | ||
|
||
private static final Logger logger = ESLoggerFactory.getLogger(Sleep.class.getName()); | ||
|
||
public enum Type{MSEC,SEC,MIN,HOUR}; | ||
public static void sleep(Type type,int num){ | ||
try { | ||
switch(type){ | ||
case MSEC: | ||
Thread.sleep(num); | ||
return; | ||
case SEC: | ||
Thread.sleep(num*1000); | ||
return; | ||
case MIN: | ||
Thread.sleep(num*60*1000); | ||
return; | ||
case HOUR: | ||
Thread.sleep(num*60*60*1000); | ||
return; | ||
default: | ||
System.err.println("输入类型错误,应为MSEC,SEC,MIN,HOUR之一"); | ||
return; | ||
} | ||
} catch (InterruptedException e) { | ||
logger.error(e.getMessage(), e); | ||
} | ||
} | ||
private static final Logger logger = ESPluginLoggerFactory.getLogger(Sleep.class.getName()); | ||
|
||
public enum Type {MSEC, SEC, MIN, HOUR} | ||
|
||
; | ||
|
||
public static void sleep(Type type, int num) { | ||
try { | ||
switch (type) { | ||
case MSEC: | ||
Thread.sleep(num); | ||
return; | ||
case SEC: | ||
Thread.sleep(num * 1000); | ||
return; | ||
case MIN: | ||
Thread.sleep(num * 60 * 1000); | ||
return; | ||
case HOUR: | ||
Thread.sleep(num * 60 * 60 * 1000); | ||
return; | ||
default: | ||
System.err.println("输入类型错误,应为MSEC,SEC,MIN,HOUR之一"); | ||
return; | ||
} | ||
} catch (InterruptedException e) { | ||
logger.error(e.getMessage(), e); | ||
} | ||
} | ||
|
||
|
||
} |