Skip to content

Commit 5a856d7

Browse files
committed
replace printStackTrace with logger
1 parent 8625fe9 commit 5a856d7

3 files changed

Lines changed: 20 additions & 17 deletions

File tree

src/main/java/app/attestation/server/AlertDispatcher.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import jakarta.mail.internet.MimeMessage;
1616

1717
import java.util.ArrayList;
18+
import java.util.logging.Level;
1819
import java.util.logging.Logger;
1920
import java.util.Properties;
2021

@@ -172,7 +173,7 @@ protected PasswordAuthentication getPasswordAuthentication() {
172173
updateExpired.reset();
173174
}
174175
} catch (final MessagingException e) {
175-
e.printStackTrace();
176+
logger.log(Level.WARNING, "email error", e);
176177
}
177178
}
178179
selectEmails.reset();
@@ -205,14 +206,14 @@ protected PasswordAuthentication getPasswordAuthentication() {
205206

206207
Transport.send(message);
207208
} catch (final MessagingException e) {
208-
e.printStackTrace();
209+
logger.log(Level.WARNING, "email error", e);
209210
}
210211
}
211212
selectEmails.reset();
212213
}
213214
}
214215
} catch (final SQLiteException e) {
215-
e.printStackTrace();
216+
logger.log(Level.WARNING, "database error", e);
216217
} finally {
217218
try {
218219
selectConfiguration.reset();
@@ -222,7 +223,7 @@ protected PasswordAuthentication getPasswordAuthentication() {
222223
selectFailed.reset();
223224
selectEmails.reset();
224225
} catch (final SQLiteException e) {
225-
e.printStackTrace();
226+
logger.log(Level.WARNING, "database error", e);
226227
}
227228
}
228229
}

src/main/java/app/attestation/server/AttestationServer.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import java.util.Base64;
5151
import java.util.EnumMap;
5252
import java.util.List;
53+
import java.util.logging.Level;
5354
import java.util.logging.Logger;
5455
import java.util.Map;
5556
import java.util.concurrent.LinkedBlockingQueue;
@@ -369,7 +370,7 @@ public final void handle(final HttpExchange exchange) throws IOException {
369370
}
370371
handlePost(exchange);
371372
} catch (final Exception e) {
372-
e.printStackTrace();
373+
logger.log(Level.SEVERE, "unhandled error handling request", e);
373374
exchange.sendResponseHeaders(500, -1);
374375
} finally {
375376
exchange.close();
@@ -569,7 +570,7 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx
569570
username = object.getString("username");
570571
password = object.getString("password");
571572
} catch (final ClassCastException | JsonException | NullPointerException e) {
572-
e.printStackTrace();
573+
logger.log(Level.INFO, "invalid request", e);
573574
exchange.sendResponseHeaders(400, -1);
574575
return;
575576
}
@@ -580,7 +581,7 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx
580581
exchange.sendResponseHeaders(409, -1);
581582
return;
582583
} catch (final GeneralSecurityException e) {
583-
e.printStackTrace();
584+
logger.log(Level.INFO, "invalid request", e);
584585
exchange.sendResponseHeaders(400, -1);
585586
return;
586587
}
@@ -600,7 +601,7 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx
600601
currentPassword = object.getString("currentPassword");
601602
newPassword = object.getString("newPassword");
602603
} catch (final ClassCastException | JsonException | NullPointerException e) {
603-
e.printStackTrace();
604+
logger.log(Level.INFO, "invalid request", e);
604605
exchange.sendResponseHeaders(400, -1);
605606
return;
606607
}
@@ -613,7 +614,7 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx
613614
try {
614615
changePassword(account.userId, currentPassword, newPassword);
615616
} catch (final GeneralSecurityException e) {
616-
e.printStackTrace();
617+
logger.log(Level.INFO, "invalid request", e);
617618
exchange.sendResponseHeaders(400, -1);
618619
return;
619620
}
@@ -631,7 +632,7 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx
631632
username = object.getString("username");
632633
password = object.getString("password");
633634
} catch (final ClassCastException | JsonException | NullPointerException e) {
634-
e.printStackTrace();
635+
logger.log(Level.INFO, "invalid request", e);
635636
exchange.sendResponseHeaders(400, -1);
636637
return;
637638
}
@@ -643,7 +644,7 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx
643644
exchange.sendResponseHeaders(400, -1);
644645
return;
645646
} catch (final GeneralSecurityException e) {
646-
e.printStackTrace();
647+
logger.log(Level.INFO, "invalid login information", e);
647648
exchange.sendResponseHeaders(403, -1);
648649
return;
649650
}
@@ -917,7 +918,7 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx
917918
alertDelay = object.getInt("alertDelay");
918919
email = object.getString("email").trim();
919920
} catch (final ClassCastException | JsonException | NullPointerException e) {
920-
e.printStackTrace();
921+
logger.log(Level.INFO, "invalid request", e);
921922
exchange.sendResponseHeaders(400, -1);
922923
return;
923924
}
@@ -999,7 +1000,7 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx
9991000
requestToken = object.getString("requestToken");
10001001
fingerprint = object.getString("fingerprint");
10011002
} catch (final ClassCastException | JsonException | NullPointerException e) {
1002-
e.printStackTrace();
1003+
logger.log(Level.INFO, "invalid request", e);
10031004
exchange.sendResponseHeaders(400, -1);
10041005
return;
10051006
}
@@ -1168,7 +1169,7 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx
11681169
writeAttestationHistoryJson(exchange, fingerprint, account, offsetId);
11691170
} catch (final ClassCastException | JsonException | NullPointerException | NumberFormatException |
11701171
DataFormatException | GeneralSecurityException e) {
1171-
e.printStackTrace();
1172+
logger.log(Level.INFO, "invalid request", e);
11721173
exchange.sendResponseHeaders(400, -1);
11731174
return;
11741175
}
@@ -1300,7 +1301,7 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx
13001301
try {
13011302
AttestationProtocol.verifySerialized(attestationResult, pendingChallenges, userId, subscribeKey == null);
13021303
} catch (final BufferUnderflowException | NegativeArraySizeException | DataFormatException | GeneralSecurityException | IOException e) {
1303-
e.printStackTrace();
1304+
logger.log(Level.INFO, "invalid request", e);
13041305
final byte[] response = "Error\n".getBytes();
13051306
exchange.sendResponseHeaders(400, response.length);
13061307
try (final OutputStream output = exchange.getResponseBody()) {

src/main/java/app/attestation/server/Maintenance.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.almworks.sqlite4java.SQLiteStatement;
77

88
import java.io.File;
9+
import java.util.logging.Level;
910
import java.util.logging.Logger;
1011

1112
class Maintenance implements Runnable {
@@ -75,14 +76,14 @@ public void run() {
7576
}
7677
}
7778
} catch (final SQLiteException e) {
78-
e.printStackTrace();
79+
logger.log(Level.WARNING, "database error", e);
7980
} finally {
8081
try {
8182
deleteDeletedDevices.reset();
8283
selectBackups.reset();
8384
updateBackups.reset();
8485
} catch (final SQLiteException e) {
85-
e.printStackTrace();
86+
logger.log(Level.WARNING, "database error", e);
8687
}
8788
}
8889
}

0 commit comments

Comments
 (0)