Adjust the default capability to reduce memory allocation
This commit is contained in:
@@ -17,6 +17,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hmcl.util;
|
package org.jackhuang.hmcl.util;
|
||||||
|
|
||||||
|
import org.jackhuang.hmcl.util.io.IOUtils;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
@@ -34,7 +36,7 @@ public final class Logging {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final Logger LOG = Logger.getLogger("HMCL");
|
public static final Logger LOG = Logger.getLogger("HMCL");
|
||||||
private static ByteArrayOutputStream storedLogs = new ByteArrayOutputStream();
|
private static final ByteArrayOutputStream storedLogs = new ByteArrayOutputStream(IOUtils.DEFAULT_BUFFER_SIZE);
|
||||||
|
|
||||||
public static void start(Path logFolder) {
|
public static void start(Path logFolder) {
|
||||||
LOG.setLevel(Level.ALL);
|
LOG.setLevel(Level.ALL);
|
||||||
@@ -100,7 +102,7 @@ public final class Logging {
|
|||||||
new Date(record.getMillis()),
|
new Date(record.getMillis()),
|
||||||
record.getSourceClassName(), record.getSourceMethodName(), record.getLevel().getName(),
|
record.getSourceClassName(), record.getSourceMethodName(), record.getLevel().getName(),
|
||||||
record.getMessage()
|
record.getMessage()
|
||||||
});
|
}, new StringBuffer(128), null).toString();
|
||||||
if (record.getThrown() != null)
|
if (record.getThrown() != null)
|
||||||
log += StringUtils.getStackTrace(record.getThrown());
|
log += StringUtils.getStackTrace(record.getThrown());
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public final class StringUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getStackTrace(Throwable throwable) {
|
public static String getStackTrace(Throwable throwable) {
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream(512);
|
||||||
try {
|
try {
|
||||||
throwable.printStackTrace(new PrintStream(stream, false, "UTF-8"));
|
throwable.printStackTrace(new PrintStream(stream, false, "UTF-8"));
|
||||||
return stream.toString("UTF-8");
|
return stream.toString("UTF-8");
|
||||||
|
|||||||
Reference in New Issue
Block a user