OCT 1. 修复日志文件配置为相对路径时无法正常创建日志文件问题

This commit is contained in:
黄昕 2023-08-24 09:47:01 +08:00
parent c2153fd024
commit d6e1ee67d0
2 changed files with 14 additions and 10 deletions

View File

@ -50,17 +50,22 @@ static spdlog::level::level_enum logLevelToSpdlogLevel(LOG_LEVEL level) {
static void InitTunnelSDKLog(const TCHAR *pLogFile, LOG_LEVEL level) {
TCHAR buf[MAX_PATH] = {0};
TCHAR tmpPath[MAX_PATH];
if (pLogFile && strlen(pLogFile) > 0 && !PathIsRelative(pLogFile)) {
TCHAR tmpPath[MAX_PATH];
StringCbCopy(tmpPath, MAX_PATH, pLogFile);
PathRemoveFileSpec(tmpPath);
MakeSureDirectoryPathExists(tmpPath);
StringCbCopy(buf, MAX_PATH, pLogFile);
if (pLogFile && strlen(pLogFile) > 0) {
if (PathIsRelative(buf)) {
StringCbPrintf(buf, MAX_PATH, TEXT("%s\\%s"), g_globalConfig.workDirectory, pLogFile);
} else {
StringCbCopy(buf, MAX_PATH, pLogFile);
}
} else {
StringCbPrintf(buf, MAX_PATH, TEXT("%s\\tunnelsdklog.log"), g_globalConfig.workDirectory);
}
StringCbCopy(tmpPath, MAX_PATH, buf);
PathRemoveFileSpec(tmpPath);
MakeSureDirectoryPathExists(tmpPath);
g_globalConfig.enableLog = TRUE;
g_globalConfig.logLevel = logLevelToSpdlogLevel(level);
@ -144,7 +149,7 @@ int TunnelSDKInitEnv(const TCHAR *pWorkDir,
StringCbCat(g_globalConfig.configDirectory, MAX_PATH, "\\NetTunnel");
SPDLOG_DEBUG(TEXT("Configure directory: {0}."), g_globalConfig.configDirectory);
SPDLOG_DEBUG(TEXT("Platform Server: {}, Work Module: {}"), pSvrUrl, isWorkServer? TEXT("SERVER") : TEXT("Client"));
SPDLOG_DEBUG(TEXT("Platform Server: {}, Work Module: {}"), pSvrUrl, isWorkServer ? TEXT("SERVER") : TEXT("Client"));
// 如果配置目录不存在则自动创建
if (!PathFileExists(g_globalConfig.configDirectory)) {

View File

@ -19,8 +19,7 @@ TEST_MODULE_INITIALIZE(ModuleInitialize) {
Assert::AreEqual(0,
TunnelSDKInitEnv(path,
"http://172.21.40.194:32549",
TEXT("C:\\Users\\HuangXin\\Documents\\development\\visual_studio\\tunnel_"
"windows\\NetTunnelApp\\bin\\Debug\\utest.log"),
TEXT("./test/utest.log"),
LOG_TRACE,
false));
//Assert::AreEqual(0, EnableVerifySignature(TEXT("123"), TEXT("123456")));