Browse Source

Stop using addline without timestamp.

pull/340/head
Greg Holmes 9 years ago
parent
commit
03eb7da560

+ 0
- 1
logging/plugin.config View File

@@ -37,7 +37,6 @@ defaults:
37 37
   general.networkfolders=true
38 38
   advanced.filenamehash=false
39 39
   general.addtime=true
40
-  general.timestamp=[dd/MM/yyyy HH:mm:ss]
41 40
   general.stripcodes=true
42 41
   general.channelmodeprefix=true
43 42
   backbuffer.autobackbuffer=true

+ 29
- 9
logging/src/com/dmdirc/addons/logging/HistoryWindow.java View File

@@ -31,9 +31,14 @@ import com.dmdirc.ui.core.components.WindowComponent;
31 31
 import com.dmdirc.ui.messages.BackBufferFactory;
32 32
 import com.dmdirc.util.io.ReverseFileReader;
33 33
 
34
+import com.google.common.annotations.VisibleForTesting;
35
+
34 36
 import java.io.IOException;
35 37
 import java.nio.file.Path;
38
+import java.text.ParsePosition;
39
+import java.text.SimpleDateFormat;
36 40
 import java.util.Collections;
41
+import java.util.Date;
37 42
 import java.util.Optional;
38 43
 
39 44
 /**
@@ -41,6 +46,10 @@ import java.util.Optional;
41 46
  */
42 47
 public class HistoryWindow extends FrameContainer {
43 48
 
49
+    private final Path logFile;
50
+    private final DMDircMBassador eventBus;
51
+    private final int numLines;
52
+
44 53
     /**
45 54
      * Creates a new HistoryWindow.
46 55
      */
@@ -54,17 +63,12 @@ public class HistoryWindow extends FrameContainer {
54 63
         super(parent, "raw", title, title, parent.getConfigManager(), backBufferFactory,
55 64
                 eventBus,
56 65
                 Collections.singletonList(WindowComponent.TEXTAREA.getIdentifier()));
66
+        this.logFile = logFile;
67
+        this.eventBus = eventBus;
68
+        this.numLines = numLines;
57 69
 
58 70
         initBackBuffer();
59
-        final int frameBufferSize = parent.getConfigManager().getOptionInt(
60
-                "ui", "frameBufferSize");
61
-        try (final ReverseFileReader reader = new ReverseFileReader(logFile)) {
62
-            addLine(reader.getLinesAsString(Math.min(frameBufferSize, numLines)), false);
63
-        } catch (IOException | SecurityException ex) {
64
-            eventBus.publishAsync(
65
-                    new UserErrorEvent(ErrorLevel.MEDIUM, ex, "Unable to read log file.", ""));
66
-        }
67
-
71
+        outputLoggingBackBuffer(parent.getConfigManager().getOptionInt("ui", "frameBufferSize"));
68 72
     }
69 73
 
70 74
     @Override
@@ -72,4 +76,20 @@ public class HistoryWindow extends FrameContainer {
72 76
         return getParent().flatMap(FrameContainer::getConnection);
73 77
     }
74 78
 
79
+    @VisibleForTesting
80
+    void outputLoggingBackBuffer(final int limit) {
81
+        try (final ReverseFileReader reader = new ReverseFileReader(logFile)) {
82
+            final Iterable<String> lines = reader.getLines(Math.min(limit, numLines));
83
+            lines.forEach(l -> {
84
+                final ParsePosition pos = new ParsePosition(0);
85
+                final Date date = new SimpleDateFormat("[dd/MM/yyyy HH:mm:ss]").parse(l, pos);
86
+                final String text = l.substring(pos.getIndex()+1);
87
+                addLine(text, date);
88
+            });
89
+        } catch (IOException | SecurityException ex) {
90
+            eventBus.publishAsync(
91
+                    new UserErrorEvent(ErrorLevel.MEDIUM, ex, "Unable to read log file.", ""));
92
+        }
93
+    }
94
+
75 95
 }

+ 3
- 21
logging/src/com/dmdirc/addons/logging/LoggingManager.java View File

@@ -102,6 +102,7 @@ public class LoggingManager implements ConfigChangeListener {
102 102
             "EEEE MMMM dd, yyyy - HH:mm:ss");
103 103
     /** Object for synchronising access to the date forma.t */
104 104
     private static final Object FORMAT_LOCK = new Object();
105
+    private static final String timestamp = "[dd/MM/yyyy HH:mm:ss]";
105 106
     /** This plugin's plugin info. */
106 107
     private final String domain;
107 108
     private final PluginInfo pluginInfo;
