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
   general.networkfolders=true
37
   general.networkfolders=true
38
   advanced.filenamehash=false
38
   advanced.filenamehash=false
39
   general.addtime=true
39
   general.addtime=true
40
-  general.timestamp=[dd/MM/yyyy HH:mm:ss]
41
   general.stripcodes=true
40
   general.stripcodes=true
42
   general.channelmodeprefix=true
41
   general.channelmodeprefix=true
43
   backbuffer.autobackbuffer=true
42
   backbuffer.autobackbuffer=true

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

31
 import com.dmdirc.ui.messages.BackBufferFactory;
31
 import com.dmdirc.ui.messages.BackBufferFactory;
32
 import com.dmdirc.util.io.ReverseFileReader;
32
 import com.dmdirc.util.io.ReverseFileReader;
33
 
33
 
34
+import com.google.common.annotations.VisibleForTesting;
35
+
34
 import java.io.IOException;
36
 import java.io.IOException;
35
 import java.nio.file.Path;
37
 import java.nio.file.Path;
38
+import java.text.ParsePosition;
39
+import java.text.SimpleDateFormat;
36
 import java.util.Collections;
40
 import java.util.Collections;
41
+import java.util.Date;
37
 import java.util.Optional;
42
 import java.util.Optional;
38
 
43
 
39
 /**
44
 /**
41
  */
46
  */
42
 public class HistoryWindow extends FrameContainer {
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
      * Creates a new HistoryWindow.
54
      * Creates a new HistoryWindow.
46
      */
55
      */
54
         super(parent, "raw", title, title, parent.getConfigManager(), backBufferFactory,
63
         super(parent, "raw", title, title, parent.getConfigManager(), backBufferFactory,
55
                 eventBus,
64
                 eventBus,
56
                 Collections.singletonList(WindowComponent.TEXTAREA.getIdentifier()));
65
                 Collections.singletonList(WindowComponent.TEXTAREA.getIdentifier()));
66
+        this.logFile = logFile;
67
+        this.eventBus = eventBus;
68
+        this.numLines = numLines;
57
 
69
 
58
         initBackBuffer();
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
     @Override
74
     @Override
72
         return getParent().flatMap(FrameContainer::getConnection);
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
             "EEEE MMMM dd, yyyy - HH:mm:ss");
102
             "EEEE MMMM dd, yyyy - HH:mm:ss");
103
     /** Object for synchronising access to the date forma.t */
103
     /** Object for synchronising access to the date forma.t */
104
     private static final Object FORMAT_LOCK = new Object();
104
     private static final Object FORMAT_LOCK = new Object();
105
+    private static final String timestamp = "[dd/MM/yyyy HH:mm:ss]";
105
     /** This plugin's plugin info. */
106
     /** This plugin's plugin info. */
106
     private final String domain;
107
     private final String domain;
107
     private final PluginInfo pluginInfo;
108
     private final PluginInfo pluginInfo;
124
     private boolean channelmodeprefix;
125
     private boolean channelmodeprefix;
125
     private boolean autobackbuffer;
126
     private boolean autobackbuffer;
126
     private boolean backbufferTimestamp;
127
     private boolean backbufferTimestamp;
127
-    /** Cached string settings. */
128
-    private String timestamp;
129
     private String colour;
128
     private String colour;
130
     /** Cached int settings. */
129
     /** Cached int settings. */
131
     private int historyLines;
130
     private int historyLines;
489
         final StringBuilder finalLine = new StringBuilder();
488
         final StringBuilder finalLine = new StringBuilder();
490
 
489
 
491
         if (addtime) {
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
             finalLine.append(dateString);
493
             finalLine.append(dateString);
507
             finalLine.append(' ');
494
             finalLine.append(' ');
508
         }
495
         }
608
         channelmodeprefix = config.getOptionBool(domain, "general.channelmodeprefix");
595
         channelmodeprefix = config.getOptionBool(domain, "general.channelmodeprefix");
609
         autobackbuffer = config.getOptionBool(domain, "backbuffer.autobackbuffer");
596
         autobackbuffer = config.getOptionBool(domain, "backbuffer.autobackbuffer");
610
         backbufferTimestamp = config.getOptionBool(domain, "backbuffer.timestamp");
597
         backbufferTimestamp = config.getOptionBool(domain, "backbuffer.timestamp");
611
-        timestamp = config.getOption(domain, "general.timestamp");
612
         historyLines = config.getOptionInt(domain, "history.lines");
598
         historyLines = config.getOptionInt(domain, "history.lines");
613
         colour = config.getOption(domain, "backbuffer.colour");
599
         colour = config.getOption(domain, "backbuffer.colour");
614
         backbufferLines = config.getOptionInt(domain, "backbuffer.lines");
600
         backbufferLines = config.getOptionInt(domain, "backbuffer.lines");
638
                 pluginInfo.getDomain(), "general.addtime", "Timestamp logs",
624
                 pluginInfo.getDomain(), "general.addtime", "Timestamp logs",
639
                 "Should a timestamp be added to the log files?",
625
                 "Should a timestamp be added to the log files?",
640
                 manager.getConfigManager(), manager.getIdentity()));
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
         general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
627
         general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
646
                 pluginInfo.getDomain(), "general.stripcodes", "Strip Control Codes",
628
                 pluginInfo.getDomain(), "general.stripcodes", "Strip Control Codes",
647
                 "Remove known irc control codes from lines before saving?",
629
                 "Remove known irc control codes from lines before saving?",

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

31
 import com.dmdirc.ui.messages.BackBufferFactory;
31
 import com.dmdirc.ui.messages.BackBufferFactory;
32
 
32
 
33
 import java.util.Arrays;
33
 import java.util.Arrays;
34
+import java.util.Date;
34
 import java.util.Optional;
35
 import java.util.Optional;
35
 
36
 
36
 /**
37
 /**
73
      * Set the parser to null to stop us holding onto parsers when the server connection is closed.
74
      * Set the parser to null to stop us holding onto parsers when the server connection is closed.
74
      */
75
      */
75
     public void unsetParser() {
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
         parser = null;
79
         parser = null;
79
     }
80
     }
80
 
81
 

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

102
                     connection, eventBus, backBufferFactory);
102
                     connection, eventBus, backBufferFactory);
103
             windowManager.addWindow(connection.getWindowModel(), window);
103
             windowManager.addWindow(connection.getWindowModel(), window);
104
             registeredParsers.put(parser, window);
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
             return true;
108
             return true;
109
         } catch (CallbackNotFoundException ex) {
109
         } catch (CallbackNotFoundException ex) {
110
             return false;
110
             return false;
123
         try {
123
         try {
124
             parser.getCallbackManager().delCallback(DebugInfoListener.class, this);
124
             parser.getCallbackManager().delCallback(DebugInfoListener.class, this);
125
             final DebugWindow window = registeredParsers.get(parser);
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
             if (close) {
129
             if (close) {
130
                 window.close();
130
                 window.close();
131
             }
131
             }
159
     public void onDebugInfo(final Parser parser, final Date date, final int level, final String data) {
159
     public void onDebugInfo(final Parser parser, final Date date, final int level, final String data) {
160
         final DebugWindow window = registeredParsers.get(parser);
160
         final DebugWindow window = registeredParsers.get(parser);
161
         if (window != null) {
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