|
@@ -47,6 +47,7 @@ import com.dmdirc.parser.interfaces.ClientInfo;
|
47
|
47
|
import com.dmdirc.parser.interfaces.Parser;
|
48
|
48
|
import com.dmdirc.plugins.Plugin;
|
49
|
49
|
import com.dmdirc.ui.messages.Styliser;
|
|
50
|
+import com.dmdirc.util.StreamUtil;
|
50
|
51
|
|
51
|
52
|
import java.awt.Color;
|
52
|
53
|
import java.io.BufferedWriter;
|
|
@@ -59,11 +60,11 @@ import java.security.MessageDigest;
|
59
|
60
|
import java.security.NoSuchAlgorithmException;
|
60
|
61
|
import java.text.DateFormat;
|
61
|
62
|
import java.text.SimpleDateFormat;
|
|
63
|
+import java.util.Collections;
|
62
|
64
|
import java.util.Date;
|
63
|
|
-import java.util.Hashtable;
|
|
65
|
+import java.util.HashMap;
|
64
|
66
|
import java.util.Map;
|
65
|
67
|
import java.util.Stack;
|
66
|
|
-
|
67
|
68
|
import java.util.Timer;
|
68
|
69
|
import java.util.TimerTask;
|
69
|
70
|
|
|
@@ -108,19 +109,13 @@ public class LoggingPlugin extends Plugin implements ActionListener,
|
108
|
109
|
/** Timer used to close idle files */
|
109
|
110
|
protected Timer idleFileTimer;
|
110
|
111
|
|
111
|
|
- /** Hashtable of open files. */
|
112
|
|
- protected final Map<String, OpenFile> openFiles = new Hashtable<String, OpenFile>();
|
|
112
|
+ /** Map of open files. */
|
|
113
|
+ protected final Map<String, OpenFile> openFiles
|
|
114
|
+ = Collections.synchronizedMap(new HashMap<String, OpenFile>());
|
113
|
115
|
|
114
|
116
|
/** Date format used for "File Opened At" log. */
|
115
|
117
|
final DateFormat openedAtFormat = new SimpleDateFormat("EEEE MMMM dd, yyyy - HH:mm:ss");
|
116
|
118
|
|
117
|
|
- /**
|
118
|
|
- * Creates a new instance of the Logging Plugin.
|
119
|
|
- */
|
120
|
|
- public LoggingPlugin() {
|
121
|
|
- super();
|
122
|
|
- }
|
123
|
|
-
|
124
|
119
|
/** {@inheritDoc} */
|
125
|
120
|
@Override
|
126
|
121
|
public void domainUpdated() {
|
|
@@ -192,15 +187,10 @@ public class LoggingPlugin extends Plugin implements ActionListener,
|
192
|
187
|
final long oldestTime = System.currentTimeMillis() - 3480000;
|
193
|
188
|
|
194
|
189
|
synchronized (openFiles) {
|
195
|
|
- for (String filename : (new Hashtable<String, OpenFile>(openFiles)).keySet()) {
|
196
|
|
- OpenFile file = openFiles.get(filename);
|
197
|
|
- if (file.lastUsedTime < oldestTime) {
|
198
|
|
- try {
|
199
|
|
- file.writer.close();
|
200
|
|
- openFiles.remove(filename);
|
201
|
|
- } catch (IOException e) {
|
202
|
|
- Logger.userError(ErrorLevel.LOW, "Unable to close idle file (File: " + filename + ")");
|
203
|
|
- }
|
|
190
|
+ for (Map.Entry<String, OpenFile> entry : openFiles.entrySet()) {
|
|
191
|
+ if (entry.getValue().lastUsedTime < oldestTime) {
|
|
192
|
+ StreamUtil.close(entry.getValue().writer);
|
|
193
|
+ openFiles.remove(entry.getKey());
|
204
|
194
|
}
|
205
|
195
|
}
|
206
|
196
|
}
|