NekoX/TMessagesProj/src/main/java/org/telegram/messenger/FileLog.java

115 lines
3.4 KiB
Java
Raw Normal View History

2013-12-20 20:25:49 +01:00
/*
2019-01-23 18:03:33 +01:00
* This is the source code of Telegram for Android v. 5.x.x.
2013-12-20 20:25:49 +01:00
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
2019-01-23 18:03:33 +01:00
* Copyright Nikolai Kudashov, 2013-2018.
2013-12-20 20:25:49 +01:00
*/
package org.telegram.messenger;
import android.util.Log;
2020-07-30 14:11:37 +02:00
import cn.hutool.core.util.StrUtil;
2018-07-30 04:07:02 +02:00
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.time.FastDateFormat;
2021-12-07 14:02:02 +01:00
import org.telegram.messenger.video.MediaCodecVideoConvertor;
2013-12-20 20:25:49 +01:00
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.util.Locale;
2020-06-25 17:28:24 +02:00
public class FileLog {
2018-07-30 04:07:02 +02:00
2015-10-29 18:10:07 +01:00
public static String getNetworkLogPath() {
2021-03-18 08:48:00 +01:00
if (BuildVars.DEBUG_PRIVATE_VERSION) return "/dev/null";
2015-10-29 18:10:07 +01:00
return "";
}
2020-06-25 17:28:24 +02:00
private static String mkTag() {
2020-07-30 14:11:37 +02:00
final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
2020-12-24 17:33:17 +01:00
return StrUtil.subAfter(stackTrace[4].getClassName(), ".", true);
2020-07-30 14:11:37 +02:00
2020-06-25 17:28:24 +02:00
}
private static String mkMessage(Throwable e) {
String message = e.getMessage();
2021-02-19 06:34:01 +01:00
if (message != null) return e.getClass().getSimpleName() + ": " + message;
2020-06-25 17:28:24 +02:00
return e.getClass().getSimpleName();
2019-12-31 14:08:08 +01:00
}
2017-03-31 01:58:05 +02:00
public static void e(final String message, final Throwable exception) {
2020-06-25 17:28:24 +02:00
Log.e(mkTag(), message, exception);
2013-12-20 20:25:49 +01:00
}
2017-03-31 01:58:05 +02:00
public static void e(final String message) {
2020-06-25 17:28:24 +02:00
Log.e(mkTag(), message);
2013-12-20 20:25:49 +01:00
}
2017-03-31 01:58:05 +02:00
public static void e(final Throwable e) {
2020-07-30 14:11:37 +02:00
Log.e(mkTag(), mkMessage(e), e);
2013-12-20 20:25:49 +01:00
}
2021-12-08 13:33:55 +01:00
public static void e(final Throwable e, boolean dummyException) {
e(e);
2013-12-20 20:25:49 +01:00
}
2022-09-16 20:48:21 +02:00
public static void fatal(final Throwable e) {
fatal(e, true);
}
public static void fatal(final Throwable e, boolean logToAppCenter) {
if (!BuildVars.LOGS_ENABLED) {
return;
}
if (BuildVars.DEBUG_VERSION && needSent(e) && logToAppCenter) {
AndroidUtilities.appCenterLog(e);
}
ensureInitied();
e.printStackTrace();
if (getInstance().streamWriter != null) {
getInstance().logQueue.postRunnable(() -> {
try {
getInstance().streamWriter.write(getInstance().dateFormat.format(System.currentTimeMillis()) + " E/tmessages: " + e + "\n");
StackTraceElement[] stack = e.getStackTrace();
for (int a = 0; a < stack.length; a++) {
getInstance().streamWriter.write(getInstance().dateFormat.format(System.currentTimeMillis()) + " E/tmessages: " + stack[a] + "\n");
}
getInstance().streamWriter.flush();
} catch (Exception e1) {
e1.printStackTrace();
}
if (BuildVars.DEBUG_PRIVATE_VERSION) {
System.exit(2);
}
});
} else {
e.printStackTrace();
if (BuildVars.DEBUG_PRIVATE_VERSION) {
System.exit(2);
}
}
}
2021-12-07 14:02:02 +01:00
private static boolean needSent(Throwable e) {
if (e instanceof InterruptedException || e instanceof MediaCodecVideoConvertor.ConversionCanceledException) {
return false;
}
return true;
}
2017-03-31 01:58:05 +02:00
public static void d(final String message) {
2020-06-25 17:28:24 +02:00
if (!BuildVars.LOGS_ENABLED) return;
Log.d(mkTag(), message);
2013-12-20 20:25:49 +01:00
}
2017-03-31 01:58:05 +02:00
public static void w(final String message) {
2020-06-25 17:28:24 +02:00
if (!BuildVars.LOGS_ENABLED) return;
Log.w(mkTag(), message);
2015-02-01 19:51:02 +01:00
}
2013-12-20 20:25:49 +01:00
}