Ref: simplify getInstance, do not put context on a singleton
This commit is contained in:
@@ -19,6 +19,8 @@
|
||||
|
||||
package com.sheepit.client;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
@@ -43,7 +45,7 @@ public final class Log {
|
||||
public final int MAX_SIZE = 10000000; // in B
|
||||
public final int PERIOD = 3600000; // duration in ms between two shrink
|
||||
|
||||
private static Log instance = null;
|
||||
@Getter private static Log instance = null;
|
||||
|
||||
private Map<Integer, List<String>> checkpoints = new HashMap<>();
|
||||
private int lastCheckPoint;
|
||||
@@ -170,24 +172,21 @@ public final class Log {
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized Log getInstance(Configuration config) {
|
||||
if (instance == null) {
|
||||
String path = null;
|
||||
boolean print = false;
|
||||
boolean debug = false;
|
||||
if (config != null) {
|
||||
debug = config.isDebugLevel();
|
||||
print = config.isPrintLog();
|
||||
path = config.getLogDirectory() == null ? null : config.getLogDirectory();
|
||||
}
|
||||
|
||||
instance = new Log(debug, print, path);
|
||||
public static synchronized void setInstance(Configuration config) {
|
||||
String path = null;
|
||||
boolean print = false;
|
||||
boolean debug = false;
|
||||
if (config != null) {
|
||||
debug = config.isDebugLevel();
|
||||
print = config.isPrintLog();
|
||||
path = config.getLogDirectory() == null ? null : config.getLogDirectory();
|
||||
}
|
||||
return instance;
|
||||
|
||||
instance = new Log(debug, print, path);
|
||||
}
|
||||
|
||||
public static synchronized void printCheckPoint(int point_) {
|
||||
Log log = getInstance(null);
|
||||
Log log = getInstance();
|
||||
Optional<List<String>> logs = log.getForCheckPoint(point_);
|
||||
if (logs.isPresent()) {
|
||||
for (String alog : logs.get()) {
|
||||
|
||||
Reference in New Issue
Block a user