Skip to content

Commit

Permalink
format log
Browse files Browse the repository at this point in the history
  • Loading branch information
qicz committed Jul 13, 2021
1 parent 2d6a813 commit 7717197
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public Configuration(Environment env, Settings settings) {
Asserts.check(Objects.nonNull(settingEtymology), message);
// 领域
String domain = settings.get("domain", "default-domain");
logger.info("new configuration for domain {} etymology {}", domain, etymology);
logger.info("new configuration for domain '{}' etymology '{}'", domain, etymology);
// 配置初始化
Configuration.initial(env);
// 构造词源及领域
Expand Down
24 changes: 11 additions & 13 deletions src/main/java/org/wltea/analyzer/dictionary/Dictionary.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private void initial(boolean enableRemoteDict) {
this.loadStopWordDict();

if (enableRemoteDict) {
logger.info("Remote Dictionary enabled!");
logger.info("Remote Dictionary enabled for '{}'!", this.domainUri);
ConfigurationProperties properties = Configuration.getProperties();
ConfigurationProperties.Remote.Refresh remoteRefresh = properties.getRemoteRefresh();
// 建立监控线程 - 主词库
Expand Down Expand Up @@ -121,7 +121,7 @@ public Hit matchInMainDict(char[] charArray) {
* @return Hit 匹配结果描述
*/
public Hit matchInMainDict(char[] charArray, int begin, int length) {
logger.info("matchInMainDict for {}", this.domainUri);
logger.info("matchInMainDict for '{}'", this.domainUri);
return this.mainDictionary.match(charArray, begin, length);
}

Expand All @@ -131,7 +131,7 @@ public Hit matchInMainDict(char[] charArray, int begin, int length) {
* @return Hit 匹配结果描述
*/
public Hit matchInQuantifierDict(char[] charArray, int begin, int length) {
logger.info("matchInQuantifierDict for {}", this.domainUri);
logger.info("matchInQuantifierDict for '{}'", this.domainUri);
return this.quantifierDictionary.match(charArray, begin, length);
}

Expand All @@ -141,7 +141,7 @@ public Hit matchInQuantifierDict(char[] charArray, int begin, int length) {
* @return boolean
*/
public boolean isStopWord(char[] charArray, int begin, int length) {
logger.info("isStopWord for {}", this.domainUri);
logger.info("isStopWord for '{}'", this.domainUri);
return this.stopWordsDictionary.match(charArray, begin, length).isMatch();
}

Expand All @@ -157,7 +157,7 @@ private void loadMainDict() {
this.mainDictionary.fillSegment(file, "Main DictFile");
// 加载扩展词典
List<String> mainExtDictFiles = Configuration.getProperties().getMainExtDictFiles();
this.loadLocalExtDict(this.mainDictionary, DictionaryType.MAIN_WORDS, mainExtDictFiles, "Main Extra DictFile");
this.loadLocalExtDict(this.mainDictionary, mainExtDictFiles, "Main Extra DictFile");

// 加载远程自定义词库
this.loadRemoteExtDict(this.mainDictionary, DictionaryType.MAIN_WORDS);
Expand Down Expand Up @@ -186,14 +186,13 @@ private void loadStopWordDict() {

// 加载扩展停止词典
List<String> extStopDictFiles = Configuration.getProperties().getExtStopDictFiles();
this.loadLocalExtDict(this.stopWordsDictionary, DictionaryType.STOP_WORDS, extStopDictFiles, "Extra Stopwords");
this.loadLocalExtDict(this.stopWordsDictionary, extStopDictFiles, "Extra Stopwords");

// 加载远程停用词典
this.loadRemoteExtDict(this.stopWordsDictionary, DictionaryType.STOP_WORDS);
}

private void loadLocalExtDict(DictSegment dictSegment,
DictionaryType dictionaryType,
List<String> extDictFiles,
String name) {
// 加载扩展词典配置
Expand All @@ -208,17 +207,16 @@ private void loadLocalExtDict(DictSegment dictSegment,

private void loadRemoteExtDict(DictSegment dictSegment,
DictionaryType dictionaryType) {
logger.info("[Remote DictFile Loading] for domain {}", this.domainUri);
logger.info("[Remote DictFile Loading] for domain '{}'", this.domainUri);
Set<String> remoteWords = DictionaryHelper.getRemoteWords(this, dictionaryType, this.domainUri);
//this.addWords(remoteWords, dictionaryType, true);
// 如果找不到扩展的字典,则忽略
if (remoteWords.isEmpty()) {
logger.info("[Remote DictFile Loading] no new words for {}", this.domainUri);
logger.info("[Remote DictFile Loading] no new words for '{}'", this.domainUri);
return;
}
remoteWords.forEach(word -> {
// 加载远程词典数据到主内存中
logger.info("[New {} Word] {}", dictionaryType.dictName, word);
logger.info("[New '{}' Word] '{}'", dictionaryType.dictName, word);
dictSegment.fillSegment(word.toLowerCase().toCharArray());
});
}
Expand All @@ -227,7 +225,7 @@ private void loadRemoteExtDict(DictSegment dictSegment,
* 重新加载词典
*/
public synchronized void reload(DictionaryType dictionaryType) {
logger.info("[Begin to reload] ik {} dictionary.", dictionaryType);
logger.info("[Begin to reload] ik '{}' dictionary.", dictionaryType);
// 新开一个实例加载词典,减少加载过程对当前词典使用的影响
Dictionary tmpDict = new Dictionary(enableRemoteDict, domainUri);
switch (dictionaryType) {
Expand All @@ -248,6 +246,6 @@ public synchronized void reload(DictionaryType dictionaryType) {
this.stopWordsDictionary = tmpDict.stopWordsDictionary;
}
}
logger.info("Reload ik {} dictionary finished.", dictionaryType);
logger.info("Reload ik '{}' dictionary finished.", dictionaryType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class HttpRemoteDictionary extends AbstractRemoteDictionary {
public Set<String> getRemoteWords(org.wltea.analyzer.dictionary.Dictionary dictionary,
DictionaryType dictionaryType,
URI domainUri) {
logger.info("[Remote DictFile Loading] For etymology 'http' and domain {}", domainUri);
logger.info("[Remote DictFile Loading] For etymology 'http' and domain '{}'", domainUri);
Set<String> words = new HashSet<>();
CloseableHttpResponse response;
BufferedReader in;
Expand Down Expand Up @@ -84,7 +84,7 @@ public Set<String> getRemoteWords(org.wltea.analyzer.dictionary.Dictionary dicti
}
response.close();
} catch (IllegalStateException | IOException e) {
logger.error("getRemoteWords error {} location {}", e, location);
logger.error("getRemoteWords error '{}' location '{}'", e, location);
}
return words;
}
Expand All @@ -100,7 +100,7 @@ public Set<String> getRemoteWords(org.wltea.analyzer.dictionary.Dictionary dicti
public void reloadRemoteDictionary(Dictionary dictionary,
DictionaryType dictionaryType,
URI domainUri) {
logger.info("[Remote DictFile Reloading] For etymology 'http' and domain {}", domainUri);
logger.info("[Remote DictFile Reloading] For etymology 'http' and domain '{}'", domainUri);
String location = this.getLocation(dictionaryType, domainUri);
HttpHead head = new HttpHead(location);
head.setConfig(REQUEST_CONFIG);
Expand Down Expand Up @@ -145,9 +145,9 @@ public void reloadRemoteDictionary(Dictionary dictionary,
}
return;
}
logger.info("remote_ext_dict {} return bad code {}", location, statusCode);
logger.info("remote_ext_dict '{}' return bad code '{}'", location, statusCode);
} catch (Exception e) {
logger.error("remote_ext_dict error {} location {} !", e, location);
logger.error("remote_ext_dict error '{}' location '{}' !", e, location);
} finally {
try {
if (response != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Set<String> getRemoteWords(org.wltea.analyzer.dictionary.Dictionary dicti
DictionaryType dictionaryType,
String etymology,
String domain) {
logger.info("[Remote DictFile Loading] For etymology 'mysql' and domain {}", domain);
logger.info("[Remote DictFile Loading] For etymology 'mysql' and domain '{}'", domain);
Set<String> words = new HashSet<>();
Connection connection = null;
PreparedStatement statement = null;
Expand Down Expand Up @@ -61,7 +61,7 @@ public Set<String> getRemoteWords(org.wltea.analyzer.dictionary.Dictionary dicti
public void reloadRemoteDictionary(Dictionary dictionary,
DictionaryType dictionaryType,
String domain) {
logger.info("[Remote DictFile Reloading] For etymology 'mysql' and domain {}", domain);
logger.info("[Remote DictFile Reloading] For etymology 'mysql' and domain '{}'", domain);
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
Expand All @@ -72,17 +72,17 @@ public void reloadRemoteDictionary(Dictionary dictionary,
statement.setString(1, domain);
resultSet = statement.executeQuery();
if (!resultSet.next()) {
logger.info("Cannot find the `ik_sequence` and dictionary {} data", domain);
logger.info("Cannot find the `ik_sequence` and dictionary '{}' data", domain);
return;
}
long maxId = resultSet.getLong("max_id");
long currentId = resultSet.getLong("current_id");
logger.info("[Remote DictFile] maxId {} currentId {}", maxId, currentId);
logger.info("[Remote DictFile] maxId '{}' currentId '{}'", maxId, currentId);
if (maxId != currentId) {
// 更新currentId
sql = String.format("current_id = %s WHERE domain = '%s'", maxId, domain);
sql = String.format("UPDATE ik_sequence SET %s", sql);
logger.info("sql {}", sql);
logger.info("sql '{}'", sql);
statement.execute(sql);
dictionary.reload(dictionaryType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class RedisRemoteDictionary extends AbstractRemoteDictionary {

private final StatefulRedisConnection<String, String> redisConnection;

private final String KEY_PREFIX = "es-ik-words";
private final static String KEY_PREFIX = "es-ik-words";

RedisRemoteDictionary() {
// lettuce 默认支持connection的重连
Expand All @@ -40,7 +40,7 @@ public Set<String> getRemoteWords(Dictionary dictionary,
DictionaryType dictionaryType,
String etymology,
String domain) {
logger.info("[Remote DictFile reloading] For etymology 'redis' domain {}", domain);
logger.info("[Remote DictFile reloading] For etymology 'redis' domain '{}'", domain);
RedisCommands<String, String> sync = this.redisConnection.sync();
String key = this.getKey(dictionaryType, domain);
List<String> words = sync.lrange(key, 0, -1);
Expand All @@ -51,13 +51,13 @@ public Set<String> getRemoteWords(Dictionary dictionary,
public void reloadRemoteDictionary(Dictionary dictionary,
DictionaryType dictionaryType,
String domain) {
logger.info("[Remote DictFile reloading] For etymology 'redis'");
logger.info("[Remote DictFile reloading] For etymology 'redis' and domain '{}'", domain);
RedisCommands<String, String> sync = this.redisConnection.sync();
// 当前 对应的 *-state key为true时,进行reload
String key = this.getKey(dictionaryType, domain);
String state = String.format("%s:state", key);
String currentState = sync.get(state);
logger.info("[Remote Dict File] state {} = {}", state, currentState);
logger.info("[Remote Dict File] state '{}' = '{}'", state, currentState);
if ("true".equals(currentState)) {
sync.set(state, "false");
dictionary.reload(dictionaryType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public final class RemoteDictionary {
private static void addRemoteDictionary(AbstractRemoteDictionary remoteDictionary) {
String etymology = remoteDictionary.etymology();
REMOTE_DICTIONARY.put(etymology, remoteDictionary);
logger.info("The Remote Dictionary For etymology {} is loaded!", etymology);
logger.info("The Remote Dictionary For etymology '{}' is loaded!", etymology);
}

public static void initial() {
Expand All @@ -35,7 +35,7 @@ public static void initial() {

public static AbstractRemoteDictionary getRemoteDictionary(URI uri) {
String etymology = uri.getScheme();
logger.info("Remote Dictionary etymology {}", etymology);
logger.info("Remote Dictionary etymology '{}'", etymology);
AbstractRemoteDictionary remoteDictionary = REMOTE_DICTIONARY.get(etymology);
if (Objects.isNull(remoteDictionary)) {
logger.error("Load Remote Dictionary Error");
Expand Down

0 comments on commit 7717197

Please sign in to comment.