Skip to content

Commit

Permalink
Reduce code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
RetGal committed Nov 13, 2023
1 parent a718202 commit 7430bf4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/main/java/mpo/dayon/common/log/LogAppender.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package mpo.dayon.common.log;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.Date;

public abstract class LogAppender {
private final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss.SSS");
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("HH:mm:ss.SSS");

protected String format(LogLevel level, String message) {
message = (message == null) ? "" : message;
return String.format("[%20.20s] [%5.5s] (%s) %s", Thread.currentThread().getName(), level,
dateFormat.format(Date.from(Instant.now())), message);
DATE_FORMAT.format(Date.from(Instant.now())), message);
}

public void append(LogLevel level, String message) {
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/mpo/dayon/common/monitoring/BigBrother.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@
import mpo.dayon.common.monitoring.counter.Counter;

public final class BigBrother {
private static final BigBrother INSTANCE = new BigBrother();

private final Timer timer = new Timer("BigBrother");

private BigBrother() {
}

private static class Helper {
private static final BigBrother INSTANCE = new BigBrother();
}

public static BigBrother get() {
return INSTANCE;
return Helper.INSTANCE;
}

private final Timer timer = new Timer("BigBrother");

/**
* @param instantRatePeriod millis
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mpo/dayon/common/utils/SystemUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static String getSystemPropertiesEx() {
public static String getRamInfo() {
final double freeMG = Runtime.getRuntime().freeMemory();
final double totalMG = Runtime.getRuntime().totalMemory();
return UnitUtilities.toByteSize(totalMG - freeMG, false) + " of " + UnitUtilities.toByteSize(totalMG, false);
return format("%s of %s", UnitUtilities.toByteSize(totalMG - freeMG, false), UnitUtilities.toByteSize(totalMG, false));
}

public static void safeClose(Closeable... closeables) {
Expand Down

0 comments on commit 7430bf4

Please sign in to comment.