2018-01-28 11:58:33 +01:00
|
|
|
//
|
2022-01-01 01:35:39 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
|
2018-01-28 11:58:33 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
package org.drinkless.tdlib;
|
|
|
|
|
|
|
|
/**
|
2019-03-06 20:19:45 +01:00
|
|
|
* Class used for managing internal TDLib logging.
|
|
|
|
* Use TdApi.*Log* methods instead.
|
2018-01-28 11:58:33 +01:00
|
|
|
*/
|
|
|
|
public final class Log {
|
|
|
|
/**
|
|
|
|
* Changes TDLib log verbosity.
|
|
|
|
*
|
2019-03-06 20:19:45 +01:00
|
|
|
* @deprecated As of TDLib 1.4.0 in favor of {@link TdApi.SetLogVerbosityLevel}, to be removed in the future.
|
2018-01-28 11:58:33 +01:00
|
|
|
* @param verbosityLevel New value of log verbosity level. Must be non-negative.
|
|
|
|
* Value 0 corresponds to fatal errors,
|
|
|
|
* value 1 corresponds to java.util.logging.Level.SEVERE,
|
|
|
|
* value 2 corresponds to java.util.logging.Level.WARNING,
|
|
|
|
* value 3 corresponds to java.util.logging.Level.INFO,
|
|
|
|
* value 4 corresponds to java.util.logging.Level.FINE,
|
|
|
|
* value 5 corresponds to java.util.logging.Level.FINER,
|
|
|
|
* value greater than 5 can be used to enable even more logging.
|
|
|
|
* Default value of the log verbosity level is 5.
|
|
|
|
*/
|
2019-03-06 20:19:45 +01:00
|
|
|
@Deprecated
|
2018-01-28 11:58:33 +01:00
|
|
|
public static native void setVerbosityLevel(int verbosityLevel);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets file path for writing TDLib internal log. By default TDLib writes logs to the System.err.
|
|
|
|
* Use this method to write the log to a file instead.
|
|
|
|
*
|
2019-03-06 20:19:45 +01:00
|
|
|
* @deprecated As of TDLib 1.4.0 in favor of {@link TdApi.SetLogStream}, to be removed in the future.
|
2018-01-28 11:58:33 +01:00
|
|
|
* @param filePath Path to a file for writing TDLib internal log. Use an empty path to
|
|
|
|
* switch back to logging to the System.err.
|
2018-03-15 17:25:51 +01:00
|
|
|
* @return whether opening the log file succeeded.
|
2018-01-28 11:58:33 +01:00
|
|
|
*/
|
2019-03-06 20:19:45 +01:00
|
|
|
@Deprecated
|
2018-01-28 17:38:59 +01:00
|
|
|
public static native boolean setFilePath(String filePath);
|
2018-01-28 11:58:33 +01:00
|
|
|
|
|
|
|
/**
|
2020-01-06 19:44:09 +01:00
|
|
|
* Changes the maximum size of TDLib log file.
|
2018-01-28 11:58:33 +01:00
|
|
|
*
|
2019-03-06 20:19:45 +01:00
|
|
|
* @deprecated As of TDLib 1.4.0 in favor of {@link TdApi.SetLogStream}, to be removed in the future.
|
2020-01-06 19:44:09 +01:00
|
|
|
* @param maxFileSize The maximum size of the file to where the internal TDLib log is written
|
2018-01-28 11:58:33 +01:00
|
|
|
* before the file will be auto-rotated. Must be positive. Defaults to 10 MB.
|
|
|
|
*/
|
2019-03-06 20:19:45 +01:00
|
|
|
@Deprecated
|
2018-01-28 11:58:33 +01:00
|
|
|
public static native void setMaxFileSize(long maxFileSize);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function is called from the JNI when a fatal error happens to provide a better error message.
|
|
|
|
* The function does not return.
|
|
|
|
*
|
|
|
|
* @param errorMessage Error message.
|
|
|
|
*/
|
|
|
|
private static void onFatalError(String errorMessage) {
|
|
|
|
class ThrowError implements Runnable {
|
|
|
|
private ThrowError(String errorMessage) {
|
|
|
|
this.errorMessage = errorMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
throw new RuntimeException("TDLib fatal error: " + errorMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
private final String errorMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
new Thread(new ThrowError(errorMessage), "TDLib fatal error thread").start();
|
|
|
|
while (true) {
|
|
|
|
try {
|
|
|
|
Thread.sleep(1000); // milliseconds
|
|
|
|
} catch (InterruptedException ex) {
|
|
|
|
Thread.currentThread().interrupt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|