2022-03-07 09:34:54 +00:00
|
|
|
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;
|
2022-03-23 22:37:04 +00:00
|
|
|
/* loaded from: com.discord-120110.apk:lombok/core/debug/AssertionLogger.SCL.lombok */
|
2022-03-07 09:34:54 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|