Skip to content

写入ERROR日志 - LogError

函数简介

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

接口名称

LogError

DLL调用

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

参数说明

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

示例

推荐联动顺序:

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

ERROR=4,操作失败但仍可继续运行LogSetTarget(0, 1|2) = FILE|CONSOLE。

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;

// 默认实例 loggerHandle=0;LogError 只接收 message,无句柄参数
ola.LogSetLevel(0, 4);          // ERROR=4,操作失败但仍可继续运行
ola.LogSetTarget(0, 1 | 2);    // FILE | CONSOLE
ola.OpenConsole(0);            // 打开插件进程控制台

ola.LogError("连接数据库失败: timeout after 5000ms");
ola.LogFlush(0);
csharp
using OLAPlug;

var ola = new OLAPlugServer();

ola.LogSetLevel(0, 4);       // ERROR=4,操作失败但仍可继续运行
ola.LogSetTarget(0, 1 | 2); // FILE | CONSOLE
ola.OpenConsole(0);

ola.LogError("连接数据库失败: timeout after 5000ms");
ola.LogFlush(0);
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()

ola.LogSetLevel(0, 4)       # ERROR=4,操作失败但仍可继续运行
ola.LogSetTarget(0, 1 | 2)  # FILE | CONSOLE
ola.OpenConsole(0)

ola.LogError("连接数据库失败: timeout after 5000ms")
ola.LogFlush(0)
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();

ola.LogSetLevel(0, 4);       // ERROR=4,操作失败但仍可继续运行
ola.LogSetTarget(0, 1 | 2); // FILE | CONSOLE
ola.OpenConsole(0);

ola.LogError("连接数据库失败: timeout after 5000ms");
ola.LogFlush(0);
go
import "github.com/ola/olaplug/olaplug"

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

ola.LogSetLevel(0, 4)       // ERROR=4,操作失败但仍可继续运行
ola.LogSetTarget(0, 1|2)   // FILE | CONSOLE
ola.OpenConsole(0)

ola.LogError("连接数据库失败: timeout after 5000ms")
ola.LogFlush(0)
rust
use olaplug::OLAPlugServer;

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

ola.log_set_level(0, 4);       // ERROR=4,操作失败但仍可继续运行
ola.log_set_target(0, 1 | 2); // FILE | CONSOLE
ola.open_console(0);

ola.log_error("连接数据库失败: timeout after 5000ms");
ola.log_flush(0);
cpp
var ola = com("OlaPlug.OlaSoft")

ola.LogSetLevel(0, 4)       // ERROR=4,操作失败但仍可继续运行
ola.LogSetTarget(0, 1 | 2) // FILE | CONSOLE
ola.OpenConsole(0)

ola.LogError("连接数据库失败: timeout after 5000ms")
ola.LogFlush(0)
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")

ola.LogSetLevel 0, 4       ' ERROR=4,操作失败但仍可继续运行
ola.LogSetTarget 0, 3     ' 1|2 = FILE|CONSOLE
ola.OpenConsole 0

ola.LogError "连接数据库失败: timeout after 5000ms"
ola.LogFlush 0
text
.局部变量 ola, OLAPlug

ola.Create ()
ola.LogSetLevel (0, 4)       ' ERROR=4,操作失败但仍可继续运行
ola.LogSetTarget (0, 位或 (1, 2))  ' FILE | CONSOLE
ola.OpenConsole (0)

ola.LogError (“连接数据库失败: timeout after 5000ms”)
ola.LogFlush (0)
aardio
import OLAPlugServer;
var ola = OLAPlugServer();

ola.LogSetLevel(0, 4);       // ERROR=4,操作失败但仍可继续运行
ola.LogSetTarget(0, 1 | 2); // FILE | CONSOLE
ola.OpenConsole(0);

ola.LogError("连接数据库失败: timeout after 5000ms");
ola.LogFlush(0);
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer

ola.LogSetLevel(0, 4)       ' ERROR=4,操作失败但仍可继续运行
ola.LogSetTarget(0, 1 位或 2)  ' FILE | CONSOLE
ola.OpenConsole(0)

ola.LogError("连接数据库失败: timeout after 5000ms")
ola.LogFlush(0)
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;

ola.LogSetLevel(0, 4);       // ERROR=4,操作失败但仍可继续运行
ola.LogSetTarget(0, 1 | 2); // FILE | CONSOLE
ola.OpenConsole(0);

ola.LogError("连接数据库失败: timeout after 5000ms");
ola.LogFlush(0);

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();

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

LogError(instance, "连接数据库失败: timeout after 5000ms");
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 LogError(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, 4);
LogSetTarget(instance, 0, 1 | 2);
OpenConsole(instance, 0);
LogError(instance, "连接数据库失败: timeout after 5000ms");
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.LogError.argtypes = [c_int64, c_char_p]
ola.LogFlush.argtypes = [c_int64, c_int64]

instance = ola.CreateCOLAPlugInterFace()
ola.LogSetLevel(instance, 0, 4)
ola.LogSetTarget(instance, 0, 1 | 2)
ola.OpenConsole(instance, 0)
ola.LogError(instance, "连接数据库失败: timeout after 5000ms".encode("utf-8"))
ola.LogFlush(instance, 0)

返回值

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

注意事项

项目说明
ERROR 级别用于记录错误信息ERROR 级别用于记录错误信息,表示程序遇到了问题。
OLA_LOG_LEVEL_ERROR只有当日志级别设置为 OLA_LOG_LEVEL_ERROR (4) 或更低时才会输出。
ERROR 级别的日志会立即刷新到文件(如果设置ERROR 级别的日志会立即刷新到文件(如果设置了自动刷新间隔)。
如果需要指定日志实例如果需要指定日志实例,请使用 LogErrorEx
如果日志系统未初始化如果日志系统未初始化,第一次调用时会自动初始化。