瀏覽代碼

SLF4J some more plugins.

pull/420/head
Greg Holmes 9 年之前
父節點
當前提交
b73820f912

+ 8
- 8
mediasource_dbus/src/com/dmdirc/addons/mediasource_dbus/DBusMediaSourceManager.java 查看文件

@@ -22,10 +22,7 @@
22 22
 
23 23
 package com.dmdirc.addons.mediasource_dbus;
24 24
 
25
-import com.dmdirc.DMDircMBassador;
26 25
 import com.dmdirc.addons.nowplaying.MediaSource;
27
-import com.dmdirc.events.UserErrorEvent;
28
-import com.dmdirc.logger.ErrorLevel;
29 26
 
30 27
 import java.io.BufferedReader;
31 28
 import java.io.File;
@@ -39,23 +36,26 @@ import java.util.Map;
39 36
 
40 37
 import javax.inject.Inject;
41 38
 
39
+import org.slf4j.Logger;
40
+import org.slf4j.LoggerFactory;
41
+
42
+import static com.dmdirc.util.LogUtils.USER_ERROR;
43
+
42 44
 /**
43 45
  * Provides a media source for DBUS players.
44 46
  */
45 47
 public class DBusMediaSourceManager {
46 48
 
49
+    private static final Logger LOG = LoggerFactory.getLogger(DBusMediaSourceManager.class);
47 50
     /** A map of discovered mpris sources. */
48 51
     private final Map<String, MediaSource> mprisSources;
49
-    /** The event bus to post errors to. */
50
-    private final DMDircMBassador eventBus;
51 52
     /** The sources used by this media source. */
52 53
     private final List<MediaSource> sources;
53 54
     /** The path to qdbus. */
54 55
     private String qdbus;
55 56
 
56 57
     @Inject
57
-    public DBusMediaSourceManager(final DMDircMBassador eventBus) {
58
-        this.eventBus = eventBus;
58
+    public DBusMediaSourceManager() {
59 59
         sources = new ArrayList<>();
60 60
         mprisSources = new HashMap<>();
61 61
     }
@@ -146,7 +146,7 @@ public class DBusMediaSourceManager {
146 146
                 }
147 147
             }
148 148
         } catch (IOException ex) {
149
-            eventBus.publishAsync(new UserErrorEvent(ErrorLevel.HIGH, ex, "Unable to get DBUS info", ""));
149
+            LOG.error(USER_ERROR, "Unable to get DBUS info", ex);
150 150
         } finally {
151 151
             if (process != null) {
152 152
                 process.destroy();

+ 10
- 14
mediasource_linux_title/src/com/dmdirc/addons/mediasource_linux_title/TitleMediaSource.java 查看文件

@@ -22,23 +22,24 @@
22 22
 
23 23
 package com.dmdirc.addons.mediasource_linux_title;
24 24
 
25
-import com.dmdirc.DMDircMBassador;
26 25
 import com.dmdirc.addons.nowplaying.MediaSource;
27 26
 import com.dmdirc.addons.nowplaying.MediaSourceState;
28
-import com.dmdirc.events.UserErrorEvent;
29
-import com.dmdirc.logger.ErrorLevel;
30 27
 
31 28
 import java.io.BufferedReader;
32 29
 import java.io.IOException;
33 30
 import java.io.InputStreamReader;
34 31
 
32
+import org.slf4j.Logger;
33
+import org.slf4j.LoggerFactory;
34
+
35
+import static com.dmdirc.util.LogUtils.USER_ERROR;
36
+
35 37
 /**
36 38
  * Provides a media source for Linux players using the `xwininfo` command.
37 39
  */
38 40
 public class TitleMediaSource implements MediaSource {
39 41
 
40
-    /** The event bus to post errors to. */
41
-    private final DMDircMBassador eventBus;
42
+    private static final Logger LOG = LoggerFactory.getLogger(TitleMediaSource.class);
42 43
     /** The command to use to get the title. */
43 44
     private final String command;
44 45
     /** The name of the player we're retrieving. */
@@ -47,12 +48,10 @@ public class TitleMediaSource implements MediaSource {
47 48
     /**
48 49
      * Creates a new title media source.
49 50
      *
50
-     * @param eventBus The event bus to post errors to
51 51
      * @param command  The command to be executed
52 52
      * @param name     The name of the media source
53 53
      */
54
-    public TitleMediaSource(final DMDircMBassador eventBus, final String command, final String name) {
55
-        this.eventBus = eventBus;
54
+    public TitleMediaSource(final String command, final String name) {
56 55
         this.command = command;
57 56
         this.name = name;
58 57
     }
@@ -115,8 +114,7 @@ public class TitleMediaSource implements MediaSource {
115 114
     }
116 115
 
117 116
     private String getInfo() {
118
-
119
-        final String[] args = new String[]{"/bin/bash", "-c", "xwininfo -root -tree | " + command};
117
+        final String[] args = {"/bin/bash", "-c", "xwininfo -root -tree | " + command};
120 118
         try {
121 119
             final Process process = Runtime.getRuntime().exec(args);
122 120
             try (InputStreamReader reader = new InputStreamReader(process.getInputStream());
@@ -126,12 +124,10 @@ public class TitleMediaSource implements MediaSource {
126 124
                     return line;
127 125
                 }
128 126
             } catch (IOException ex) {
129
-                eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, ex,
130
-                        "Unable to retrieve media source info", ""));
127
+                LOG.info(USER_ERROR, "Unable to retrieve media source info", ex);
131 128
             }
132 129
         } catch (IOException ex) {
133
-            eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, ex,
134
-                            "Unable to retrieve media source info", ""));
130
+            LOG.info(USER_ERROR, "Unable to retrieve media source info", ex);
135 131
         }
136 132
 
137 133
         return "";

+ 12
- 19
scriptplugin/src/com/dmdirc/addons/scriptplugin/ScriptEngineWrapper.java 查看文件

@@ -22,14 +22,9 @@
22 22
 
23 23
 package com.dmdirc.addons.scriptplugin;
24 24
 
25
-import com.dmdirc.DMDircMBassador;
26
-import com.dmdirc.events.UserErrorEvent;
27
-import com.dmdirc.logger.ErrorLevel;
28
-
29 25
 import com.google.common.base.Preconditions;
30 26
 
31 27
 import java.io.File;
32
-import java.io.FileNotFoundException;
33 28
 import java.io.FileReader;
34 29
 import java.io.IOException;
35 30
 
@@ -38,13 +33,17 @@ import javax.script.ScriptEngine;
38 33
 import javax.script.ScriptEngineManager;
39 34
 import javax.script.ScriptException;
40 35
 
36
+import org.slf4j.Logger;
37
+import org.slf4j.LoggerFactory;
38
+
39
+import static com.dmdirc.util.LogUtils.USER_ERROR;
40
+
41 41
 /**
42 42
  * Class to create script engines!
43 43
  */
44 44
 public class ScriptEngineWrapper {
45 45
 
46
-    /** The event bus to post errors to. */
47
-    private final DMDircMBassador eventBus;
46
+    private static final Logger LOG = LoggerFactory.getLogger(ScriptEngineWrapper.class);
48 47
     /** The Script Engine this wrapper wraps */
49 48
     private ScriptEngine engine;
50 49
     /** The File this script is from */
@@ -58,17 +57,13 @@ public class ScriptEngineWrapper {
58 57
      * Create a new ScriptEngineWrapper
59 58
      *
60 59
      * @param scriptEngineManager Manager to get script engines
61
-     * @param eventBus            The event bus to post errors to
62 60
      * @param filename            Filename of script
63 61
      *
64
-     * @throws java.io.FileNotFoundException If file is not found
65
-     * @throws javax.script.ScriptException  If there was an error during creation
62
+     * @throws ScriptException  If there was an error during creation
66 63
      */
67 64
     protected ScriptEngineWrapper(final ScriptEngineManager scriptEngineManager,
68
-            final DMDircMBassador eventBus, final String filename)
69
-            throws FileNotFoundException, ScriptException {
65
+            final String filename) throws ScriptException {
70 66
         Preconditions.checkNotNull(filename, "File cannot be null");
71
-        this.eventBus = eventBus;
72 67
         this.scriptEngineManager = scriptEngineManager;
73 68
         file = new File(filename);
74 69
 
@@ -109,7 +104,7 @@ public class ScriptEngineWrapper {
109 104
      *
110 105
      * @return Created script engine
111 106
      *
112
-     * @throws javax.script.ScriptException  If there was an error during creation
107
+     * @throws ScriptException  If there was an error during creation
113 108
      */
114 109
     protected ScriptEngine createEngine() throws ScriptException {
115 110
         final ScriptEngine result = scriptEngineManager.getEngineByName("JavaScript");
@@ -141,9 +136,8 @@ public class ScriptEngineWrapper {
141 136
             // and do nothing rather that add an error every time a method is called
142 137
             // that doesn't exist (such as the action_* methods)
143 138
         } catch (ScriptException e) {
144
-            eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, e,
145
-                    "Error calling '" + functionName + "' in '" + file.getPath() + "': " +
146
-                            e.getMessage(), ""));
139
+            LOG.info(USER_ERROR, "Error calling '{}' in '{}': {}",
140
+                    functionName, file.getPath(), e.getMessage(), e);
147 141
         }
148 142
     }
149 143
 
@@ -162,8 +156,7 @@ public class ScriptEngineWrapper {
162 156
             // Tell it that it has been rehashed
163 157
             callFunction("onRehashSucess");
164 158
         } catch (ScriptException e) {
165
-            eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, e,
166
-                    "Reloading '" + file.getPath() + "' failed: " + e.getMessage(), ""));
159
+            LOG.info(USER_ERROR, "Reloading '{}' failed: {}", file.getPath(), e.getMessage(), e);
167 160
             // Tell it that its rehash failed
168 161
             callFunction("onRehashFailed", e);
169 162
             return false;

+ 10
- 13
scriptplugin/src/com/dmdirc/addons/scriptplugin/ScriptManager.java 查看文件

@@ -22,13 +22,9 @@
22 22
 
23 23
 package com.dmdirc.addons.scriptplugin;
24 24
 
25
-import com.dmdirc.DMDircMBassador;
26 25
 import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
27
-import com.dmdirc.events.UserErrorEvent;
28
-import com.dmdirc.logger.ErrorLevel;
29 26
 
30 27
 import java.io.File;
31
-import java.io.FileNotFoundException;
32 28
 import java.util.Arrays;
33 29
 import java.util.HashMap;
34 30
 import java.util.LinkedList;
@@ -39,24 +35,26 @@ import javax.inject.Inject;
39 35
 import javax.script.ScriptEngineManager;
40 36
 import javax.script.ScriptException;
41 37
 
38
+import org.slf4j.Logger;
39
+import org.slf4j.LoggerFactory;
40
+
41
+import static com.dmdirc.util.LogUtils.USER_ERROR;
42
+
42 43
 public class ScriptManager {
43 44
 
45
+    private static final Logger LOG = LoggerFactory.getLogger(ScriptManager.class);
44 46
     /** Script engine manager. */
45 47
     private final ScriptEngineManager scriptEngineManager;
46 48
     /** Script directory. */
47 49
     private final String scriptDirectory;
48 50
     /** Store Script State Name,Engine */
49 51
     private final Map<String, ScriptEngineWrapper> scripts = new HashMap<>();
50
-    /** The event bus to post events to. */
51
-    private final DMDircMBassador eventBus;
52 52
 
53 53
     @Inject
54 54
     public ScriptManager(final ScriptEngineManager scriptEngineManager,
55
-            @Directory(ScriptModule.SCRIPTS) final String scriptDirectory,
56
-            final DMDircMBassador eventBus) {
55
+            @Directory(ScriptModule.SCRIPTS) final String scriptDirectory) {
57 56
         this.scriptEngineManager = scriptEngineManager;
58 57
         this.scriptDirectory = scriptDirectory;
59
-        this.eventBus = eventBus;
60 58
     }
61 59
 
62 60
     /**
@@ -99,11 +97,10 @@ public class ScriptManager {
99 97
         if (!scripts.containsKey(scriptFilename)) {
100 98
             try {
101 99
                 final ScriptEngineWrapper wrapper = new ScriptEngineWrapper(scriptEngineManager,
102
-                        eventBus, scriptFilename);
100
+                        scriptFilename);
103 101
                 scripts.put(scriptFilename, wrapper);
104
-            } catch (FileNotFoundException | ScriptException e) {
105
-                eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, e,
106
-                        "Error loading '" + scriptFilename + "': " + e.getMessage(), ""));
102
+            } catch (ScriptException e) {
103
+                LOG.info(USER_ERROR, "Error loading '{}': {}", scriptFilename, e.getMessage(), e);
107 104
                 return false;
108 105
             }
109 106
         }

+ 12
- 9
scriptplugin/src/com/dmdirc/addons/scriptplugin/ScriptPluginManager.java 查看文件

@@ -27,8 +27,6 @@ import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
27 27
 import com.dmdirc.events.DMDircEvent;
28 28
 import com.dmdirc.events.PluginLoadedEvent;
29 29
 import com.dmdirc.events.PluginUnloadedEvent;
30
-import com.dmdirc.events.UserErrorEvent;
31
-import com.dmdirc.logger.ErrorLevel;
32 30
 
33 31
 import java.io.File;
34 32
 import java.io.FileInputStream;
@@ -41,10 +39,16 @@ import java.util.List;
41 39
 import javax.inject.Inject;
42 40
 import javax.script.ScriptEngineManager;
43 41
 
42
+import org.slf4j.Logger;
43
+import org.slf4j.LoggerFactory;
44
+
44 45
 import net.engio.mbassy.listener.Handler;
45 46
 
47
+import static com.dmdirc.util.LogUtils.USER_ERROR;
48
+
46 49
 public class ScriptPluginManager {
47 50
 
51
+    private static final Logger LOG = LoggerFactory.getLogger(ScriptPluginManager.class);
48 52
     private final DMDircMBassador eventBus;
49 53
     private final String scriptDir;
50 54
     private final ScriptManager scriptManager;
@@ -77,9 +81,8 @@ public class ScriptPluginManager {
77 81
             try (FileInputStream fis = new FileInputStream(savedVariables)) {
78 82
                 globalVariables.load(fis);
79 83
             } catch (IOException e) {
80
-                eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, e,
81
-                        "Error reading savedVariables from '" + savedVariables.getPath() + "': "
82
-                                + e.getMessage(), ""));
84
+                LOG.info(USER_ERROR, "Error reading savedVariables from '{}': {}",
85
+                        savedVariables.getPath(), e.getMessage(), e);
83 86
             }
84 87
         }
85 88
     }
@@ -91,8 +94,8 @@ public class ScriptPluginManager {
91 94
         try (FileOutputStream fos = new FileOutputStream(savedVariables)) {
92 95
             globalVariables.store(fos, "# DMDirc Script Plugin savedVariables");
93 96
         } catch (IOException e) {
94
-            eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, e,"Error reading savedVariables to '"
95
-                    + savedVariables.getPath() + "': " + e.getMessage(), ""));
97
+            LOG.info(USER_ERROR, "Error writing savedVariables to '{}': {}",
98
+                    savedVariables.getPath(), e.getMessage(), e);
96 99
         }
97 100
     }
98 101
 
@@ -107,8 +110,8 @@ public class ScriptPluginManager {
107 110
                 .toUpperCase();
108 111
         final List<Object> arguments = new ArrayList<>();
109 112
         for (Method method : event.getClass().getMethods()) {
110
-            if ((method.getName().startsWith("get") && method.getParameterTypes().length == 0)
111
-                    && !method.getName().equals("getDisplayFormat")) {
113
+            if (method.getName().startsWith("get") && method.getParameterTypes().length == 0 &&
114
+                    !"getDisplayFormat".equals(method.getName())) {
112 115
                 arguments.add(method.invoke(event));
113 116
             }
114 117
         }

Loading…
取消
儲存