migrate to spdlog for DebugLog

main
Yik Teng Hie 2 years ago
parent 41904f6fea
commit 31d84fb240

@ -4,40 +4,34 @@
#pragma once
#include <string>
#include <memory>
#include "spdlog/spdlog.h"
class CFileLog
{
public:
CFileLog();
CFileLog(const std::string& strName = R"(file_logger)");
virtual ~CFileLog();
void SetFilename(std::string csFilename);
void SetHeaderString(std::string csHeaderString);
void LogData(std::string csData, bool bCreateNew = false);
void LogDataToFile(std::string csFileName, std::string csData, bool bCreateNew = false);
void EnableRunningNumber(bool bEnable, std::string csHeader);
void InitLogger();
void SetFilename(const std::string& csFilename);
void LogData(const std::string& csData);
private:
std::string GetLogFileNameWithRunningNumber(std::string csFileName);
std::string RemoveFileExtension(std::string csFullName, std::string csRemoveExt, std::string newExt);
std::string IncAndReturnRunningLotNumberFile(std::string csFileName);
//
std::string GetTime();
std::string GetYYYYMMDD();
/////
// Variables
////
std::string m_strName;
std::string m_strFilename;
std::string m_strFilenameExt;
std::string m_strFolderName;
std::string m_strPathFilename;
std::string m_strFileExt;
std::string m_strHeaderString;
std::string m_strConfigHeader;
long m_lFileNo;
bool m_bHeaderCreated;
bool m_bLogTimeStamp;
bool m_bLogDailyFormat;
bool m_bSaveWithRunningNumber;
std::string m_strPathFilename;
bool m_bLogDailyFormat{ false };
std::shared_ptr<spdlog::logger> m_logger;
};

