Skip to content

Commit 239e4bf

Browse files
committed
cleaner error handling
1 parent 3d0dea0 commit 239e4bf

6 files changed

Lines changed: 22 additions & 11 deletions

File tree

src/main/com/mongodb/ByteDecoder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.util.Date;
2424
import java.util.regex.Pattern;
2525
import java.nio.ByteBuffer;
26-
26+
import java.util.logging.*;
2727

2828
/**
2929
* Deserializes a string from the database into a <code>DBObject</code>.
@@ -129,11 +129,11 @@ private DBObject _create( String path ){
129129
return (DBObject)c.newInstance();
130130
}
131131
catch ( InstantiationException ie ){
132-
ie.printStackTrace();
132+
LOGGER.log( Level.FINE , "can't create a: " + c , ie );
133133
throw new MongoInternalException( "can't instantiate a : " + c , ie );
134134
}
135135
catch ( IllegalAccessException iae ){
136-
iae.printStackTrace();
136+
LOGGER.log( Level.FINE , "can't create a: " + c , iae );
137137
throw new MongoInternalException( "can't instantiate a : " + c , iae );
138138
}
139139
}

src/main/com/mongodb/Bytes.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,24 @@
2222
import java.nio.charset.*;
2323
import java.util.regex.Pattern;
2424
import java.util.*;
25+
import java.util.logging.*;
2526

2627
/**
2728
* Handles byte functions for <code>ByteEncoder</code> and <code>ByteDecoder</code>.
2829
*/
2930
public class Bytes {
30-
31+
32+
static Logger LOGGER = Logger.getLogger( "com.mongodb" );
33+
3134
static final boolean D = Boolean.getBoolean( "DEBUG.DB" );
3235

36+
static {
37+
if ( D )
38+
LOGGER.setLevel( Level.ALL );
39+
else
40+
LOGGER.setLevel( Level.WARNING );
41+
}
42+
3343
/** Little-endian */
3444
public static final ByteOrder ORDER = ByteOrder.LITTLE_ENDIAN;
3545

src/main/com/mongodb/DBApiLayer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.nio.*;
2222
import java.util.*;
23+
import java.util.logging.*;
2324

2425
import com.mongodb.util.*;
2526

@@ -344,7 +345,7 @@ void _cleanCursors()
344345
killCursors( l );
345346
}
346347
catch ( Throwable t ){
347-
t.printStackTrace();
348+
Bytes.LOGGER.log( Level.WARNING , "can't clean cursors" , t );
348349
_deadCursorIds.addAll( l );
349350
}
350351
}

src/main/com/mongodb/DBPort.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ void _open()
144144
}
145145
catch ( IOException ioe ){
146146
// TODO - erh to fix lastError = new IOException( "couldn't connect to [" + _addr + "] bc:" + lastError , lastError );
147-
lastError = new IOException( "couldn't connect to [" + _addr + "] bc:" + ioe);
148-
_logger.log( Level.SEVERE , "connect fail to : " + _addr , ioe );
147+
lastError = new IOException( "couldn't connect to [" + _addr + "] bc:" + ioe , ioe );
148+
_logger.log( Level.INFO , "connect fail to : " + _addr , ioe );
149149
}
150150

151151
if ( _pool != null && ! _pool._everWorked )
@@ -202,5 +202,5 @@ protected void finalize(){
202202
private SocketChannel _sock;
203203

204204

205-
private static Logger _rootLogger = Logger.getLogger( "db.port" );
205+
private static Logger _rootLogger = Logger.getLogger( "com.mongodb.port" );
206206
}

src/main/com/mongodb/DBPortPool.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.net.*;
2525
import java.util.*;
2626
import java.util.concurrent.*;
27+
import java.util.logging.*;
2728

2829
class DBPortPool extends SimplePool<DBPort> {
2930

@@ -102,8 +103,7 @@ void gotError( Exception e ){
102103
return;
103104
}
104105

105-
System.out.println( "emptying DBPortPool b/c of error" );
106-
e.printStackTrace();
106+
Bytes.LOGGER.log( Level.INFO , "emptying DBPortPool b/c of error" , e );
107107
clear();
108108
}
109109

src/main/com/mongodb/DBTCP.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
public class DBTCP extends DBMessageLayer {
2828

29-
static Logger _logger = Logger.getLogger( "DBTCP" );
29+
static Logger _logger = Logger.getLogger( Bytes.LOGGER.getName() + ".tcp" );
3030
static Logger _createLogger = Logger.getLogger( _logger.getName() + ".connect" );
3131

3232
public DBTCP( DBAddress addr )

0 commit comments

Comments
 (0)