@@ -817,8 +817,11 @@ public void trueClose(boolean addToDeadPool) throws IOException {
817817 try {
818818 in .close ();
819819 } catch (IOException ioe ) {
820- log .error ("++++ error closing input stream for socket: " + toString () + " for host: " + getHost ());
821- log .error (ioe .getMessage (), ioe );
820+ if (log .isErrorEnabled ()) {
821+ log .error ("++++ error closing input stream for socket: " + toString () + " for host: "
822+ + getHost ());
823+ log .error (ioe .getMessage (), ioe );
824+ }
822825 errMsg .append ("++++ error closing input stream for socket: " + toString () + " for host: "
823826 + getHost () + "\n " );
824827 errMsg .append (ioe .getMessage ());
@@ -830,8 +833,11 @@ public void trueClose(boolean addToDeadPool) throws IOException {
830833 try {
831834 out .close ();
832835 } catch (IOException ioe ) {
833- log .error ("++++ error closing output stream for socket: " + toString () + " for host: " + getHost ());
834- log .error (ioe .getMessage (), ioe );
836+ if (log .isErrorEnabled ()) {
837+ log .error ("++++ error closing output stream for socket: " + toString () + " for host: "
838+ + getHost ());
839+ log .error (ioe .getMessage (), ioe );
840+ }
835841 errMsg .append ("++++ error closing output stream for socket: " + toString () + " for host: "
836842 + getHost () + "\n " );
837843 errMsg .append (ioe .getMessage ());
@@ -843,8 +849,10 @@ public void trueClose(boolean addToDeadPool) throws IOException {
843849 try {
844850 sock .close ();
845851 } catch (IOException ioe ) {
846- log .error ("++++ error closing socket: " + toString () + " for host: " + getHost ());
847- log .error (ioe .getMessage (), ioe );
852+ if (log .isErrorEnabled ()) {
853+ log .error ("++++ error closing socket: " + toString () + " for host: " + getHost ());
854+ log .error (ioe .getMessage (), ioe );
855+ }
848856 errMsg .append ("++++ error closing socket: " + toString () + " for host: " + getHost () + "\n " );
849857 errMsg .append (ioe .getMessage ());
850858 err = true ;
@@ -916,7 +924,8 @@ public boolean isAlive() {
916924 */
917925 public String readLine () throws IOException {
918926 if (sock == null || !sock .isConnected ()) {
919- log .error ("++++ attempting to read from closed socket" );
927+ if (log .isErrorEnabled ())
928+ log .error ("++++ attempting to read from closed socket" );
920929 throw new IOException ("++++ attempting to read from closed socket" );
921930 }
922931
@@ -957,7 +966,8 @@ public String readLine() throws IOException {
957966 */
958967 public void clearEOL () throws IOException {
959968 if (sock == null || !sock .isConnected ()) {
960- log .error ("++++ attempting to read from closed socket" );
969+ if (log .isErrorEnabled ())
970+ log .error ("++++ attempting to read from closed socket" );
961971 throw new IOException ("++++ attempting to read from closed socket" );
962972 }
963973
@@ -991,7 +1001,8 @@ public void clearEOL() throws IOException {
9911001 */
9921002 public int read (byte [] b ) throws IOException {
9931003 if (sock == null || !sock .isConnected ()) {
994- log .error ("++++ attempting to read from closed socket" );
1004+ if (log .isErrorEnabled ())
1005+ log .error ("++++ attempting to read from closed socket" );
9951006 throw new IOException ("++++ attempting to read from closed socket" );
9961007 }
9971008
@@ -1012,7 +1023,8 @@ public int read(byte[] b) throws IOException {
10121023 */
10131024 public void flush () throws IOException {
10141025 if (sock == null || !sock .isConnected ()) {
1015- log .error ("++++ attempting to write to closed socket" );
1026+ if (log .isErrorEnabled ())
1027+ log .error ("++++ attempting to write to closed socket" );
10161028 throw new IOException ("++++ attempting to write to closed socket" );
10171029 }
10181030 out .flush ();
@@ -1028,7 +1040,8 @@ public void flush() throws IOException {
10281040 */
10291041 public void write (byte [] b ) throws IOException {
10301042 if (sock == null || !sock .isConnected ()) {
1031- log .error ("++++ attempting to write to closed socket" );
1043+ if (log .isErrorEnabled ())
1044+ log .error ("++++ attempting to write to closed socket" );
10321045 throw new IOException ("++++ attempting to write to closed socket" );
10331046 }
10341047 out .write (b );
@@ -1058,12 +1071,14 @@ public String toString() {
10581071 protected void finalize () throws Throwable {
10591072 try {
10601073 if (sock != null ) {
1061- log .error ("++++ closing potentially leaked socket in finalize" );
1074+ if (log .isErrorEnabled ())
1075+ log .error ("++++ closing potentially leaked socket in finalize" );
10621076 sock .close ();
10631077 sock = null ;
10641078 }
10651079 } catch (Throwable t ) {
1066- log .error (t .getMessage (), t );
1080+ if (log .isErrorEnabled ())
1081+ log .error (t .getMessage (), t );
10671082 } finally {
10681083 super .finalize ();
10691084 }
@@ -1257,13 +1272,16 @@ protected SockIO createSocket(String host) {
12571272 socket = new SockIO (this , host , this .socketTO , this .socketConnectTO , this .nagle );
12581273
12591274 if (!socket .isConnected ()) {
1260- log .error ("++++ failed to get SockIO obj for: " + host + " -- new socket is not connected" );
1275+ if (log .isErrorEnabled ())
1276+ log .error ("++++ failed to get SockIO obj for: " + host + " -- new socket is not connected" );
12611277 deadPool .put (socket , ZERO );
12621278 socket = null ;
12631279 }
12641280 } catch (Exception ex ) {
1265- log .error ("++++ failed to get SockIO obj for: " + host );
1266- log .error (ex .getMessage (), ex );
1281+ if (log .isErrorEnabled ()) {
1282+ log .error ("++++ failed to get SockIO obj for: " + host );
1283+ log .error (ex .getMessage (), ex );
1284+ }
12671285 socket = null ;
12681286 }
12691287
@@ -1424,8 +1442,9 @@ protected void selfMaint() {
14241442 // then close socket
14251443 // and remove from pool
14261444 if ((hungTime + maxBusyTime ) < System .currentTimeMillis ()) {
1427- log .error ("+++ removing potentially hung connection from busy pool ... socket in pool for "
1428- + (System .currentTimeMillis () - hungTime ) + "ms" );
1445+ if (log .isErrorEnabled ())
1446+ log .error ("+++ removing potentially hung connection from busy pool ... socket in pool for "
1447+ + (System .currentTimeMillis () - hungTime ) + "ms" );
14291448
14301449 // remove from the busy pool
14311450 deadPool .put (socket , ZERO );
@@ -1446,8 +1465,10 @@ protected void selfMaint() {
14461465 try {
14471466 socket .trueClose (false );
14481467 } catch (Exception ex ) {
1449- log .error ("++++ failed to close SockIO obj from deadPool" );
1450- log .error (ex .getMessage (), ex );
1468+ if (log .isErrorEnabled ()) {
1469+ log .error ("++++ failed to close SockIO obj from deadPool" );
1470+ log .error (ex .getMessage (), ex );
1471+ }
14511472 }
14521473
14531474 socket = null ;
@@ -1530,7 +1551,8 @@ protected void clearHostFromPool(Map<String, Map<SockIO, Long>> pool, String hos
15301551 try {
15311552 socket .trueClose ();
15321553 } catch (IOException ioe ) {
1533- log .error ("++++ failed to close socket: " + ioe .getMessage ());
1554+ if (log .isErrorEnabled ())
1555+ log .error ("++++ failed to close socket: " + ioe .getMessage ());
15341556 }
15351557
15361558 i .remove ();
0 commit comments