|
17 | 17 |
|
18 | 18 | package org.apache.log4j.net; |
19 | 19 |
|
20 | | -import java.io.BufferedInputStream; |
21 | | -import java.io.IOException; |
22 | | -import java.io.InterruptedIOException; |
23 | | -import java.io.ObjectInputStream; |
24 | 20 | import java.net.Socket; |
25 | 21 |
|
26 | | -import org.apache.log4j.Logger; |
| 22 | +import org.apache.log4j.helpers.LogLog; |
27 | 23 | import org.apache.log4j.spi.LoggerRepository; |
28 | 24 | import org.apache.log4j.spi.LoggingEvent; |
29 | 25 |
|
30 | 26 | // Contributors: Moses Hohman <mmhohman@rainbow.uchicago.edu> |
31 | 27 |
|
32 | 28 | /** |
33 | 29 | Read {@link LoggingEvent} objects sent from a remote client using |
34 | | - Sockets (TCP). These logging events are logged according to local |
35 | | - policy, as if they were generated locally. |
| 30 | + Sockets (TCP) in Log4j up to 1.2.17. |
36 | 31 |
|
37 | | - <p>For example, the socket node might decide to log events to a |
38 | | - local file and also resent them to a second socket node. |
| 32 | + Changed in 1.2.18+ to complain about its use and do nothing else. |
| 33 | + See <a href="https://logging.apache.org/log4j/1.2/">the log4j 1.2 homepage</a> |
| 34 | + for more information on why JMS is disabled since 1.2.18. |
39 | 35 |
|
40 | | - @author Ceki Gülcü |
| 36 | + @author Ceki Gülcü |
41 | 37 |
|
42 | | - @since 0.8.4 |
| 38 | + @since 0.8.4 |
| 39 | + @noinspection unused |
43 | 40 | */ |
44 | 41 | public class SocketNode implements Runnable { |
45 | 42 |
|
46 | | - Socket socket; |
47 | | - LoggerRepository hierarchy; |
48 | | - ObjectInputStream ois; |
49 | | - |
50 | | - static Logger logger = Logger.getLogger(SocketNode.class); |
| 43 | + static final String SOCKET_NODE_UNSUPPORTED = |
| 44 | + "ERROR-LOG4J-NETWORKING-UNSUPPORTED: SocketNode unsupported!" + |
| 45 | + " This is a breaking change in Log4J 1 >=1.2.18. Stop using this class!"; |
51 | 46 |
|
52 | 47 | public SocketNode(Socket socket, LoggerRepository hierarchy) { |
53 | | - this.socket = socket; |
54 | | - this.hierarchy = hierarchy; |
55 | | - try { |
56 | | - ois = new ObjectInputStream( |
57 | | - new BufferedInputStream(socket.getInputStream())); |
58 | | - } catch(InterruptedIOException e) { |
59 | | - Thread.currentThread().interrupt(); |
60 | | - logger.error("Could not open ObjectInputStream to "+socket, e); |
61 | | - } catch(IOException e) { |
62 | | - logger.error("Could not open ObjectInputStream to "+socket, e); |
63 | | - } catch(RuntimeException e) { |
64 | | - logger.error("Could not open ObjectInputStream to "+socket, e); |
65 | | - } |
| 48 | + LogLog.error(SOCKET_NODE_UNSUPPORTED); |
66 | 49 | } |
67 | 50 |
|
68 | | - //public |
69 | | - //void finalize() { |
70 | | - //System.err.println("-------------------------Finalize called"); |
71 | | - // System.err.flush(); |
72 | | - //} |
73 | | - |
74 | 51 | public void run() { |
75 | | - LoggingEvent event; |
76 | | - Logger remoteLogger; |
77 | | - |
78 | | - try { |
79 | | - if (ois != null) { |
80 | | - while(true) { |
81 | | - // read an event from the wire |
82 | | - event = (LoggingEvent) ois.readObject(); |
83 | | - // get a logger from the hierarchy. The name of the logger is taken to be the name contained in the event. |
84 | | - remoteLogger = hierarchy.getLogger(event.getLoggerName()); |
85 | | - //event.logger = remoteLogger; |
86 | | - // apply the logger-level filter |
87 | | - if(event.getLevel().isGreaterOrEqual(remoteLogger.getEffectiveLevel())) { |
88 | | - // finally log the event as if was generated locally |
89 | | - remoteLogger.callAppenders(event); |
90 | | - } |
91 | | - } |
92 | | - } |
93 | | - } catch(java.io.EOFException e) { |
94 | | - logger.info("Caught java.io.EOFException closing conneciton."); |
95 | | - } catch(java.net.SocketException e) { |
96 | | - logger.info("Caught java.net.SocketException closing conneciton."); |
97 | | - } catch(InterruptedIOException e) { |
98 | | - Thread.currentThread().interrupt(); |
99 | | - logger.info("Caught java.io.InterruptedIOException: "+e); |
100 | | - logger.info("Closing connection."); |
101 | | - } catch(IOException e) { |
102 | | - logger.info("Caught java.io.IOException: "+e); |
103 | | - logger.info("Closing connection."); |
104 | | - } catch(Exception e) { |
105 | | - logger.error("Unexpected exception. Closing conneciton.", e); |
106 | | - } finally { |
107 | | - if (ois != null) { |
108 | | - try { |
109 | | - ois.close(); |
110 | | - } catch(Exception e) { |
111 | | - logger.info("Could not close connection.", e); |
112 | | - } |
113 | | - } |
114 | | - if (socket != null) { |
115 | | - try { |
116 | | - socket.close(); |
117 | | - } catch(InterruptedIOException e) { |
118 | | - Thread.currentThread().interrupt(); |
119 | | - } catch(IOException ex) { |
120 | | - } |
121 | | - } |
122 | | - } |
| 52 | + LogLog.error(SOCKET_NODE_UNSUPPORTED); |
123 | 53 | } |
124 | 54 | } |
0 commit comments