Skip to content

Commit a55d172

Browse files
committed
JAVA-2852: Log failure to get machine or process id at debug
The ObjectId class logs its failure to get either the machine identifer, from NetworkInterface#getNetworkInterfaces, or the process identifier, from JMX, at warning level, and includes the stack trace. This is annoying for applications running on platforms where this occurs (e.g. IBM JRE or Android's Dalvik), as it appears in the logs on every application startup, there's no workaround, and the fallback behavior of using SecureRandom is not a cause for concern. This commit removes the stack trace from the log message and changes the level from warn to debug
1 parent a6ea587 commit a55d172

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

bson/src/main/org/bson/types/ObjectId.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,9 @@ private static int createMachineIdentifier() {
516516
}
517517
machinePiece = sb.toString().hashCode();
518518
} catch (Throwable t) {
519-
// exception sometimes happens with IBM JVM, use random
519+
// exception sometimes happens with IBM JVM, use SecureRandom instead
520520
machinePiece = (new SecureRandom().nextInt());
521-
LOGGER.warn("Failed to get machine identifier from network interface, using random number instead", t);
521+
LOGGER.debug("Failed to get machine identifier from network interface, using SecureRandom instead");
522522
}
523523
machinePiece = machinePiece & LOW_ORDER_THREE_BYTES;
524524
return machinePiece;
@@ -537,8 +537,9 @@ private static short createProcessIdentifier() {
537537
}
538538

539539
} catch (Throwable t) {
540+
// JMX not available on Android, use SecureRandom instead
540541
processId = (short) new SecureRandom().nextInt();
541-
LOGGER.warn("Failed to get process identifier from JMX, using random number instead", t);
542+
LOGGER.debug("Failed to get process identifier from JMX, using SecureRandom instead");
542543
}
543544

544545
return processId;

0 commit comments

Comments
 (0)