Skip to content

Commit 9c9eaf0

Browse files
committed
Stronger guard against trace logging in VertxContext
1 parent 358e9bf commit 9c9eaf0

File tree

1 file changed

+10
-9
lines changed
  • hibernate-reactive-core/src/main/java/org/hibernate/reactive/context/impl

1 file changed

+10
-9
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/context/impl/VertxContext.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
public class VertxContext implements Context, ServiceRegistryAwareService {
2626

2727
private static final Log LOG = LoggerFactory.make( Log.class, MethodHandles.lookup() );
28+
private static final boolean trace = LOG.isTraceEnabled();
2829

2930
private VertxInstance vertxInstance;
3031

@@ -37,11 +38,11 @@ public void injectServices(ServiceRegistryImplementor serviceRegistry) {
3738
public <T> void put(Key<T> key, T instance) {
3839
final io.vertx.core.Context context = Vertx.currentContext();
3940
if ( context != null ) {
40-
LOG.tracef( "Putting key,value in context: [%1$s, %2$s]", key, instance );
41+
if ( trace ) LOG.tracef( "Putting key,value in context: [%1$s, %2$s]", key, instance );
4142
context.putLocal( key, instance );
4243
}
4344
else {
44-
LOG.tracef( "Context is null for key,value: [%1$s, %2$s]", key, instance );
45+
if ( trace ) LOG.tracef( "Context is null for key,value: [%1$s, %2$s]", key, instance );
4546
throw LOG.notVertxContextActive();
4647
}
4748
}
@@ -51,11 +52,11 @@ public <T> T get(Key<T> key) {
5152
final io.vertx.core.Context context = Vertx.currentContext();
5253
if ( context != null ) {
5354
T local = context.getLocal( key );
54-
LOG.tracef( "Getting value %2$s from context for key %1$s", key, local );
55+
if ( trace ) LOG.tracef( "Getting value %2$s from context for key %1$s", key, local );
5556
return local;
5657
}
5758
else {
58-
LOG.tracef( "Context is null. Returning null for key %s", key );
59+
if ( trace ) LOG.tracef( "Context is null. Returning null for key %s", key );
5960
return null;
6061
}
6162
}
@@ -65,28 +66,28 @@ public void remove(Key<?> key) {
6566
final io.vertx.core.Context context = Vertx.currentContext();
6667
if ( context != null ) {
6768
boolean removed = context.removeLocal( key );
68-
LOG.tracef( "Key %s removed from context: %s", key, removed );
69+
if ( trace ) LOG.tracef( "Key %s removed from context: %s", key, removed );
6970
}
7071
else {
71-
LOG.tracef( "Context is null, nothing to remove for key %s", key );
72+
if ( trace ) LOG.tracef( "Context is null, nothing to remove for key %s", key );
7273
}
7374
}
7475

7576
@Override
7677
public void execute(Runnable runnable) {
7778
final io.vertx.core.Context currentContext = Vertx.currentContext();
7879
if ( currentContext == null ) {
79-
LOG.tracef( "Not in a Vert.x context, checking the VertxInstance service" );
80+
if ( trace ) LOG.tracef( "Not in a Vert.x context, checking the VertxInstance service" );
8081
final io.vertx.core.Context newContext = vertxInstance.getVertx().getOrCreateContext();
8182
// Ensure we don't run on the root context, which is globally scoped:
8283
// that could lead to unintentionally share the same session with other streams.
8384
ContextInternal newContextInternal = (ContextInternal) newContext;
8485
final ContextInternal duplicate = newContextInternal.duplicate();
85-
LOG.tracef( "Using duplicated context from VertxInstance: %s", duplicate );
86+
if ( trace ) LOG.tracef( "Using duplicated context from VertxInstance: %s", duplicate );
8687
duplicate.runOnContext( x -> runnable.run() );
8788
}
8889
else {
89-
LOG.tracef( "Running in the current Vert.x context %s", currentContext );
90+
if ( trace ) LOG.tracef( "Running in the current Vert.x context %s", currentContext );
9091
runnable.run();
9192
}
9293
}

0 commit comments

Comments
 (0)