[PlantSimulation]#C015#C语言接口学习-官方DEMO功能扩展

本文介绍了如何在MATLAB的DLL项目中,通过log4cxx库添加日志功能,包括配置文件设置、代码中的日志记录和调用过程。展示了如何在接口函数前后插入日志信息以便追踪调用细节。
摘要由CSDN通过智能技术生成

功能扩展,增加日志记录功能。

为了记录dll接口方法的调用细节,可以在接口中添加日志文件。此处使用log4cxx进行演示。

一、项目配置

指定log4cxx包含目录和库目录

image.png

二、代码

1、引用

MATLAB

#include "log4cxx/logger.h"
#include "log4cxx/propertyconfigurator.h"
using namespace log4cxx;
using namespace log4cxx::helpers;
LoggerPtr logger;

2、初始化

MATLAB

extern "C" __declspec(dllexport)
void LogCxxInit(UF_Value* ret, UF_Value* arg)
{
    string trace = "fa";
    string Property = "./log4cxx.properties";
    log4cxx::PropertyConfigurator::configure(Property);
    logger = Logger::getLogger(trace);
    ret->type = UF_NONE;
}

3、调用

MATLAB

extern "C" __declspec(dllexport)
void calcSin(UF_Value *ret, UF_Value *arg)
{
    LOG4CXX_INFO(logger, ("calcSin invoke start"));
    ret->type = UF_REAL;
    ret->value.real = sin(arg[0].value.real);
    LOG4CXX_INFO(logger, ("calcSin invoke end"));
}

三、项目调用

MATLAB

openConsole
var file:string := to_str(getCurrentDirectory, "\PlantSimulationInterfaceDemo.dll")
var j := loadLibrary(file)
if j > 0 
    print getLoadedLibrary(j)," is loaded."
    
    callLibrary(j,"LogCxxInit")
    
    var r := callLibrary(j, "calcSin", PI/6)
    promptmessage(to_str("sin(PI/6) = ", r))
    
    print "Unloading: ", freeLibrary(j)
end
  • 10
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值