이전 버전(1.33.4)의 문서를 보고 있습니다. 이 버전은 계속 지원됩니다.
최신 버전 정보는 1.33.5에서 확인하세요.
최신 버전 정보는 1.33.5에서 확인하세요.
set_on_tp_log
이 함수는 DRL에서 tp_log 명령을 사용할 때 로그 메시지를 확인하는 콜백 함수를 등록합니다. 이 이벤트가 발생할 때 원하는 코드를 자동으로 실행하는 데 사용하세요.
정의
DRFLEx.h, CDRFLEx 클래스의 public 섹션
void set_on_tp_log(TOnTpLogCB pCallbackFunc) {
_set_on_tp_log(_rbtCtrl, pCallbackFunc);
};
매개변수
매개변수 이름 |
자료형 |
기본값 |
설명 |
|---|---|---|---|
pCallbackFunc |
콜백 함수 정의를 참고하세요 |
반환값
없음
참고
콜백 함수 규칙을 참고하세요.
예제
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <string>
#include <thread>
#include <chrono>
// 타임스탬프를 추가하는 간단한 유틸리티
string GetTimestamp()
{
time_t now = time(0);
tm* ltm = localtime(&now);
char buffer[64];
sprintf(buffer, "%04d-%02d-%02d %02d:%02d:%02d",
1900 + ltm->tm_year, 1 + ltm->tm_mon, ltm->tm_mday,
ltm->tm_hour, ltm->tm_min, ltm->tm_sec);
return string(buffer);
}
// TP 로그 메시지용 콜백 함수
void OnTpLog(const char* strLog)
{
printf("[%s] [TP LOG] %s\n", GetTimestamp().c_str(), strLog);
// 예: 로컬 로그 파일에도 저장
ofstream logFile("tp_log_history.txt", ios::app);
if (logFile.is_open())
{
logFile << "[" << GetTimestamp() << "] " << strLog << endl;
logFile.close();
}
// 예: 특정 이벤트 키워드 감지
if (strstr(strLog, "Warning"))
printf("[Host] Warning detected from TP log.\n");
}
// TP 로그 콜백 함수 등록
drfl.set_on_tp_log(OnTpLog);
printf("Waiting for TP log events...\n");
while (true)
{
this_thread::sleep_for(chrono::seconds(1));
}
등록한 콜백 함수는 DRL을 통해 티치펜던트(TP)에서 로그 메시지가 발생하면 자동으로 실행됩니다. 이 콜백으로 TP 이벤트를 실시간으로 모니터링하고 기록할 수 있으며, 필요에 따라 메시지를 저장하거나 걸러내거나 대응할 수 있습니다.