migrate to spdlog for DebugLog
parent
41904f6fea
commit
31d84fb240
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.
@ -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;
|
||||
};
|
||||
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue