소스 검색

SLF4J Logging in the Ident plugin.

pull/416/head
Greg Holmes 9 년 전
부모
커밋
84de46e048
2개의 변경된 파일21개의 추가작업 그리고 27개의 파일을 삭제
  1. 9
    12
      identd/src/com/dmdirc/addons/identd/IdentClient.java
  2. 12
    15
      identd/src/com/dmdirc/addons/identd/IdentdServer.java

+ 9
- 12
identd/src/com/dmdirc/addons/identd/IdentClient.java 파일 보기

22
 
22
 
23
 package com.dmdirc.addons.identd;
23
 package com.dmdirc.addons.identd;
24
 
24
 
25
-import com.dmdirc.DMDircMBassador;
26
-import com.dmdirc.events.UserErrorEvent;
27
 import com.dmdirc.interfaces.Connection;
25
 import com.dmdirc.interfaces.Connection;
28
 import com.dmdirc.interfaces.ConnectionManager;
26
 import com.dmdirc.interfaces.ConnectionManager;
29
 import com.dmdirc.interfaces.User;
27
 import com.dmdirc.interfaces.User;
30
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
28
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
31
 import com.dmdirc.interfaces.config.ReadOnlyConfigProvider;
29
 import com.dmdirc.interfaces.config.ReadOnlyConfigProvider;
32
-import com.dmdirc.logger.ErrorLevel;
30
+import com.dmdirc.util.LogUtils;
33
 import com.dmdirc.util.SystemInfo;
31
 import com.dmdirc.util.SystemInfo;
34
 import com.dmdirc.util.io.StreamUtils;
32
 import com.dmdirc.util.io.StreamUtils;
35
 
33
 
39
 import java.io.PrintWriter;
37
 import java.io.PrintWriter;
40
 import java.net.Socket;
38
 import java.net.Socket;
41
 
39
 
40
+import org.slf4j.Logger;
41
+import org.slf4j.LoggerFactory;
42
+
42
 /**
43
 /**
43
  * The IdentClient responds to an ident request.
44
  * The IdentClient responds to an ident request.
44
  */
45
  */
