Skip to content

写入INFO日志 - LogInfo

函数简介

写入 INFO 级别日志到默认日志实例。

接口名称

LogInfo

DLL调用

c
int32_t LogInfo(int64_t instance, const char* message);

参数说明

参数名类型说明
instance长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
message字符串日志消息。

示例

推荐联动顺序:

LogSetLevel(0, 2) → LogSetTarget(0, 1|2) → OpenConsole(0)
        → LogInfo("...") → LogFlush(0)

INFO=2,正常运行信息(默认级别)LogSetTarget(0, 1|2) = FILE|CONSOLE。

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;

// 默认实例 loggerHandle=0;LogInfo 只接收 message,无句柄参数
ola.LogSetLevel(0, 2);          // INFO=2,正常运行信息(默认级别)
ola.LogSetTarget(0, 1 | 2);    // FILE | CONSOLE
ola.OpenConsole(0);            // 打开插件进程控制台

ola.LogInfo("服务启动完成,监听端口 8080");
ola.LogFlush(0);
csharp
using OLAPlug;

var ola = new OLAPlugServer();

ola.LogSetLevel(0, 2);       // INFO=2,正常运行信息(默认级别)
ola.LogSetTarget(0, 1 | 2); // FILE | CONSOLE
ola.OpenConsole(0);

ola.LogInfo("服务启动完成,监听端口 8080");
ola.LogFlush(0);
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()

ola.LogSetLevel(0, 2)       # INFO=2,正常运行信息(默认级别)
ola.LogSetTarget(0, 1 | 2)  # FILE | CONSOLE
ola.OpenConsole(0)

ola.LogInfo("服务启动完成,监听端口 8080")
ola.LogFlush(0)
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();

ola.LogSetLevel(0, 2);       // INFO=2,正常运行信息(默认级别)
ola.LogSetTarget(0, 1 | 2); // FILE | CONSOLE
ola.OpenConsole(0);

ola.LogInfo("服务启动完成,监听端口 8080");
ola.LogFlush(0);
go
import "github.com/ola/olaplug/olaplug"

ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()

ola.LogSetLevel(0, 2)       // INFO=2,正常运行信息(默认级别)
ola.LogSetTarget(0, 1|2)   // FILE | CONSOLE
ola.OpenConsole(0)

ola.LogInfo("服务启动完成,监听端口 8080")
ola.LogFlush(0)
rust
use olaplug::OLAPlugServer;

let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();

ola.log_set_level(0, 2);       // INFO=2,正常运行信息(默认级别)
ola.log_set_target(0, 1 | 2); // FILE | CONSOLE
ola.open_console(0);

ola.log_info("服务启动完成,监听端口 8080");
ola.log_flush(0);
cpp
var ola = com("OlaPlug.OlaSoft")

ola.LogSetLevel(0, 2)       // INFO=2,正常运行信息(默认级别)
ola.LogSetTarget(0, 1 | 2) // FILE | CONSOLE
ola.OpenConsole(0)

ola.LogInfo("服务启动完成,监听端口 8080")
ola.LogFlush(0)
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")

ola.LogSetLevel 0, 2       ' INFO=2,正常运行信息(默认级别)
ola.LogSetTarget 0, 3     ' 1|2 = FILE|CONSOLE
ola.OpenConsole 0

ola.LogInfo "服务启动完成,监听端口 8080"
ola.LogFlush 0
text
.局部变量 ola, OLAPlug

ola.Create ()
ola.LogSetLevel (0, 2)       ' INFO=2,正常运行信息(默认级别)
ola.LogSetTarget (0, 位或 (1, 2))  ' FILE | CONSOLE
ola.OpenConsole (0)

ola.LogInfo (“服务启动完成,监听端口 8080”)
ola.LogFlush (0)
aardio
import OLAPlugServer;
var ola = OLAPlugServer();

ola.LogSetLevel(0, 2);       // INFO=2,正常运行信息(默认级别)
ola.LogSetTarget(0, 1 | 2); // FILE | CONSOLE
ola.OpenConsole(0);

ola.LogInfo("服务启动完成,监听端口 8080");
ola.LogFlush(0);
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer

ola.LogSetLevel(0, 2)       ' INFO=2,正常运行信息(默认级别)
ola.LogSetTarget(0, 1 位或 2)  ' FILE | CONSOLE
ola.OpenConsole(0)

ola.LogInfo("服务启动完成,监听端口 8080")
ola.LogFlush(0)
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;

ola.LogSetLevel(0, 2);       // INFO=2,正常运行信息(默认级别)
ola.LogSetTarget(0, 1 | 2); // FILE | CONSOLE
ola.OpenConsole(0);

ola.LogInfo("服务启动完成,监听端口 8080");
ola.LogFlush(0);

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();

// Native: LogInfo(instance, message) — 无 loggerHandle
LogSetLevel(instance, 0, 2);
LogSetTarget(instance, 0, 1 | 2); // FILE | CONSOLE
OpenConsole(instance, 0);

LogInfo(instance, "服务启动完成,监听端口 8080");
LogFlush(instance, 0);
csharp
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 LogSetLevel(long ola, long loggerHandle, int level);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int LogSetTarget(long ola, long loggerHandle, int targetFlags);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int OpenConsole(long ola, int type);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int LogInfo(long ola, string message);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int LogFlush(long ola, long loggerHandle);

long instance = CreateCOLAPlugInterFace();
LogSetLevel(instance, 0, 2);
LogSetTarget(instance, 0, 1 | 2);
OpenConsole(instance, 0);
LogInfo(instance, "服务启动完成,监听端口 8080");
LogFlush(instance, 0);
python
from ctypes import CDLL, c_int, c_int64, c_char_p

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
ola.LogSetLevel.argtypes = [c_int64, c_int64, c_int]
ola.LogSetTarget.argtypes = [c_int64, c_int64, c_int]
ola.OpenConsole.argtypes = [c_int64, c_int]
ola.LogInfo.argtypes = [c_int64, c_char_p]
ola.LogFlush.argtypes = [c_int64, c_int64]

instance = ola.CreateCOLAPlugInterFace()
ola.LogSetLevel(instance, 0, 2)
ola.LogSetTarget(instance, 0, 1 | 2)
ola.OpenConsole(instance, 0)
ola.LogInfo(instance, "服务启动完成,监听端口 8080".encode("utf-8"))
ola.LogFlush(instance, 0)

返回值

返回值说明
1成功。
0失败。

注意事项

项目说明
INFO 级别用于记录程序的正常运行信息INFO 级别用于记录程序的正常运行信息。
OLA_LOG_LEVEL_INFO只有当日志级别设置为 OLA_LOG_LEVEL_INFO (2) 或更低时才会输出。
这是默认的日志级别这是默认的日志级别,适合生产环境使用。
如果需要指定日志实例如果需要指定日志实例,请使用 LogInfoEx
如果日志系统未初始化如果日志系统未初始化,第一次调用时会自动初始化。