@@ -124,8 +125,6 @@ public class LoggingManager implements ConfigChangeListener {
124 125
     private boolean channelmodeprefix;
125 126
     private boolean autobackbuffer;
126 127
     private boolean backbufferTimestamp;
127
-    /** Cached string settings. */
128
-    private String timestamp;
129 128
     private String colour;
130 129
     /** Cached int settings. */
131 130
     private int historyLines;
@@ -489,20 +488,8 @@ public class LoggingManager implements ConfigChangeListener {
489 488
         final StringBuilder finalLine = new StringBuilder();
490 489
 
491 490
         if (addtime) {
492
-            String dateString;
493
-            try {
494
-                final DateFormat dateFormat = new SimpleDateFormat(timestamp);
495
-                dateString = dateFormat.format(new Date()).trim();
496
-            } catch (IllegalArgumentException iae) {
497
-                // Default to known good format
498
-                final DateFormat dateFormat = new SimpleDateFormat("[dd/MM/yyyy HH:mm:ss]");
499
-                dateString = dateFormat.format(new Date()).trim();
500
-
501
-                eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, iae,
502
-                        "Dateformat String '" + timestamp + "' is invalid. For more information: "
503
-                        + "http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html",
504
-                        ""));
505
-            }
491
+            final DateFormat dateFormat = new SimpleDateFormat(timestamp);
492
+            final String dateString = dateFormat.format(new Date()).trim();
506 493
             finalLine.append(dateString);
507 494
             finalLine.append(' ');
508 495
         }
@@ -608,7 +595,6 @@ public class LoggingManager implements ConfigChangeListener {
608 595
         channelmodeprefix = config.getOptionBool(domain, "general.channelmodeprefix");
609 596
         autobackbuffer = config.getOptionBool(domain, "backbuffer.autobackbuffer");
610 597
         backbufferTimestamp = config.getOptionBool(domain, "backbuffer.timestamp");
611
-        timestamp = config.getOption(domain, "general.timestamp");
612 598
         historyLines = config.getOptionInt(domain, "history.lines");
613 599
         colour = config.getOption(domain, "backbuffer.colour");
614 600
         backbufferLines = config.getOptionInt(domain, "backbuffer.lines");
@@ -638,10 +624,6 @@ public class LoggingManager implements ConfigChangeListener {
638 624
                 pluginInfo.getDomain(), "general.addtime", "Timestamp logs",
639 625
                 "Should a timestamp be added to the log files?",
640 626
                 manager.getConfigManager(), manager.getIdentity()));
641
-        general.addSetting(new PreferencesSetting(PreferencesType.TEXT,
642
-                pluginInfo.getDomain(), "general.timestamp", "Timestamp format",
643
-                "The String to pass to 'SimpleDateFormat' to format the timestamp",
644
-                manager.getConfigManager(), manager.getIdentity()));
645 627
         general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
646 628
                 pluginInfo.getDomain(), "general.stripcodes", "Strip Control Codes",
647 629
                 "Remove known irc control codes from lines before saving?",

+ 3
- 2
parserdebug/src/com/dmdirc/addons/parserdebug/DebugWindow.java View File

@@ -31,6 +31,7 @@ import com.dmdirc.ui.core.components.WindowComponent;
31 31
 import com.dmdirc.ui.messages.BackBufferFactory;
32 32
 
33 33
 import java.util.Arrays;
34
+import java.util.Date;
34 35
 import java.util.Optional;
35 36
 
36 37
 /**
@@ -73,8 +74,8 @@ public class DebugWindow extends FrameContainer {
73 74
      * Set the parser to null to stop us holding onto parsers when the server connection is closed.
74 75
      */
75 76
     public void unsetParser() {
76
-        addLine("======================", true);
77
-        addLine("Unset parser: " + parser, true);
77
+        addLine("======================", new Date());
78
+        addLine("Unset parser: " + parser, new Date());
78 79
         parser = null;
79 80
     }
80 81
 

+ 7
- 7
parserdebug/src/com/dmdirc/addons/parserdebug/ParserDebugManager.java View File

@@ -102,9 +102,9 @@ public class ParserDebugManager implements DebugInfoListener {
102 102
                     connection, eventBus, backBufferFactory);
103 103
             windowManager.addWindow(connection.getWindowModel(), window);
104 104
             registeredParsers.put(parser, window);
105
-            window.addLine("======================", true);
106
-            window.addLine("Started Monitoring: " + parser, true);
107
-            window.addLine("======================", true);
105
+            window.addLine("======================", new Date());
106
+            window.addLine("Started Monitoring: " + parser, new Date());
107
+            window.addLine("======================", new Date());
108 108
             return true;
109 109
         } catch (CallbackNotFoundException ex) {
110 110
             return false;
@@ -123,9 +123,9 @@ public class ParserDebugManager implements DebugInfoListener {
123 123
         try {
124 124
             parser.getCallbackManager().delCallback(DebugInfoListener.class, this);
125 125
             final DebugWindow window = registeredParsers.get(parser);
126
-            window.addLine("======================", true);
127
-            window.addLine("No Longer Monitoring: " + parser + " (User Requested)", true);
128
-            window.addLine("======================", true);
126
+            window.addLine("======================", new Date());
127
+            window.addLine("No Longer Monitoring: " + parser + " (User Requested)", new Date());
128
+            window.addLine("======================", new Date());
129 129
             if (close) {
130 130
                 window.close();
131 131
             }
@@ -159,7 +159,7 @@ public class ParserDebugManager implements DebugInfoListener {
159 159
     public void onDebugInfo(final Parser parser, final Date date, final int level, final String data) {
160 160
         final DebugWindow window = registeredParsers.get(parser);
161 161
         if (window != null) {
162
-            window.addLine(String.format("[%d] %s%n", level, data), true);
162
+            window.addLine(String.format("[%d] %s%n", level, data), new Date());
163 163
         }
164 164
     }
165 165
 

Loading…
Cancel
Save