@ -22,15 +22,15 @@
#define COMMDLL_DLLCLASS __declspec(dllimport)
#endif
constexpr auto MAX_UNIT = 2048;
constexpr auto MAX_UNIT = 2048;
struct stGPMultiUnitDataResult
{
std::string strResult;
double dResult1;
double dResult2;
double dResult3;
double dResult4;
double dResult1;
double dResult2;
double dResult3;
double dResult4;
};
using namespace std;
@ -169,7 +169,7 @@ public:
bool StartLightVerification(int nStationNo);
void ReceiveComm(const char* cpcBuffer, int nSize);
int WaitInTeachOrCapture(int nStationNo, DWORD dwTimeout); // Monitor Either InTeach or Capture
int WaitInTeachOrCapture(int nStationNo, DWORD dwTimeout); // Monitor Either InTeach or Capture
bool Get2DMatrixResult(int nStationNo, std::string& str2DMatrixResult);
bool StartTeachPosition(int nStationNo, int nIndexX, int nIndexY, int nColFOV, int nRowFOV);
@ -203,16 +203,16 @@ public:
bool WaitStartBufferingLoopAck(int nStationNo, DWORD dwTimeout = 0);
bool RequestEndBufferingGetReady(int nStationNo);
bool WaitEndBufferingLoopAck(int nStationNo, DWORD dwTimeout = 0);
int GetNoOfBufferingCapture(int nStationNo);
int GetNoOfBufferingCapture(int nStationNo);
// Get GP Info
std::string GetInfo(int nPackageID, std::string csParameter, DWORD dwTimeout = 0, bool bWaitAck = false);
bool WaitInfoReady(DWORD dwTimeout = 0);
bool GetInfoResult(std::string& csPackageNameResult);
bool WaitInfoReady(DWORD dwTimeout = 0);
bool GetInfoResult(std::string& csPackageNameResult);
std::string GetModelNameInfo(DWORD dwTimeout = 0);
std::string GetPackageNameInfo(int nPackageID, DWORD dwTimeout = 0);
int GetPackageIdInfo(DWORD dwTimeout = 0);
int GetPackageIdInfo(DWORD dwTimeout = 0);
//
bool OpenLot(std::string csPackageName, DWORD dwTimeout = 5000);
@ -249,10 +249,10 @@ public:
bool IsModuleEnable(int nStationNo, int nInspectionModule, int nSetNo = 1);
double GetResolution(int nStationNo, bool bXResolution);
bool IsSemiT10Enable(int nStationNo);
bool IsRefLocateEnable(int nStationNo);
bool IsSemiT10Enable(int nStationNo);
bool IsRefLocateEnable(int nStationNo);
int GetInspectionSequence(int nStationNo);
int GetInspectionSequence(int nStationNo);
bool IsDiagLogDataEnable(int nStationNo);
bool IsDiagResultAlwaysGood(int nStationNo);
@ -274,11 +274,11 @@ public:
// Data Logging
void SetLogEnable(bool bEnable = true);
void SetLogFilename(std::string csFilename);
void SetLogFilename(const std::string& csFilename);
//
void InitParameters(int nStationNo, int nNoOfUnitsResult, std::vector<int>& pnGx, std::vector<int>& pnLx, std::vector<int>& pnDataSetType, int nNoOfDataSetType = 1);
void InitParameters(int nStationNo, int nNoOfUnitsResult, std::vector<int>& pnGx, std::vector<int>& pnLx, std::vector<int>& pnDataSetType, int nNoOfDataSetType = 1);
CVisionUnitResult* GetMultiUnitResult(int nStationNo, int nUnitNo, int nCat);
int GetTotalUnits(int nStationNo);
int GetTotalUnits(int nStationNo);
//
// Save the current reject image to the dedicated folder. Acknowledge R<CR> if OK or F<CR> if error.
@ -302,13 +302,13 @@ public:
bool SetInspectionInfo(int nStationNo, std::string strID, CPoint ptXY);
size_t GetMaxStnInUse() { return m_nMaxStnInUse; }
void SetMaxStnInUse(size_t nMaxStnInUse) { m_nMaxStnInUse = nMaxStnInUse; }
void SetMaxStnInUse(size_t nMaxStnInUse) { m_nMaxStnInUse = nMaxStnInUse; }
private:
void InitPviTokenConfig();
int GetPviParamNo(int nDataSetNum, int nTokenPos);
int GetPviParamNo(int nDataSetNum, int nTokenPos);
//
virtual bool ProcessDollarUnitDataSet(string& strData, CVisionUnitResult* pVisionBuffer, int nDataSetType, bool bAbsPosition = false); // $ protocol
@ -321,10 +321,10 @@ private:
bool IsValidStationNo(int nStationNo);
void ResetReceiveBuffer();
void ResetReceiveBuffer();
string TranslateResCode(const string& strCode);
void SaveLogData(std::string strMsg);
void SaveLogData(const std::string& strMsg);
// Attributes
// Option
@ -348,8 +348,8 @@ private:
vector<string> m_vec2DMatrixResult;
vector<string> m_vecImageLoadResult;
string m_strInfoResult;
string m_strOcrParamValue;
string m_strInfoResult;
string m_strOcrParamValue;
std::vector<std::vector<stGPMultiUnitDataResult>> m_stMultiUnitResult;
////
@ -376,8 +376,8 @@ private:
size_t m_nMaxStnInUse;
// Logging
CCriticalSection m_criticalSectionFileLog;
CFileLog m_FileLog;
bool m_bLogEnable;
CFileLog m_FileLog;
bool m_bLogEnable;
bool m_bLocalLoopback;
// E30
@ -386,8 +386,8 @@ private:
//
std::unique_ptr<CICameraId> m_camId;
string m_strOneLine;
string m_strDryRunExceptionCode;
string m_strOneLine;
string m_strDryRunExceptionCode;
std::vector<CMyPoint> m_ptPackageSize;

@ -34,20 +34,20 @@ public:
private:
CConcurrentQueue<CBufferedSocketMessage>* m_pMessageQueue;
CConcurrentQueue<CBufferedSocketMessage>* m_pSendQueue;
CBufferMessageThread* m_pMessageThread;
CBufferMessageThread* m_PSenderThread;
IBufferSocketCallBack* m_pCallBack;
CReceivingThread* m_pReceivingThread;
CEvt* m_hConnectedEvent;
SOCKET s;
bool bIsConnected;
CBufferMessageThread* m_pMessageThread;
CBufferMessageThread* m_PSenderThread;
IBufferSocketCallBack* m_pCallBack;
CReceivingThread* m_pReceivingThread;
CEvt* m_hConnectedEvent;
SOCKET s;
bool bIsConnected;
// Private methods
protected:
void OnReceive(const char* buf, size_t len);
void OnDisconnect(int errorCode);
int Read(char* buf, size_t size);
int Write(const char* buf, size_t len);
int Read(char* buf, size_t size);
int Write(const char* buf, size_t len);
private:
CBufferedSocket(const CBufferedSocket&);

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -23,5 +23,5 @@ public:
int m_nCurrentIndex;
private:
CWinThread* m_pGalilIntThread[4];
std::array<CWinThread*, 4> m_pGalilIntThread;
};

