@@ -48,6 +48,7 @@ public final class BigQueryJdbcResultSetLogger {
4848
4949 private final BigQueryJdbcCustomLogger delegate ;
5050 private final String targetClassName ;
51+ private final ConnectionLogContext connectionContext ;
5152 private final String connectionId ;
5253
5354 private volatile BigQueryJdbcResultSetLogger arrowStructLogger ;
@@ -56,25 +57,36 @@ public final class BigQueryJdbcResultSetLogger {
5657 private volatile BigQueryJdbcResultSetLogger jsonArrayLogger ;
5758
5859 private BigQueryJdbcResultSetLogger (
59- BigQueryJdbcCustomLogger delegate , String targetClassName , String connectionId ) {
60+ BigQueryJdbcCustomLogger delegate ,
61+ String targetClassName ,
62+ ConnectionLogContext connectionContext ) {
6063 this .delegate = delegate ;
6164 this .targetClassName = targetClassName ;
62- this .connectionId = connectionId ;
65+ this .connectionContext = connectionContext ;
66+ this .connectionId = connectionContext != null ? connectionContext .connectionId () : null ;
6367 }
6468
6569 public static BigQueryJdbcResultSetLogger getLogger (Class <?> clazz ) {
66- return getLogger (clazz , null );
70+ return getLogger (clazz , ( ConnectionLogContext ) null );
6771 }
6872
6973 public static BigQueryJdbcResultSetLogger getLogger (Class <?> clazz , String connectionId ) {
74+ if (connectionId == null || connectionId .isEmpty ()) {
75+ return getLogger (clazz , (ConnectionLogContext ) null );
76+ }
77+ return getLogger (clazz , new ConnectionLogContext (connectionId , ConnectionLogContext .ALL_VALUE ));
78+ }
79+
80+ static BigQueryJdbcResultSetLogger getLogger (
81+ Class <?> clazz , ConnectionLogContext connectionContext ) {
7082 String className = clazz .getName ();
7183 BigQueryJdbcCustomLogger delegate =
7284 DELEGATES .computeIfAbsent (className , BigQueryJdbcCustomLogger ::new );
73- if (connectionId == null ) {
85+ if (connectionContext == null ) {
7486 return GLOBAL_FACADES .computeIfAbsent (
7587 className , k -> new BigQueryJdbcResultSetLogger (delegate , k , null ));
7688 }
77- return new BigQueryJdbcResultSetLogger (delegate , className , connectionId );
89+ return new BigQueryJdbcResultSetLogger (delegate , className , connectionContext );
7890 }
7991
8092 public String getConnectionId () {
@@ -92,46 +104,49 @@ public boolean isLoggable(Level level) {
92104
93105 public BigQueryJdbcResultSetLogger getArrowStructLogger () {
94106 if (arrowStructLogger == null ) {
95- arrowStructLogger = getLogger (BigQueryArrowStruct .class , connectionId );
107+ arrowStructLogger = getLogger (BigQueryArrowStruct .class , connectionContext );
96108 }
97109 return arrowStructLogger ;
98110 }
99111
100112 public BigQueryJdbcResultSetLogger getJsonStructLogger () {
101113 if (jsonStructLogger == null ) {
102- jsonStructLogger = getLogger (BigQueryJsonStruct .class , connectionId );
114+ jsonStructLogger = getLogger (BigQueryJsonStruct .class , connectionContext );
103115 }
104116 return jsonStructLogger ;
105117 }
106118
107119 public BigQueryJdbcResultSetLogger getArrowArrayLogger () {
108120 if (arrowArrayLogger == null ) {
109- arrowArrayLogger = getLogger (BigQueryArrowArray .class , connectionId );
121+ arrowArrayLogger = getLogger (BigQueryArrowArray .class , connectionContext );
110122 }
111123 return arrowArrayLogger ;
112124 }
113125
114126 public BigQueryJdbcResultSetLogger getJsonArrayLogger () {
115127 if (jsonArrayLogger == null ) {
116- jsonArrayLogger = getLogger (BigQueryJsonArray .class , connectionId );
128+ jsonArrayLogger = getLogger (BigQueryJsonArray .class , connectionContext );
117129 }
118130 return jsonArrayLogger ;
119131 }
120132
121133 /**
122- * Stamps the connection ID into {@code params[0]} and forwards to the shared logger. Does not
123- * touch the record's source class/method: hot-path callers set them explicitly, and cold-path
124- * callers ({@code severe}, {@code warning}) rely on {@link
134+ * Stamps the {@link ConnectionLogContext} into {@code params[0]} and forwards to the shared
135+ * logger. Does not touch the record's source class/method: hot-path callers set them explicitly,
136+ * and cold-path callers ({@code severe}, {@code warning}) rely on {@link
125137 * BigQueryJdbcCustomLogger.BigQueryJdbcLogRecord} to infer them lazily.
126138 */
127139 public void log (LogRecord record ) {
128- if (connectionId != null ) {
140+ if (record == null ) {
141+ return ;
142+ }
143+ if (connectionContext != null ) {
129144 Object [] existingParams = record .getParameters ();
130145 if (existingParams == null || existingParams .length == 0 ) {
131- record .setParameters (new Object [] {connectionId });
132- } else {
146+ record .setParameters (new Object [] {connectionContext });
147+ } else if (!( existingParams [ 0 ] instanceof ConnectionLogContext )) {
133148 Object [] newParams = new Object [existingParams .length + 1 ];
134- newParams [0 ] = connectionId ;
149+ newParams [0 ] = connectionContext ;
135150 System .arraycopy (existingParams , 0 , newParams , 1 , existingParams .length );
136151 record .setParameters (newParams );
137152 }
0 commit comments