discord-jadx/app/src/main/java/lombok/core/debug/AssertionLogger.java

94 lines
3.1 KiB
Java

package lombok.core.debug;
import com.adjust.sdk.Constants;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Date;
import java.util.Random;
import java.util.concurrent.atomic.AtomicBoolean;
import lombok.core.Version;
/* loaded from: com.discord-118107.apk:lombok/core/debug/AssertionLogger.SCL.lombok */
public class AssertionLogger {
private static final String LOG_PATH;
private static final AtomicBoolean loggedIntro;
private static final String PROCESS_ID;
private static final String ID_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
static {
String str;
String property = System.getProperty("lombok.assertion.log", null);
if (property != null) {
LOG_PATH = property.isEmpty() ? null : property;
} else {
try {
str = System.getenv("LOMBOK_ASSERTION_LOG");
} catch (Exception unused) {
str = null;
}
LOG_PATH = (str == null || str.isEmpty()) ? null : str;
}
loggedIntro = new AtomicBoolean(false);
PROCESS_ID = generateProcessId();
}
private static String generateProcessId() {
char[] cArr = new char[4];
Random random = new Random();
for (int i = 0; i < cArr.length; i++) {
cArr[i] = ID_CHARS.charAt(random.nextInt(ID_CHARS.length()));
}
return new String(cArr);
}
private static synchronized void logToFile(String str) {
if (str != null) {
try {
FileOutputStream fileOutputStream = new FileOutputStream(LOG_PATH, true);
fileOutputStream.write(str.getBytes(Constants.ENCODING));
fileOutputStream.close();
} catch (Exception e) {
throw new RuntimeException("assertion logging can't write to log file", e);
}
}
}
private static void logIntro() {
String str;
if (!loggedIntro.getAndSet(true)) {
try {
str = Version.getFullVersion();
} catch (Exception unused) {
str = Version.getVersion();
}
logToFile(String.format("{%s} [%s -- START %s]\n", PROCESS_ID, new Date(), str));
}
}
public static <T extends Throwable> T assertLog(String str, T t) {
StringWriter stringWriter;
if (LOG_PATH == null) {
return t;
}
logIntro();
if (str == null) {
str = "(No message)";
}
String str2 = "";
if (t != null) {
PrintWriter printWriter = new PrintWriter(new StringWriter());
t.printStackTrace(printWriter);
printWriter.close();
str2 = "\n " + stringWriter.toString().replace("\r", "").replace("\n", "\n ").trim();
}
logToFile(String.format("{%s} [%ty%<tm%<tdT%<tH%<tM%<tS.%<tL] %s%s\n", PROCESS_ID, new Date(), str, str2));
return t;
}
public static void assertLog(String str) {
if (LOG_PATH != null) {
assertLog(str, null);
}
}
}