@ -1,14 +1,66 @@
#pragma once
#include "fmt/format.h"
#include "DllDefines.h"
void UTILITYDLL DebugLog(LPSTR lpFormat, ...);
void UTILITYDLL DebugLog(bool bTraceData, LPSTR lpFormat, ...);
void UTILITYDLL DebugLog(LPCTSTR lpName, bool bTraceData, LPSTR lpFormat, ...);
#ifdef LEGACY_LOGGER
#include "LegacyDebugLog.h"
#include "LegacyDebugLogTiming.h"
#include "LegacyGuiEventLog.h"
extern UTILITYDLL CLegacyDebugLog mitechDebug;
extern UTILITYDLL CLegacyDebugLogTiming mitechDebugLogTiming;
extern UTILITYDLL CLegacyGuiEventLog mitechGuiEventLog;
#else
#include "MitechDebugLog.h"
#include "MitechDebugLogTiming.h"
#include "MitechGuiEventLog.h"
extern UTILITYDLL CMitechDebugLog mitechDebug;
extern UTILITYDLL CMitechDebugLogTiming mitechDebugLogTiming;
extern UTILITYDLL CMitechGuiEventLog mitechGuiEventLog;
#endif
//
template <typename... Args>
void DebugLog(fmt::format_string<Args...> _fmt, Args&&... args)
{
mitechDebug.Log(_fmt, args...);
}
void UTILITYDLL DebugLogTiming(LPSTR lpFormat, ...);
void UTILITYDLL DebugLogTiming(bool bTraceData, LPSTR lpFormat, ...);
void UTILITYDLL DebugLogTiming(LPCTSTR lpName, bool bTraceData, LPSTR lpFormat, ...);
template <typename... Args>
void DebugLogTrace(bool bTraceData, fmt::format_string<Args...> _fmt, Args&&... args)
{
if (bTraceData)
{
mitechDebug.Log(_fmt, args...);
}
}
template <typename... Args>
void DebugLogTiming(fmt::format_string<Args...> _fmt, Args&&... args)
{
mitechDebugLogTiming.Log(_fmt, args...);
}
template <typename... Args>
void DebugLogTimingTrace(bool bTraceData, fmt::format_string<Args...> _fmt, Args&&... args)
{
if (bTraceData)
{
mitechDebugLogTiming.Log(_fmt, args...);
}
}
template <typename... Args>
void GUIEventLog(fmt::format_string<Args...> _fmt, Args&&... args)
{
mitechGuiEventLog.Log(_fmt, args...);
}
void UTILITYDLL ShutdownLogging();
void UTILITYDLL StartDebugLog();
void UTILITYDLL StopDebugLog();
@ -20,7 +72,5 @@ bool UTILITYDLL IsDebugLogStarted();
bool UTILITYDLL IsDebugLogTimingStarted();
// All GUI Activities Events Log
void UTILITYDLL GUIEventLog(LPSTR lpFormat, ...);
void UTILITYDLL StartGUIEventLog();
void UTILITYDLL StopGUIEventLog();

@ -0,0 +1,20 @@
#pragma once
#include "Logger.h"
#include "dbg.h"
class CLegacyDebugLog : public CLogger
{
public:
explicit CLegacyDebugLog(const std::string& strName);
~CLegacyDebugLog() final;
private:
void InitLogger();
// Inherited via CLogger
void DoStart() override;
void DoFlush() override;
void DoLogging(const std::string& strMsg) override;
//
CDebugPrintf m_logger{ 0 };
};

@ -0,0 +1,19 @@
#pragma once
#include "Logger.h"
#include "dbg.h"
class CLegacyDebugLogTiming : public CLogger
{
public:
CLegacyDebugLogTiming(const std::string& strName);
~CLegacyDebugLogTiming() final;
private:
void InitLogger();
// Inherited via CLogger
void DoStart() override;
void DoFlush() override;
void DoLogging(const std::string& strMsg) override;
CDebugPrintf m_logger{ 1 };
};

@ -0,0 +1,20 @@
#pragma once
#include "Logger.h"
#include "dbg.h"
class CLegacyGuiEventLog : public CLogger
{
public:
CLegacyGuiEventLog(const std::string& strName);
~CLegacyGuiEventLog() final;
private:
void InitLogger();
// Inherited via CLogger
void DoStart() override;
void DoFlush() override;
void DoLogging(const std::string& strMsg) override;
CDebugPrintf m_logger{ 2 };
};

