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

39 lines
945 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.File;
2011-05-29 13:25:25 +02:00
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 {
private static final List<String> queue = new LinkedList<String>();
private static final String filePath = new File(ChestShop.folder, "ChestShop.log").getPath();
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!");
}
}
}