Return whether Log::set_file_path succeded or not.
GitOrigin-RevId: a928f8691ebedfd7451bf8bd7957071786b50349
This commit is contained in:
parent
662471ea48
commit
a47d5d5511
@ -1,6 +1,6 @@
|
|||||||
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
|
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
|
||||||
|
|
||||||
project(TDLib VERSION 1.0.5 LANGUAGES CXX C)
|
project(TDLib VERSION 1.0.6 LANGUAGES CXX C)
|
||||||
|
|
||||||
option(TD_ENABLE_JNI "Use \"ON\" to enable JNI-compatible TDLib API.")
|
option(TD_ENABLE_JNI "Use \"ON\" to enable JNI-compatible TDLib API.")
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ target_link_libraries(YourTarget PRIVATE Td::TdStatic)
|
|||||||
|
|
||||||
Or you could install `TDLib` and then reference it in your CMakeLists.txt like this:
|
Or you could install `TDLib` and then reference it in your CMakeLists.txt like this:
|
||||||
```
|
```
|
||||||
find_package(Td 1.0.5 REQUIRED)
|
find_package(Td 1.0.6 REQUIRED)
|
||||||
target_link_libraries(YourTarget PRIVATE Td::TdStatic)
|
target_link_libraries(YourTarget PRIVATE Td::TdStatic)
|
||||||
```
|
```
|
||||||
See [example/cpp/CMakeLists.txt](https://github.com/tdlib/td/tree/master/example/cpp/CMakeLists.txt).
|
See [example/cpp/CMakeLists.txt](https://github.com/tdlib/td/tree/master/example/cpp/CMakeLists.txt).
|
||||||
|
@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
|
|||||||
|
|
||||||
project(TdExample VERSION 1.0 LANGUAGES CXX)
|
project(TdExample VERSION 1.0 LANGUAGES CXX)
|
||||||
|
|
||||||
find_package(Td 1.0.5 REQUIRED)
|
find_package(Td 1.0.6 REQUIRED)
|
||||||
|
|
||||||
add_executable(tdjson_example tdjson_example.cpp)
|
add_executable(tdjson_example tdjson_example.cpp)
|
||||||
target_link_libraries(tdjson_example PRIVATE Td::TdJson)
|
target_link_libraries(tdjson_example PRIVATE Td::TdJson)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required(VERSION 3.1)
|
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
|
||||||
|
|
||||||
project(TdJavaExample VERSION 1.0 LANGUAGES CXX)
|
project(TdJavaExample VERSION 1.0 LANGUAGES CXX)
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ endif()
|
|||||||
|
|
||||||
add_custom_target(td_generate_java_api
|
add_custom_target(td_generate_java_api
|
||||||
COMMAND ${GENERATE_JAVA_API_CMD}
|
COMMAND ${GENERATE_JAVA_API_CMD}
|
||||||
COMMENT "Generate Java TDLib API source files"
|
COMMENT "Generating Java TDLib API source files"
|
||||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/td/bin/td_generate_java_api ${TD_API_TLO_PATH} ${TD_API_TL_PATH} ${JAVADOC_TL_DOCUMENTATION_GENERATOR_PATH}
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/td/bin/td_generate_java_api ${TD_API_TLO_PATH} ${TD_API_TL_PATH} ${JAVADOC_TL_DOCUMENTATION_GENERATOR_PATH}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ get_filename_component(JAVA_OUTPUT_DIRECTORY ${CMAKE_INSTALL_PREFIX}/bin REALPAT
|
|||||||
file(MAKE_DIRECTORY ${JAVA_OUTPUT_DIRECTORY})
|
file(MAKE_DIRECTORY ${JAVA_OUTPUT_DIRECTORY})
|
||||||
add_custom_target(build_java
|
add_custom_target(build_java
|
||||||
COMMAND ${Java_JAVAC_EXECUTABLE} -d ${JAVA_OUTPUT_DIRECTORY} ${JAVA_SOURCE_PATH}/example/Example.java ${JAVA_SOURCE_PATH}/Client.java ${JAVA_SOURCE_PATH}/Log.java ${JAVA_SOURCE_PATH}/TdApi.java
|
COMMAND ${Java_JAVAC_EXECUTABLE} -d ${JAVA_OUTPUT_DIRECTORY} ${JAVA_SOURCE_PATH}/example/Example.java ${JAVA_SOURCE_PATH}/Client.java ${JAVA_SOURCE_PATH}/Log.java ${JAVA_SOURCE_PATH}/TdApi.java
|
||||||
COMMENT "Build Java code"
|
COMMENT "Building Java code"
|
||||||
DEPENDS td_generate_java_api
|
DEPENDS td_generate_java_api
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ set(JAVA_SOURCE_PATH "${TD_API_JAVA_PATH}/${TD_API_JAVA_PACKAGE}")
|
|||||||
add_custom_target(generate_javadoc
|
add_custom_target(generate_javadoc
|
||||||
COMMAND ${Java_JAVADOC_EXECUTABLE} -d ${JAVA_OUTPUT_DIRECTORY}/../docs org.drinkless.tdlib
|
COMMAND ${Java_JAVADOC_EXECUTABLE} -d ${JAVA_OUTPUT_DIRECTORY}/../docs org.drinkless.tdlib
|
||||||
WORKING_DIRECTORY ${TD_API_JAVA_PATH}
|
WORKING_DIRECTORY ${TD_API_JAVA_PATH}
|
||||||
COMMENT "Generate Javadoc documentation"
|
COMMENT "Generating Javadoc documentation"
|
||||||
DEPENDS td_generate_java_api
|
DEPENDS td_generate_java_api
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -31,8 +31,9 @@ public final class Log {
|
|||||||
*
|
*
|
||||||
* @param filePath Path to a file for writing TDLib internal log. Use an empty path to
|
* @param filePath Path to a file for writing TDLib internal log. Use an empty path to
|
||||||
* switch back to logging to the System.err.
|
* switch back to logging to the System.err.
|
||||||
|
* @return whether opening the log file succeeded
|
||||||
*/
|
*/
|
||||||
public static native void setFilePath(String filePath);
|
public static native boolean setFilePath(String filePath);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changes maximum size of TDLib log file.
|
* Changes maximum size of TDLib log file.
|
||||||
|
@ -11,6 +11,8 @@ import org.drinkless.tdlib.Log;
|
|||||||
import org.drinkless.tdlib.TdApi;
|
import org.drinkless.tdlib.TdApi;
|
||||||
|
|
||||||
import java.io.Console;
|
import java.io.Console;
|
||||||
|
import java.io.IOError;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.NavigableSet;
|
import java.util.NavigableSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@ -161,8 +163,9 @@ public final class Example {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void getCommand() {
|
private static void getCommand() {
|
||||||
String command = System.console().readLine("Enter command (gcs - GetChats, gc - GetChat, me - GetMe, sm <chatId> <message> - SendMessage, lo - LogOut, q - Quit): ");
|
String command = System.console().readLine("Enter command (gcs - GetChats, gc <chatId> - GetChat, me - GetMe, sm <chatId> <message> - SendMessage, lo - LogOut, q - Quit): ");
|
||||||
String[] commands = command.split(" ", 2);
|
String[] commands = command.split(" ", 2);
|
||||||
|
try {
|
||||||
switch (commands[0]) {
|
switch (commands[0]) {
|
||||||
case "gcs": {
|
case "gcs": {
|
||||||
int limit = 20;
|
int limit = 20;
|
||||||
@ -195,6 +198,9 @@ public final class Example {
|
|||||||
default:
|
default:
|
||||||
System.err.println("Unsupported command: " + command);
|
System.err.println("Unsupported command: " + command);
|
||||||
}
|
}
|
||||||
|
} catch (ArrayIndexOutOfBoundsException e) {
|
||||||
|
print("Not enough arguments");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void getChatList(final int limit) {
|
private static void getChatList(final int limit) {
|
||||||
@ -259,6 +265,9 @@ public final class Example {
|
|||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) throws InterruptedException {
|
||||||
// disable TDLib log
|
// disable TDLib log
|
||||||
Log.setVerbosityLevel(0);
|
Log.setVerbosityLevel(0);
|
||||||
|
if (!Log.setFilePath("log")) {
|
||||||
|
throw new IOError(new IOException("Write access to the current directory is required"));
|
||||||
|
}
|
||||||
|
|
||||||
// create client
|
// create client
|
||||||
client = Client.create(new UpdatesHandler(), null, null);
|
client = Client.create(new UpdatesHandler(), null, null);
|
||||||
|
@ -73,8 +73,8 @@ static void Log_setVerbosityLevel(JNIEnv *env, jclass clazz, jint new_log_verbos
|
|||||||
td::Log::set_verbosity_level(static_cast<int>(new_log_verbosity_level));
|
td::Log::set_verbosity_level(static_cast<int>(new_log_verbosity_level));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Log_setFilePath(JNIEnv *env, jclass clazz, jstring file_path) {
|
static jboolean Log_setFilePath(JNIEnv *env, jclass clazz, jstring file_path) {
|
||||||
td::Log::set_file_path(td::jni::from_jstring(env, file_path));
|
return td::Log::set_file_path(td::jni::from_jstring(env, file_path)) ? JNI_TRUE : JNI_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Log_setMaxFileSize(JNIEnv *env, jclass clazz, jlong max_file_size) {
|
static void Log_setMaxFileSize(JNIEnv *env, jclass clazz, jlong max_file_size) {
|
||||||
@ -132,7 +132,7 @@ static jint register_native(JavaVM *vm) {
|
|||||||
register_method(client_class, "destroyNativeClient", "(J)V", Client_destroyNativeClient);
|
register_method(client_class, "destroyNativeClient", "(J)V", Client_destroyNativeClient);
|
||||||
|
|
||||||
register_method(log_class, "setVerbosityLevel", "(I)V", Log_setVerbosityLevel);
|
register_method(log_class, "setVerbosityLevel", "(I)V", Log_setVerbosityLevel);
|
||||||
register_method(log_class, "setFilePath", "(Ljava/lang/String;)V", Log_setFilePath);
|
register_method(log_class, "setFilePath", "(Ljava/lang/String;)Z", Log_setFilePath);
|
||||||
register_method(log_class, "setMaxFileSize", "(J)V", Log_setMaxFileSize);
|
register_method(log_class, "setMaxFileSize", "(J)V", Log_setMaxFileSize);
|
||||||
|
|
||||||
register_method(object_class, "toString", "()Ljava/lang/String;", Object_toString);
|
register_method(object_class, "toString", "()Ljava/lang/String;", Object_toString);
|
||||||
|
@ -30,7 +30,7 @@ td_json_client_destroy.restype = None
|
|||||||
td_json_client_destroy.argtypes = [c_void_p]
|
td_json_client_destroy.argtypes = [c_void_p]
|
||||||
|
|
||||||
td_set_log_file_path = tdjson.td_set_log_file_path
|
td_set_log_file_path = tdjson.td_set_log_file_path
|
||||||
td_set_log_file_path.restype = None
|
td_set_log_file_path.restype = c_int
|
||||||
td_set_log_file_path.argtypes = [c_char_p]
|
td_set_log_file_path.argtypes = [c_char_p]
|
||||||
|
|
||||||
td_set_log_max_file_size = tdjson.td_set_log_max_file_size
|
td_set_log_max_file_size = tdjson.td_set_log_max_file_size
|
||||||
|
@ -24,17 +24,18 @@ static void fatal_error_callback_wrapper(CSlice message) {
|
|||||||
fatal_error_callback(message.c_str());
|
fatal_error_callback(message.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Log::set_file_path(string file_path) {
|
bool Log::set_file_path(string file_path) {
|
||||||
if (file_path.empty()) {
|
if (file_path.empty()) {
|
||||||
log_interface = default_log_interface;
|
log_interface = default_log_interface;
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_log.init(file_path, max_log_file_size)) {
|
if (file_log.init(file_path, max_log_file_size)) {
|
||||||
log_interface = &ts_log;
|
log_interface = &ts_log;
|
||||||
} else {
|
return true;
|
||||||
LOG(FATAL) << "Can't init file log";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Log::set_max_file_size(int64 max_file_size) {
|
void Log::set_max_file_size(int64 max_file_size) {
|
||||||
|
@ -30,8 +30,9 @@ class Log {
|
|||||||
*
|
*
|
||||||
* \param[in] file_path Path to a file where the internal TDLib log will be written. Use an empty path to
|
* \param[in] file_path Path to a file where the internal TDLib log will be written. Use an empty path to
|
||||||
* switch back to the default logging behaviour.
|
* switch back to the default logging behaviour.
|
||||||
|
* \return True on success, or false otherwise, i.e. if the file can't be opened for writing.
|
||||||
*/
|
*/
|
||||||
static void set_file_path(std::string file_path);
|
static bool set_file_path(std::string file_path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets maximum size of the file to where the internal TDLib log is written before the file will be auto-rotated.
|
* Sets maximum size of the file to where the internal TDLib log is written before the file will be auto-rotated.
|
||||||
|
@ -187,7 +187,7 @@ class Td final : public NetQueryCallback {
|
|||||||
static td_api::object_ptr<td_api::Object> static_request(td_api::object_ptr<td_api::Function> function);
|
static td_api::object_ptr<td_api::Object> static_request(td_api::object_ptr<td_api::Function> function);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr const char *tdlib_version = "1.0.5";
|
static constexpr const char *tdlib_version = "1.0.6";
|
||||||
static constexpr int32 ONLINE_TIMEOUT = 240;
|
static constexpr int32 ONLINE_TIMEOUT = 240;
|
||||||
|
|
||||||
void send_result(uint64 id, tl_object_ptr<td_api::Object> object);
|
void send_result(uint64 id, tl_object_ptr<td_api::Object> object);
|
||||||
|
@ -10,8 +10,8 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
void td_set_log_file_path(const char *file_path) {
|
int td_set_log_file_path(const char *file_path) {
|
||||||
td::Log::set_file_path(file_path == nullptr ? "" : file_path);
|
return static_cast<int>(td::Log::set_file_path(file_path == nullptr ? "" : file_path));
|
||||||
}
|
}
|
||||||
|
|
||||||
void td_set_log_max_file_size(long long max_file_size) {
|
void td_set_log_max_file_size(long long max_file_size) {
|
||||||
|
@ -25,8 +25,9 @@ extern "C" {
|
|||||||
*
|
*
|
||||||
* \param[in] file_path Null-terminated path to a file where the internal TDLib log will be written.
|
* \param[in] file_path Null-terminated path to a file where the internal TDLib log will be written.
|
||||||
* Use an empty path to switch back to the default logging behaviour.
|
* Use an empty path to switch back to the default logging behaviour.
|
||||||
|
* \return True 1 on success, or 0 otherwise, i.e. if the file can't be opened for writing.
|
||||||
*/
|
*/
|
||||||
TDJSON_EXPORT void td_set_log_file_path(const char *file_path);
|
TDJSON_EXPORT int td_set_log_file_path(const char *file_path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets maximum size of the file to where the internal TDLib log is written before the file will be auto-rotated.
|
* Sets maximum size of the file to where the internal TDLib log is written before the file will be auto-rotated.
|
||||||
|
Reference in New Issue
Block a user