ChestShop-3/com/Acrobot/ChestShop/Logging/FileWriterQueue.java

38 lines
893 B
Java
Raw Normal View History

2011-05-29 13:25:25 +02:00
package com.Acrobot.ChestShop.Logging;
2011-06-09 22:54:01 +02:00
import com.Acrobot.ChestShop.ChestShop;
2011-05-29 13:25:25 +02:00
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.LinkedList;
import java.util.List;
/**
* @author Acrobot
*/
2011-06-09 22:54:01 +02:00
public class FileWriterQueue implements Runnable {
2011-05-29 13:25:25 +02:00
private static List<String> queue = new LinkedList<String>();
2011-06-09 22:54:01 +02:00
public static String filePath = ChestShop.folder + "/ChestShop.log";
2011-05-29 13:25:25 +02:00
2011-06-09 22:54:01 +02:00
public static void addToQueue(String message) {
2011-05-29 13:25:25 +02:00
queue.add(message);
}
public void run() {
2011-06-09 22:54:01 +02:00
try {
2011-05-29 13:25:25 +02:00
BufferedWriter bw = new BufferedWriter(new FileWriter(filePath, true));
2011-06-09 22:54:01 +02:00
for (String msg : queue) {
2011-05-29 13:25:25 +02:00
bw.write(msg);
bw.newLine();
}
bw.close();
2011-06-09 22:54:01 +02:00
queue.clear();
} catch (Exception e) {
2011-05-29 13:25:25 +02:00
Logging.log("Couldn't write to log file!");
}
}
}