Skip to content

Commit

Permalink
LunaChat v2.3.1 : Fixed issue #40.
Browse files Browse the repository at this point in the history
  • Loading branch information
ucchyocean committed Jul 27, 2013
1 parent 5a806f9 commit 6e4e4ef
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions src/main/java/com/github/ucchyocean/lc/LunaChatLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import java.text.SimpleDateFormat;
import java.util.Date;

import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitRunnable;

/**
* LunaChatロガー
* @author ucchy
Expand Down Expand Up @@ -39,27 +42,35 @@ public LunaChatLogger(String name) {
* ログを出力する
* @param message ログ内容
*/
public void log(String message) {
public void log(final String message) {

checkDir();

FileWriter writer = null;
try {
writer = new FileWriter(file, true);
String str = lformat.format(new Date()) + "," + message;
writer.write(str + "\r\n");
writer.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
if ( writer != null ) {
// 以降の処理を、発言処理の負荷軽減のため、非同期実行にする。(see issue #40.)
Bukkit.getScheduler().runTaskAsynchronously(LunaChat.instance, new BukkitRunnable() {
@Override
public void run() {

FileWriter writer = null;
try {
writer.close();
writer = new FileWriter(file, true);
String str = lformat.format(new Date()) + "," + message;
writer.write(str + "\r\n");
writer.flush();
} catch (Exception e) {
// do nothing.
e.printStackTrace();
} finally {
if ( writer != null ) {
try {
writer.close();
} catch (Exception e) {
// do nothing.
}
}
}

}
}
});
}

/**
Expand Down

0 comments on commit 6e4e4ef

Please sign in to comment.