主题
写入CRITICAL日志 - LogCritical
函数简介
写入 CRITICAL 级别日志到默认日志实例。
接口名称
LogCriticalDLL调用
c
int32_t LogCritical(int64_t instance, const char* message);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| message | 字符串 | 日志消息。 |
示例
推荐联动顺序:
LogSetLevel(0, 5) → LogSetTarget(0, 1|2) → OpenConsole(0)
→ LogCritical("...") → LogFlush(0)CRITICAL=5,严重故障,通常需要立即处理;LogSetTarget(0, 1|2) = FILE|CONSOLE。
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
// 默认实例 loggerHandle=0;LogCritical 只接收 message,无句柄参数
ola.LogSetLevel(0, 5); // CRITICAL=5,严重故障,通常需要立即处理
ola.LogSetTarget(0, 1 | 2); // FILE | CONSOLE
ola.OpenConsole(0); // 打开插件进程控制台
ola.LogCritical("磁盘空间不足,服务即将停止");
ola.LogFlush(0);csharp
using OLAPlug;
var ola = new OLAPlugServer();
ola.LogSetLevel(0, 5); // CRITICAL=5,严重故障,通常需要立即处理
ola.LogSetTarget(0, 1 | 2); // FILE | CONSOLE
ola.OpenConsole(0);
ola.LogCritical("磁盘空间不足,服务即将停止");
ola.LogFlush(0);python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
ola.LogSetLevel(0, 5) # CRITICAL=5,严重故障,通常需要立即处理
ola.LogSetTarget(0, 1 | 2) # FILE | CONSOLE
ola.OpenConsole(0)
ola.LogCritical("磁盘空间不足,服务即将停止")
ola.LogFlush(0)java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
ola.LogSetLevel(0, 5); // CRITICAL=5,严重故障,通常需要立即处理
ola.LogSetTarget(0, 1 | 2); // FILE | CONSOLE
ola.OpenConsole(0);
ola.LogCritical("磁盘空间不足,服务即将停止");
ola.LogFlush(0);go
import "github.com/ola/olaplug/olaplug"
ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
ola.LogSetLevel(0, 5) // CRITICAL=5,严重故障,通常需要立即处理
ola.LogSetTarget(0, 1|2) // FILE | CONSOLE
ola.OpenConsole(0)
ola.LogCritical("磁盘空间不足,服务即将停止")
ola.LogFlush(0)rust
use olaplug::OLAPlugServer;
let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
ola.log_set_level(0, 5); // CRITICAL=5,严重故障,通常需要立即处理
ola.log_set_target(0, 1 | 2); // FILE | CONSOLE
ola.open_console(0);
ola.log_critical("磁盘空间不足,服务即将停止");
ola.log_flush(0);cpp
var ola = com("OlaPlug.OlaSoft")
ola.LogSetLevel(0, 5) // CRITICAL=5,严重故障,通常需要立即处理
ola.LogSetTarget(0, 1 | 2) // FILE | CONSOLE
ola.OpenConsole(0)
ola.LogCritical("磁盘空间不足,服务即将停止")
ola.LogFlush(0)vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ola.LogSetLevel 0, 5 ' CRITICAL=5,严重故障,通常需要立即处理
ola.LogSetTarget 0, 3 ' 1|2 = FILE|CONSOLE
ola.OpenConsole 0
ola.LogCritical "磁盘空间不足,服务即将停止"
ola.LogFlush 0text
.局部变量 ola, OLAPlug
ola.Create ()
ola.LogSetLevel (0, 5) ' CRITICAL=5,严重故障,通常需要立即处理
ola.LogSetTarget (0, 位或 (1, 2)) ' FILE | CONSOLE
ola.OpenConsole (0)
ola.LogCritical (“磁盘空间不足,服务即将停止”)
ola.LogFlush (0)aardio
import OLAPlugServer;
var ola = OLAPlugServer();
ola.LogSetLevel(0, 5); // CRITICAL=5,严重故障,通常需要立即处理
ola.LogSetTarget(0, 1 | 2); // FILE | CONSOLE
ola.OpenConsole(0);
ola.LogCritical("磁盘空间不足,服务即将停止");
ola.LogFlush(0);text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
ola.LogSetLevel(0, 5) ' CRITICAL=5,严重故障,通常需要立即处理
ola.LogSetTarget(0, 1 位或 2) ' FILE | CONSOLE
ola.OpenConsole(0)
ola.LogCritical("磁盘空间不足,服务即将停止")
ola.LogFlush(0)cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
ola.LogSetLevel(0, 5); // CRITICAL=5,严重故障,通常需要立即处理
ola.LogSetTarget(0, 1 | 2); // FILE | CONSOLE
ola.OpenConsole(0);
ola.LogCritical("磁盘空间不足,服务即将停止");
ola.LogFlush(0);原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
// Native: LogCritical(instance, message) — 无 loggerHandle
LogSetLevel(instance, 0, 5);
LogSetTarget(instance, 0, 1 | 2); // FILE | CONSOLE
OpenConsole(instance, 0);
LogCritical(instance, "磁盘空间不足,服务即将停止");
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 LogCritical(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, 5);
LogSetTarget(instance, 0, 1 | 2);
OpenConsole(instance, 0);
LogCritical(instance, "磁盘空间不足,服务即将停止");
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.LogCritical.argtypes = [c_int64, c_char_p]
ola.LogFlush.argtypes = [c_int64, c_int64]
instance = ola.CreateCOLAPlugInterFace()
ola.LogSetLevel(instance, 0, 5)
ola.LogSetTarget(instance, 0, 1 | 2)
ola.OpenConsole(instance, 0)
ola.LogCritical(instance, "磁盘空间不足,服务即将停止".encode("utf-8"))
ola.LogFlush(instance, 0)返回值
| 返回值 | 说明 |
|---|---|
1 | 成功。 |
0 | 失败。 |
注意事项
| 项目 | 说明 |
|---|---|
| CRITICAL 是最高级别的日志 | CRITICAL 是最高级别的日志,用于记录严重错误。 |
| OLA_LOG_LEVEL_CRITICAL | 只有当日志级别设置为 OLA_LOG_LEVEL_CRITICAL (5) 或更低时才会输出。 |
| CRITICAL 级别的日志会立即刷新到文件(如 | CRITICAL 级别的日志会立即刷新到文件(如果设置了自动刷新间隔)。 |
| 通常表示程序即将崩溃或无法继续运行 | 通常表示程序即将崩溃或无法继续运行。 |
| 如果需要指定日志实例 | 如果需要指定日志实例,请使用 LogCriticalEx。 |
| 如果日志系统未初始化 | 如果日志系统未初始化,第一次调用时会自动初始化。 |
