https://jira.mongodb.org/browse/JAVA-375 #54

Closed
wants to merge 3 commits into from
View
2 src/main/com/mongodb/Bytes.java
@@ -36,7 +36,7 @@
*/
public class Bytes extends BSON {
- static final Logger LOGGER = Logger.getLogger( "com.mongodb" );
+ static final Logger LOGGER = Logger.getLogger( Bytes.class.getCanonicalName() );
static final boolean D = Boolean.getBoolean( "DEBUG.MONGO" );
View
25 src/main/com/mongodb/DBApiLayer.java
@@ -42,22 +42,23 @@
*/
public class DBApiLayer extends DB {
- static final boolean D = Boolean.getBoolean( "DEBUG.DB" );
/** The maximum number of cursors allowed */
static final int NUM_CURSORS_BEFORE_KILL = 100;
static final int NUM_CURSORS_PER_BATCH = 20000;
// --- show
- static final Logger TRACE_LOGGER = Logger.getLogger( "com.mongodb.TRACE" );
+ static final Logger LOGGER = Logger.getLogger(DBApiLayer.class.getCanonicalName());
static final Level TRACE_LEVEL = Boolean.getBoolean( "DB.TRACE" ) ? Level.INFO : Level.FINEST;
- static final boolean willTrace(){
- return TRACE_LOGGER.isLoggable( TRACE_LEVEL );
+ static boolean willTrace(){
+ return LOGGER.isLoggable( TRACE_LEVEL );
}
- static final void trace( String s ){
- TRACE_LOGGER.log( TRACE_LEVEL , s );
+ static void trace( String s ){
+ if(willTrace()) {
+ LOGGER.log( TRACE_LEVEL , s );
+ }
}
static int chooseBatchSize(int batchSize, int limit, int fetched) {
@@ -136,7 +137,7 @@ public void cleanCursors( boolean force )
if ( sz == 0 || ( ! force && sz < NUM_CURSORS_BEFORE_KILL))
return;
- Bytes.LOGGER.info( "going to kill cursors : " + sz );
+ LOGGER.info( "going to kill cursors : " + sz );
Map<ServerAddress,List<Long>> m = new HashMap<ServerAddress,List<Long>>();
DeadCursor c;
@@ -154,7 +155,7 @@ public void cleanCursors( boolean force )
killCursors( e.getKey() , e.getValue() );
}
catch ( Throwable t ){
- Bytes.LOGGER.log( Level.WARNING , "can't clean cursors" , t );
+ LOGGER.log( Level.WARNING , "can't clean cursors" , t );
for ( Long x : e.getValue() )
_deadCursorIds.add( new DeadCursor( x , e.getKey() ) );
}
@@ -270,7 +271,7 @@ public WriteResult remove( DBObject o , com.mongodb.WriteConcern concern, DBEnco
if (encoder == null)
encoder = DefaultDBEncoder.FACTORY.create();
- if ( willTrace() ) trace( "remove: " + _fullNameSpace + " " + JSON.serialize( o ) );
+ trace( "remove: " + _fullNameSpace + " " + JSON.serialize( o ) );
OutMessage om = new OutMessage( _mongo , 2006, encoder );
@@ -298,7 +299,7 @@ public WriteResult remove( DBObject o , com.mongodb.WriteConcern concern, DBEnco
if ( ref == null )
ref = new BasicDBObject();
- if ( willTrace() ) trace( "find: " + _fullNameSpace + " " + JSON.serialize( ref ) );
+ trace( "find: " + _fullNameSpace + " " + JSON.serialize( ref ) );
OutMessage query = OutMessage.query( _mongo , options , _fullNameSpace , numToSkip , chooseBatchSize(batchSize, limit, 0) , ref , fields, readPref);
@@ -331,7 +332,7 @@ public WriteResult update( DBObject query , DBObject o , boolean upsert , boolea
_checkObject(o, false, false);
}
- if ( willTrace() ) trace( "update: " + _fullNameSpace + " " + JSON.serialize( query ) + " " + JSON.serialize( o ) );
+ trace( "update: " + _fullNameSpace + " " + JSON.serialize( query ) + " " + JSON.serialize( o ) );
OutMessage om = new OutMessage( _mongo , 2001, encoder );
om.writeInt( 0 ); // reserved
@@ -522,7 +523,7 @@ void killCursor() {
try {
killCursors(_host, l);
} catch (Throwable t) {
- Bytes.LOGGER.log(Level.WARNING, "can't clean 1 cursor", t);
+ LOGGER.log(Level.WARNING, "can't clean 1 cursor", t);
_deadCursorIds.add(new DeadCursor(curId, _host));
}
_curResult._cursor = 0;
View
8 src/main/com/mongodb/DBPort.java
@@ -63,7 +63,6 @@ public DBPort( ServerAddress addr ){
_hashCode = _addr.hashCode();
- _logger = Logger.getLogger( _rootLogger.getName() + "." + addr.toString() );
_decoder = _options.dbDecoderFactory.create();
}
@@ -226,7 +225,7 @@ boolean _open()
}
catch ( IOException ioe ){
lastError = new IOException( "couldn't connect to [" + _addr + "] bc:" + ioe );
- _logger.log( Level.INFO , "connect fail to : " + _addr , ioe );
+ _logger.log( Level.INFO , "connect fail to : " + _addr + " -- serverAddress: " + _sa, ioe );
close();
}
@@ -241,7 +240,7 @@ boolean _open()
if ( sleepTime + sleptSoFar > maxAutoConnectRetryTime )
sleepTime = maxAutoConnectRetryTime - sleptSoFar;
- _logger.severe( "going to sleep and retry. total sleep time after = " + ( sleptSoFar + sleptSoFar ) + "ms this time:" + sleepTime + "ms" );
+ _logger.severe( "going to sleep and retry. total sleep time after = " + ( sleptSoFar + sleptSoFar ) + "ms this time:" + sleepTime + "ms. serverAddress: " + _sa );
ThreadUtil.sleep( sleepTime );
sleepTime *= 2;
@@ -333,7 +332,7 @@ public DBPortPool getPool() {
final InetSocketAddress _addr;
final DBPortPool _pool;
final MongoOptions _options;
- final Logger _logger;
+ final Logger _logger = Logger.getLogger(DBPort.class.getCanonicalName());
final DBDecoder _decoder;
private Socket _socket;
@@ -346,5 +345,4 @@ public DBPortPool getPool() {
int _lastThread;
long _calls = 0;
- private static Logger _rootLogger = Logger.getLogger( "com.mongodb.port" );
}
View
13 src/main/com/mongodb/DBPortPool.java
@@ -26,6 +26,7 @@
import java.util.Map;
import java.util.concurrent.Semaphore;
import java.util.logging.Level;
+import java.util.logging.Logger;
import javax.management.JMException;
import javax.management.MBeanServer;
@@ -35,6 +36,8 @@
import com.mongodb.util.SimplePool;
public class DBPortPool extends SimplePool<DBPort> {
+
+ private static final Logger LOGGER = Logger.getLogger(DBPortPool.class.getCanonicalName());
static class Holder {
@@ -73,15 +76,15 @@ DBPortPool get( ServerAddress addr ){
ObjectName on = createObjectName( addr );
if ( _server.isRegistered( on ) ){
_server.unregisterMBean( on );
- Bytes.LOGGER.log( Level.INFO , "multiple Mongo instances for same host, jmx numbers might be off" );
+ LOGGER.log( Level.INFO , "multiple Mongo instances for same host, jmx numbers might be off" );
}
_server.registerMBean( p , on );
}
catch ( JMException e ){
- Bytes.LOGGER.log( Level.WARNING , "jmx registration error: " + e + " continuing..." );
+ LOGGER.log( Level.WARNING , "jmx registration error: " + e + " continuing..." );
}
catch ( java.security.AccessControlException e ){
- Bytes.LOGGER.log( Level.WARNING , "jmx registration error: " + e + " continuing..." );
+ LOGGER.log( Level.WARNING , "jmx registration error: " + e + " continuing..." );
}
}
@@ -101,7 +104,7 @@ void close(){
_server.unregisterMBean( on );
}
} catch ( JMException e ){
- Bytes.LOGGER.log( Level.WARNING , "jmx de-registration error, continuing" , e );
+ LOGGER.log( Level.WARNING , "jmx de-registration error, continuing" , e );
}
}
}
@@ -201,7 +204,7 @@ void gotError( Exception e ){
// we don't want to clear the port pool for a connection timing out
return;
}
- Bytes.LOGGER.log( Level.WARNING , "emptying DBPortPool to " + getServerAddress() + " b/c of error" , e );
+ LOGGER.log( Level.WARNING , "emptying DBPortPool to " + getServerAddress() + " b/c of error" , e );
// force close all sockets
View
10 src/main/com/mongodb/DBTCPConnector.java
@@ -32,17 +32,17 @@
public class DBTCPConnector implements DBConnector {
- static Logger _logger = Logger.getLogger( Bytes.LOGGER.getName() + ".tcp" );
+ static Logger _logger = Logger.getLogger( DBTCPConnector.class.getCanonicalName());
static Logger _createLogger = Logger.getLogger( _logger.getName() + ".connect" );
public DBTCPConnector( Mongo m , ServerAddress addr )
throws MongoException {
_mongo = m;
_portHolder = new DBPortPool.Holder( m._options );
_checkAddress( addr );
-
- _createLogger.info( addr.toString() );
-
+
+ _logger.info("init " + addr.toString());
+
_set( addr );
_allHosts = null;
_rsStatus = null;
@@ -62,7 +62,7 @@ public DBTCPConnector( Mongo m , List<ServerAddress> all )
_allHosts = new ArrayList<ServerAddress>( all ); // make a copy so it can't be modified
_rsStatus = new ReplicaSetStatus( m, _allHosts );
- _createLogger.info( all + " -> " + getAddress() );
+ _logger.info( "init with list of addresses" + all + " -> " + getAddress() );
}
public void start() {
View
2 src/main/com/mongodb/DefaultDBCallback.java
@@ -137,5 +137,5 @@ public void reset(){
private String _lastName;
final DBCollection _collection;
final DB _db;
- static final Logger LOGGER = Logger.getLogger( "com.mongo.DECODING" );
+ static final Logger LOGGER = Logger.getLogger( DefaultDBCallback.class.getCanonicalName() );
}
View
2 src/main/com/mongodb/LazyDBCallback.java
@@ -51,5 +51,5 @@ public Object createDBRef( String ns, ObjectId id ){
final DBCollection _collection;
final DB _db;
- private static final Logger log = Logger.getLogger( LazyDBCallback.class.getName() );
+ private static final Logger log = Logger.getLogger( LazyDBCallback.class.getCanonicalName() );
}
View
2 src/main/com/mongodb/LazyWriteableDBCallback.java
@@ -41,5 +41,5 @@ public Object createObject( byte[] data, int offset ){
return o;
}
- private static final Logger log = Logger.getLogger( LazyWriteableDBCallback.class.getName() );
+ private static final Logger log = Logger.getLogger( LazyWriteableDBCallback.class.getCanonicalName() );
}
View
2 src/main/com/mongodb/MongoURI.java
@@ -281,7 +281,7 @@ public DBCollection connectCollection( Mongo m ){
final String _uri;
- static final Logger LOGGER = Logger.getLogger( "com.mongodb.MongoURI" );
+ static final Logger LOGGER = Logger.getLogger( MongoURI.class.getCanonicalName() );
@Override
public String toString() {
View
2 src/main/com/mongodb/ReplicaSetStatus.java
@@ -49,7 +49,7 @@
*/
public class ReplicaSetStatus {
- static final Logger _rootLogger = Logger.getLogger( "com.mongodb.ReplicaSetStatus" );
+ static final Logger _rootLogger = Logger.getLogger( ReplicaSetStatus.class.getCanonicalName() );
static final int UNAUTHENTICATED_ERROR_CODE = 10057;
ReplicaSetStatus( Mongo mongo, List<ServerAddress> initial ){
View
2 src/main/org/bson/BSON.java
@@ -30,7 +30,7 @@
public class BSON {
- static final Logger LOGGER = Logger.getLogger( "org.bson.BSON" );
+ static final Logger LOGGER = Logger.getLogger( BSON.class.getCanonicalName() );
// ---- basics ----
View
2 src/main/org/bson/LazyBSONCallback.java
@@ -81,5 +81,5 @@ public Object createDBRef( String ns, ObjectId id ){
}
}*/
private Object _root;
- private static final Logger log = Logger.getLogger( "org.bson.LazyBSONCallback" );
+ private static final Logger log = Logger.getLogger( LazyBSONCallback.class.getCanonicalName() );
}
View
2 src/main/org/bson/LazyBSONDecoder.java
@@ -26,7 +26,7 @@
* implementation of BSONDecoder that creates LazyBSONObject instances
*/
public class LazyBSONDecoder implements BSONDecoder {
- static final Logger LOG = Logger.getLogger( LazyBSONDecoder.class.getName() );
+ static final Logger LOG = Logger.getLogger( LazyBSONDecoder.class.getCanonicalName() );
public BSONObject readObject(byte[] b) {
try {
View
2 src/main/org/bson/LazyBSONObject.java
@@ -475,5 +475,5 @@ public String toString(){
protected final BSONByteBuffer _input; // TODO - Guard this with synchronicity?
// callback is kept to create sub-objects on the fly
protected final LazyBSONCallback _callback;
- private static final Logger log = Logger.getLogger( "org.bson.LazyBSONObject" );
+ private static final Logger log = Logger.getLogger( LazyBSONObject.class.getCanonicalName() );
}
View
2 src/main/org/bson/io/BSONByteBuffer.java
@@ -289,7 +289,7 @@ static void _fillRange( byte min, byte max ){
_fillRange( (byte) 'A', (byte) 'Z' );
}
- private static final Logger log = Logger.getLogger( "org.bson.io.BSONByteBuffer" );
+ private static final Logger log = Logger.getLogger( BSONByteBuffer.class.getCanonicalName() );
}
View
2 src/main/org/bson/types/ObjectId.java
@@ -42,7 +42,7 @@
private static final long serialVersionUID = -4415279469780082174L;
- static final Logger LOGGER = Logger.getLogger( "org.bson.ObjectId" );
+ static final Logger LOGGER = Logger.getLogger( ObjectId.class.getCanonicalName());
/** Gets a new object id.
* @return the new id
View
9 src/test/com/mongodb/DBCursorTest.java
@@ -16,14 +16,11 @@
package com.mongodb;
-import java.io.IOException;
-import java.util.Iterator;
-
-import java.util.logging.Level;
-import java.util.logging.Logger;
+import com.mongodb.util.TestCase;
import org.testng.annotations.Test;
-import com.mongodb.util.TestCase;
+import java.io.IOException;
+import java.util.Iterator;
public class DBCursorTest extends TestCase {