45
 public class IdentClient implements Runnable {
46
 public class IdentClient implements Runnable {
46
 
47
 
47
-    /** The event bus to post errors on. */
48
-    private final DMDircMBassador eventBus;
48
+    private static final Logger LOG = LoggerFactory.getLogger(IdentClient.class);
49
     /** The IdentdServer that owns this Client. */
49
     /** The IdentdServer that owns this Client. */
50
     private final IdentdServer server;
50
     private final IdentdServer server;
51
     /** The Socket that we are in charge of. */
51
     /** The Socket that we are in charge of. */
64
     /**
64
     /**
65
      * Create the IdentClient.
65
      * Create the IdentClient.
66
      */
66
      */
67
-    public IdentClient(final DMDircMBassador eventBus, final IdentdServer server,
68
-            final Socket socket, final ConnectionManager connectionManager,
69
-            final AggregateConfigProvider config, final String domain,
70
-            final SystemInfo systemInfo) {
71
-        this.eventBus = eventBus;
67
+    public IdentClient(final IdentdServer server, final Socket socket,
68
+            final ConnectionManager connectionManager, final AggregateConfigProvider config,
69
+            final String domain, final SystemInfo systemInfo) {
72
         this.server = server;
70
         this.server = server;
73
         this.socket = socket;
71
         this.socket = socket;
74
         this.connectionManager = connectionManager;
72
         this.connectionManager = connectionManager;
99
             }
97
             }
100
         } catch (IOException e) {
98
         } catch (IOException e) {
101
             if (thisThread == thread) {
99
             if (thisThread == thread) {
102
-                eventBus.publishAsync(new UserErrorEvent(ErrorLevel.HIGH, e,
103
-                        "ClientSocket Error: " + e.getMessage(), ""));
100
+                LOG.error(LogUtils.USER_ERROR, "ClientSocket Error: {}", e.getMessage(), e);
104
             }
101
             }
105
         } finally {
102
         } finally {
106
             StreamUtils.close(socket);
103
             StreamUtils.close(socket);

+ 12
- 15
identd/src/com/dmdirc/addons/identd/IdentdServer.java 파일 보기

23
 package com.dmdirc.addons.identd;
23
 package com.dmdirc.addons.identd;
24
 
24
 
25
 import com.dmdirc.ClientModule.GlobalConfig;
25
 import com.dmdirc.ClientModule.GlobalConfig;
26
-import com.dmdirc.DMDircMBassador;
27
-import com.dmdirc.events.UserErrorEvent;
28
 import com.dmdirc.interfaces.ConnectionManager;
26
 import com.dmdirc.interfaces.ConnectionManager;
29
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
27
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
30
-import com.dmdirc.logger.ErrorLevel;
31
 import com.dmdirc.plugins.PluginDomain;
28
 import com.dmdirc.plugins.PluginDomain;
32
 import com.dmdirc.util.SystemInfo;
29
 import com.dmdirc.util.SystemInfo;
33
 
30
 
39
 
36
 
40
 import javax.inject.Inject;
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
  * The IdentdServer watches over the ident port when required
45
  * The IdentdServer watches over the ident port when required
44
  */
46
  */
45
 public final class IdentdServer implements Runnable {
47
 public final class IdentdServer implements Runnable {
46
 
48
 
47
-    /** The event bus to post errors on. */
48
-    private final DMDircMBassador eventBus;
49
+    private static final Logger LOG = LoggerFactory.getLogger(IdentdServer.class);
49
     /** The Thread in use for this server */
50
     /** The Thread in use for this server */
50
     private volatile Thread myThread;
51
     private volatile Thread myThread;
51
     /** The current socket in use for this server */
52
     /** The current socket in use for this server */
66
     /**
67
     /**
67
      * Create the IdentdServer.
68
      * Create the IdentdServer.
68
      *
69
      *
69
-     * @param eventBus      The event bus to post errors on
70
      * @param connectionManager Server manager to iterate over servers
70
      * @param connectionManager Server manager to iterate over servers
71
      * @param config        Global config
71
      * @param config        Global config
72
      * @param domain        This plugin's setting domain
72
      * @param domain        This plugin's setting domain
73
      */
73
      */
74
     @Inject
74
     @Inject
75
-    public IdentdServer(final DMDircMBassador eventBus,
76
-            final ConnectionManager connectionManager,
75
+    public IdentdServer(final ConnectionManager connectionManager,
77
             @GlobalConfig final AggregateConfigProvider config,
76
             @GlobalConfig final AggregateConfigProvider config,
78
             @PluginDomain(IdentdPlugin.class) final String domain,
77
             @PluginDomain(IdentdPlugin.class) final String domain,
79
             final SystemInfo systemInfo) {
78
             final SystemInfo systemInfo) {
80
-        this.eventBus = eventBus;
81
         this.connectionManager = connectionManager;
79
         this.connectionManager = connectionManager;
82
         this.config = config;
80
         this.config = config;
83
         this.domain = domain;
81
         this.domain = domain;
93
         while (myThread == thisThread) {
91
         while (myThread == thisThread) {
94
             try {
92
             try {
95
                 final Socket clientSocket = serverSocket.accept();
93
                 final Socket clientSocket = serverSocket.accept();
96
-                final IdentClient client = new IdentClient(eventBus, this, clientSocket,
97
-                        connectionManager, config, domain, systemInfo);
94
+                final IdentClient client = new IdentClient(this, clientSocket, connectionManager,
95
+                        config, domain, systemInfo);
98
                 client.start();
96
                 client.start();
99
                 addClient(client);
97
                 addClient(client);
100
             } catch (IOException e) {
98
             } catch (IOException e) {
101
                 if (myThread == thisThread) {
99
                 if (myThread == thisThread) {
102
-                    eventBus.publishAsync(new UserErrorEvent(ErrorLevel.HIGH, e,
103
-                            "Accepting client failed: " + e.getMessage(), ""));
100
+                    LOG.error(USER_ERROR, "Accepting client failed: {}", e.getMessage(), e);
104
                 }
101
                 }
105
             }
102
             }
106
         }
103
         }
153
                 myThread = new Thread(this);
150
                 myThread = new Thread(this);
154
                 myThread.start();
151
                 myThread.start();
155
             } catch (IOException e) {
152
             } catch (IOException e) {
156
-                eventBus.publishAsync(new UserErrorEvent(ErrorLevel.HIGH, e,
157
-                        "Unable to start identd server: " + e.getMessage(), ""));
153
+                LOG.error(USER_ERROR, "Unable to start identd server: {}", e.getMessage(), e);
158
                 if ("Permission denied".equals(e.getMessage())) {
154
                 if ("Permission denied".equals(e.getMessage())) {
159
                     failed = true;
155
                     failed = true;
160
                 }
156
                 }
175
             try {
171
             try {
176
                 serverSocket.close();
172
                 serverSocket.close();
177
             } catch (IOException e) {
173
             } catch (IOException e) {
174
+                LOG.info("Unable to close socket: {}", e.getMessage(), e);
178
             }
175
             }
179
 
176
 
180
             synchronized (clientList) {
177
             synchronized (clientList) {

Loading…
취소
저장