modify the default path of OB_LOGGER to HOME

This commit is contained in:
HaHaJeff 2023-10-20 13:13:30 +00:00 committed by ob-robot
parent 098ebfbf83
commit 5b4c6cac5c
2 changed files with 65 additions and 5 deletions

View File

@ -272,7 +272,7 @@ int ObAdminDumpBlock::parse_single_log_entry_(const LogEntry &entry,
if (OB_FAIL(parser_le.parse())) {
LOG_WARN("ObAdminParserLogEntry failed", K(ret), K(entry), K(block_name), K(lsn));
} else {
LOG_INFO("parse_single_log_entry_ success",K(entry), K(str_arg_));
LOG_TRACE("parse_single_log_entry_ success",K(entry), K(str_arg_));
}
return ret;
}

View File

@ -14,6 +14,9 @@
#include <sstream>
#include <iterator>
#include <string.h>
#include <sys/types.h>
#include <pwd.h>
#include <malloc.h>
#include "share/ob_define.h"
#include "dumpsst/ob_admin_dumpsst_executor.h"
#include "io_bench/ob_admin_io_executor.h"
@ -26,6 +29,7 @@
#include "log_tool/ob_admin_log_tool_executor.h"
#include "slog_tool/ob_admin_slog_executor.h"
#include "dump_ckpt/ob_admin_dump_ckpt_executor.h"
#include "lib/utility/ob_print_utils.h"
using namespace oceanbase::common;
using namespace oceanbase::tools;
@ -47,12 +51,68 @@ void print_usage()
" ob_admin -S unix_domain_socket_path xxx");
}
int get_log_base_directory(char *log_file_name, const int64_t log_file_name_len,
char *log_file_rs_name, const int64_t log_file_rs_name_len)
{
int ret = OB_SUCCESS;
const char *log_file_name_ptr = "ob_admin.log";
const char *log_file_rs_name_ptr = "ob_admin_rs.log";
// the format of log file name is 'ob_admin_log_dir' + "/" + ob_admin.log + '\0'
const int tmp_log_file_name_len = 1 + strlen(log_file_name_ptr) + 1;
const int tmp_log_file_rs_name_len = 1 + strlen(log_file_rs_name_ptr) + 1;
if (NULL == log_file_name || 0 >= log_file_name_len
|| NULL == log_file_rs_name || 0 >= log_file_rs_name_len) {
ret = OB_INVALID_ARGUMENT;
fprintf(stderr, "\ninvalid argument, errno:%d\n", errno);
} else {
const char *ob_admin_log_dir = getenv("OB_ADMIN_LOG_DIR");
int64_t ob_admin_log_dir_len = 0;
bool is_directory = false;
if (NULL == ob_admin_log_dir) {
fprintf(stderr, "\nThe OB_ADMIN_LOG_DIR environment variable not found, we will not generate ob_admin.log\n"
"If log files are required, please notice that log files should not be outputted to\n"
"OceanBase's clog directory.(for example, export OB_ADMIN_LOG_DIR=/tmp)\n");
ret = OB_ENTRY_NOT_EXIST;
} else if (FALSE_IT(ob_admin_log_dir_len = strlen(ob_admin_log_dir))) {
} else if (OB_FAIL(FileDirectoryUtils::is_directory(ob_admin_log_dir, is_directory))) {
fprintf(stderr, "\nCheck is_directory failed, we will not generate ob_admin.log(errno:%d)\n", ret);
} else if (!is_directory) {
fprintf(stderr, "\nThe OB_ADMIN_LOG_DIR(%s) environment variable is not a directory, we will not generate ob_admin.log\n"
"If log files are required, please notice that log files should not be outputted to\n"
"OceanBase's clog directory.\n", ob_admin_log_dir);
ret = OB_ENTRY_NOT_EXIST;
} else if (0 != access(ob_admin_log_dir, W_OK)) {
fprintf(stderr, "\nPermission denied, currently OB_ADMIN_LOG_DIR(%s) environment variable, we will not generate ob_admin.log\n"
"If log files are required, please notice that log files should not be outputted to\n"
"OceanBase's clog directory.\n", ob_admin_log_dir);
ret = OB_ENTRY_NOT_EXIST;
} else if (ob_admin_log_dir_len + tmp_log_file_name_len > log_file_name_len
|| ob_admin_log_dir_len + tmp_log_file_rs_name_len > log_file_rs_name_len) {
fprintf(stderr, "\nLog file name length too longer, please modify log's directory via export $OB_ADMIN_LOG_DIR=xxx\n"
"If log files are required, please notice that log files should not be outputted to\n"
"OceanBase's clog directory, currently OB_ADMIN_LOG_DIR(%s) environment variable.\n", ob_admin_log_dir);
ret = OB_SIZE_OVERFLOW;
} else if (OB_FAIL(databuff_printf(log_file_name, log_file_name_len, "%s/%s", ob_admin_log_dir, log_file_name_ptr))) {
fprintf(stderr, "\nUnexpected error, databuff_printf failed\n");
} else if (OB_FAIL(databuff_printf(log_file_rs_name, log_file_rs_name_len, "%s/%s", ob_admin_log_dir, log_file_rs_name_ptr))) {
fprintf(stderr, "\nUnexpected error, databuff_printf failed\n");
} else {
}
}
return ret;
}
int main(int argc, char *argv[])
{
int ret = 0;
OB_LOGGER.set_log_level("INFO");
OB_LOGGER.set_file_name("ob_admin.log", true, false);
OB_LOGGER.set_file_name("ob_admin.log", true, false, "ob_admin_rs.log");
char log_file_name[OB_MAX_FILE_NAME_LENGTH] = {'\0'};
char log_file_rs_name[OB_MAX_FILE_NAME_LENGTH] = {'\0'};
if (OB_FAIL(get_log_base_directory(log_file_name, sizeof(log_file_name), log_file_rs_name, sizeof(log_file_rs_name)))) {
} else {
OB_LOGGER.set_log_level("INFO");
OB_LOGGER.set_file_name(log_file_name, true, false, log_file_rs_name);
}
const char *log_level = getenv("OB_ADMIN_LOG_LEVEL");
if (NULL != log_level) {
OB_LOGGER.set_log_level(log_level);
@ -69,7 +129,7 @@ int main(int argc, char *argv[])
executor = new ObAdminIOExecutor();
#ifdef OB_BUILD_TDE_SECURITY
} else if (0 == strcmp("dump_key", argv[1])) {
executor = new ObAdminDumpKeyExecutor();
executor = new ObAdminDumpKeyExecutor();
#endif
} else if (0 == strcmp("dump_enum_value", argv[1])) {
executor = new ObAdminDumpEnumValueExecutor();