[grid] Avoiding duplicate code in LoggingOptions [skip ci]
@@ -200,28 +200,20 @@ public void configureLogging() {
String encoding = getLogEncoding();
if (isUsingPlainLogs()) {
- String message;
Handler handler = new FlushingHandler(out);
handler.setFormatter(new TerseFormatter());
- try {
- if (encoding != null) {
- handler.setEncoding(encoding);
- message = String.format("Using encoding %s", encoding);
- } else {
- message = "Using the system default encoding";
- }
- } catch (UnsupportedEncodingException e) {
- message =
- String.format("Using the system default encoding. Unsupported encoding %s", encoding);
- }
- logger.addHandler(handler);
- logger.log(Level.INFO, message);
+ configureLogEncoding(logger, encoding, handler);
}
if (isUsingStructuredLogging()) {
- String message;
Handler handler = new FlushingHandler(out);
handler.setFormatter(new JsonFormatter());
+ configureLogEncoding(logger, encoding, handler);
+ }
+ }
+
+ private void configureLogEncoding(Logger logger, String encoding, Handler handler) {
+ String message;
try {
if (encoding != null) {
handler.setEncoding(encoding);
@@ -236,7 +228,6 @@ public void configureLogging() {
logger.addHandler(handler);
logger.log(Level.INFO, message);
}
- }
private OutputStream getOutputStream() {
return config.get(LOGGING_SECTION, "log-file")