@ -0,0 +1,54 @@
#pragma once
#include <string>
#include "fmt/format.h"
#include "fmt/args.h"
#include "DllDefines.h"
class UTILITYDLL CLogger
{
public:
CLogger(const std::string& strName);
virtual ~CLogger();
void Start();
void Stop();
void SetEnable(bool bEnable) { m_bEnable = bEnable; }
void Log(const std::string& strMsg);
template <typename... Args>
void Log(fmt::format_string<Args...> _fmt, Args&&... args)
{
try
{
std::vector<char> buf;
fmt::vformat_to(std::back_inserter(buf), _fmt, fmt::make_format_args(args...));
std::string log_msg(std::string_view(buf.data(), buf.size()));
Log(log_msg);
}
catch (...)
{
}
}
protected:
bool IsEnable() const { return m_bEnable; }
std::string GetName() { return m_strName; }
private:
virtual void DoStart() = 0;
virtual void DoFlush() = 0;
virtual void DoLogging(const std::string& strMsg) = 0;
std::string m_strName;
bool m_bEnable{ false };
bool m_bRotating{ true };
int m_nFileSizeMB{ 1 };
//
};

@ -0,0 +1,28 @@
#pragma once
#include <string>
#include <memory>
#include "spdlog/spdlog.h"
#include "Logger.h"
#include "DllDefines.h"
class UTILITYDLL CMitechDebugLog : public CLogger
{
public:
explicit CMitechDebugLog(const std::string& strName);
~CMitechDebugLog() final;
private:
void InitLogger();
// Inherited via CLogger
void DoStart() override;
void DoFlush() override;
void DoLogging(const std::string& strMsg) override;
std::shared_ptr<spdlog::logger> m_logger;
std::string m_strPathFilename{ R"(d:\machine\log\DebugLog.log)" };
};

@ -0,0 +1,27 @@
#pragma once
#include <string>
#include <memory>
#include "spdlog/spdlog.h"
#include "Logger.h"
class CMitechDebugLogTiming : public CLogger
{
public:
CMitechDebugLogTiming(const std::string& strName);
~CMitechDebugLogTiming() final;
private:
void InitLogger();
// Inherited via CLogger
void DoStart() override;
void DoFlush() override;
void DoLogging(const std::string& strMsg) override;
std::shared_ptr<spdlog::logger> m_logger;
std::string m_strPathFilename{ R"(d:\machine\log\DebugLogTiming.log)" };
};

@ -0,0 +1,26 @@
#pragma once
#include <memory>
#include <string>
#include "spdlog/spdlog.h"
#include "Logger.h"
class CMitechGuiEventLog : public CLogger
{
public:
CMitechGuiEventLog(const std::string& strName);
~CMitechGuiEventLog() final;
private:
void InitLogger();
// Inherited via CLogger
void DoStart() override;
void DoFlush() override;
void DoLogging(const std::string& strMsg) override;
std::shared_ptr<spdlog::logger> m_logger;
std::string m_strPathFilename{ R"(d:\machine\log\GuiEventLog.log)" };
};

@ -0,0 +1,28 @@
#pragma once
// third party library
#include "fmt/format.h"
#include "spdlog/pattern_formatter.h"
// mitech library
#include "utility.h"
class CTimingFormatterFlag : public spdlog::custom_flag_formatter
{
public:
void format(const spdlog::details::log_msg&, const std::tm&, spdlog::memory_buf_t& dest) override
{
auto myTime = m_HighResCounter.GetCurrentTimeSpanInMsec();
std::string strTime = fmt::format("{:d}.{:03d}", (myTime / 1000), (myTime % 1000));
dest.append(strTime.data(), strTime.data() + strTime.size());
}
std::unique_ptr<custom_flag_formatter> clone() const override
{
return spdlog::details::make_unique<CTimingFormatterFlag>();
}
private:
CHighResPerformanceCounter m_HighResCounter;
};

@ -54,7 +54,7 @@ class CDebugPrintf
public:
bool LogStarted();
void StopLog();
void StartLog(char* cFilename = NULL);
void StartLog(char* cFilename = nullptr);
CDebugPrintf(int nDebugType = 0);
virtual ~CDebugPrintf();

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save