Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: init debug log handler #234

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,8 @@

public class DatabendConnection implements Connection, FileTransferAPI, Consumer<DatabendSession> {
private static final Logger logger = Logger.getLogger(DatabendConnection.class.getPackage().getName());
private static final FileHandler FILE_HANDLER;
private static FileHandler FILE_HANDLER;

static {
try {
FILE_HANDLER = new FileHandler("databend-jdbc-debug.log");
FILE_HANDLER.setLevel(Level.ALL);
FILE_HANDLER.setFormatter(new SimpleFormatter());
logger.addHandler(FILE_HANDLER);
} catch (Exception e) {
throw new RuntimeException("Failed to create FileHandler", e);
}
}

private final AtomicBoolean closed = new AtomicBoolean();
private final AtomicBoolean autoCommit = new AtomicBoolean(true);
Expand All @@ -74,6 +64,19 @@ public class DatabendConnection implements Connection, FileTransferAPI, Consumer
private final DatabendDriverUri driverUri;
private AtomicReference<DatabendSession> session = new AtomicReference<>();

private void initializeFileHandler() {
if (this.debug()) {
try {
FILE_HANDLER = new FileHandler("databend-jdbc-debug.log");
FILE_HANDLER.setLevel(Level.ALL);
FILE_HANDLER.setFormatter(new SimpleFormatter());
logger.addHandler(FILE_HANDLER);
} catch (Exception e) {
throw new RuntimeException("Failed to create FileHandler", e);
}
}
}

DatabendConnection(DatabendDriverUri uri, OkHttpClient httpClient) throws SQLException {
requireNonNull(uri, "uri is null");
this.httpUri = uri.getUri();
Expand All @@ -82,6 +85,8 @@ public class DatabendConnection implements Connection, FileTransferAPI, Consumer
this.setSchema(uri.getDatabase());
DatabendSession session = new DatabendSession.Builder().setHost(this.getURI()).setDatabase(this.getSchema()).build();
this.setSession(session);

initializeFileHandler();
}

private static void checkResultSet(int resultSetType, int resultSetConcurrency)
Expand Down