主题
获取当前文件路径 - LogGetCurrentFilePath
函数简介
获取日志实例当前正在使用的日志文件路径。
接口名称
LogGetCurrentFilePathDLL调用
c
const char* LogGetCurrentFilePath(int64_t instance, int64_t loggerHandle);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| loggerHandle | 长整数型 | 日志实例句柄(0 表示默认实例)。 |
示例
配置路径并写日志后,打印当前实际文件路径。
SDK 调用
cpp
#include "OLAPlugServer.h"
#include <cstdio>
OLAPlugServer ola;
const int64_t logger = 0; // 默认实例
ola.LogSetBaseDirectory(logger, "D:\\logs");
ola.LogSetFileNamePattern(logger, "app_{date}_{index}.log");
ola.LogInfo("probe path");
std::string path = ola.LogGetCurrentFilePath(logger);
std::printf("current log file: %s\n", path.c_str());csharp
using System;
using OLAPlug;
var ola = new OLAPlugServer();
long logger = 0;
ola.LogSetBaseDirectory(logger, @"D:\logs");
ola.LogSetFileNamePattern(logger, "app_{date}_{index}.log");
ola.LogInfo("probe path");
string path = ola.LogGetCurrentFilePath(logger);
Console.WriteLine("current log file: " + path);python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
logger = 0
ola.LogSetBaseDirectory(logger, r"D:\logs")
ola.LogSetFileNamePattern(logger, "app_{date}_{index}.log")
ola.LogInfo("probe path")
path = ola.LogGetCurrentFilePath(logger)
print("current log file:", path)java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
long logger = 0;
ola.LogSetBaseDirectory(logger, "D:\\logs");
ola.LogSetFileNamePattern(logger, "app_{date}_{index}.log");
ola.LogInfo("probe path");
String path = ola.LogGetCurrentFilePath(logger);
System.out.println("current log file: " + path);go
import (
"fmt"
"github.com/ola/olaplug/olaplug"
)
ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
logger := int64(0)
ola.LogSetBaseDirectory(logger, `D:\logs`)
ola.LogSetFileNamePattern(logger, "app_{date}_{index}.log")
ola.LogInfo("probe path")
path := ola.LogGetCurrentFilePath(logger)
fmt.Println("current log file:", path)rust
use olaplug::OLAPlugServer;
let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let logger = 0i64;
ola.log_set_base_directory(logger, r"D:\logs");
ola.log_set_file_name_pattern(logger, "app_{date}_{index}.log");
ola.log_info("probe path");
let path = ola.log_get_current_file_path(logger);
println!("current log file: {}", path);cpp
var ola = com("OlaPlug.OlaSoft")
var logger = 0
ola.LogSetBaseDirectory(logger, "D:\\logs")
ola.LogSetFileNamePattern(logger, "app_{date}_{index}.log")
ola.LogInfo("probe path")
var path = ola.LogGetCurrentFilePath(logger)
traceprint("current log file: " + path)vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
logger = 0
ola.LogSetBaseDirectory logger, "D:\logs"
ola.LogSetFileNamePattern logger, "app_{date}_{index}.log"
ola.LogInfo "probe path"
path = ola.LogGetCurrentFilePath(logger)
TracePrint "current log file: " & pathtext
.局部变量 ola, OLAPlug
.局部变量 ret, 整数型
.局部变量 logger, 长整数型
.局部变量 path, 文本型
ola.Create ()
logger = 0
ola.LogSetBaseDirectory (logger, “D:\logs”)
ola.LogSetFileNamePattern (logger, “app_{date}_{index}.log”)
ola.LogInfo (“probe path”)
path = ola.LogGetCurrentFilePath (logger)
调试输出 (“current log file:”, path)aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var logger = 0;
ola.LogSetBaseDirectory(logger, "D:\\logs");
ola.LogSetFileNamePattern(logger, "app_{date}_{index}.log");
ola.LogInfo("probe path");
var path = ola.LogGetCurrentFilePath(logger);
io.print("current log file: ", path);text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
长整数 logger = 0
ola.LogSetBaseDirectory(logger, "D:\\logs")
ola.LogSetFileNamePattern(logger, "app_{date}_{index}.log")
ola.LogInfo("probe path")
文本 path = ola.LogGetCurrentFilePath(logger)
调试输出 ("current log file:", path)cpp
#include "OLAPlugServer.h"
#include <cstdio>
OLAPlugServer ola;
int64_t logger = 0;
ola.LogSetBaseDirectory(logger, "D:\\logs");
ola.LogSetFileNamePattern(logger, "app_{date}_{index}.log");
ola.LogInfo("probe path");
std::string path = ola.LogGetCurrentFilePath(logger);
std::printf("current log file: %s\n", path.c_str());原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
long logger = 0;
LogSetBaseDirectory(instance, logger, "D:\\logs");
LogSetFileNamePattern(instance, logger, "app_{date}_{index}.log");
LogInfo(instance, "probe path");
// const char* path = LogGetCurrentFilePath(instance, logger);
// 若返回字符串指针,需配合 GetStringFromPtr / FreeStringPtrcsharp
using System.Runtime.InteropServices;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int LogSetBaseDirectory(long ola, long loggerHandle, string baseDirectory);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int LogSetFileNamePattern(long ola, long loggerHandle, string fileNamePattern);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int LogInfo(long ola, string message);
long instance = CreateCOLAPlugInterFace();
long logger = 0;
LogSetBaseDirectory(instance, logger, @"D:\logs");
LogSetFileNamePattern(instance, logger, "app_{date}_{index}.log");
LogInfo(instance, "probe path");python
from ctypes import CDLL, c_int, c_int64
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
logger = 0
ola.LogSetBaseDirectory(instance, logger, b"D:\\logs")
ola.LogSetFileNamePattern(instance, logger, b"app_{date}_{index}.log")
ola.LogInfo(instance, b"probe path")返回值
| 返回值 | 说明 |
|---|---|
| (返回值) | 当前文件路径(字符串),失败返回空字符串或 NULL。返回的字符串指针需要调用 FreeStringPtr 接口释放内存。 |
注意事项
| 项目 | 说明 |
|---|---|
| 释放内存 | 返回的字符串指针需要调用 FreeStringPtr 接口释放内存。 |
| 如果日志系统未初始化 | 如果日志系统未初始化,返回空字符串或 NULL。 |
| 路径 | 返回的是完整的绝对路径。 |
| 路径 | 文件路径会随着日志分割而变化。 |
