github.com/gabime/spdl…
#pragma once
#include "Singleton.h"
#include "DataModel.h"
#include "include/spdlog/spdlog.h"
#include "include/spdlog/sinks/rotating_file_sink.h"
#include "include/spdlog/fmt/ostr.h"
using namespace spdlog;
std::ostream& operator<<(std::ostream& os, const MedibusServer::EssentialInfo& info)
{
return os << "info.MedibusCode:" << "<" << info.MedibusCode << ">"
<< "info.CF10Code:" << "<" << info.CF10Code << ">"
<< "info.CF10CodeDes:" << "<" << info.CF10CodeDes << ">"
<< "info.facility:" << "<" << info.facility << ">"
<< "info.bed:" << "<" << info.bed << ">"
<< "info.poc:" << "<" << info.poc << ">"
<< std::endl;
}
template <> struct fmt::formatter<MedibusServer::EssentialInfo> : fmt::ostream_formatter {};
std::ostream& operator<<(std::ostream& os, const MedibusServer::AlarmInfo& info)
{
return os << "MedibusCode: " << "<" << info.CommonInfo.MedibusCode << ">"
<< "MedibusCodePage: " << "<" << info.CommonInfo.MedibusCodePage << ">"
<< "CF10TypeCode: " << "<" << info.CommonInfo.CF10TypeCode << ">"
<< "CF10TypeCodeDes: " << "<" << info.CommonInfo.CF10TypeCodeDes << ">"
<< "VmdHandle: " << "<" << info.CommonInfo.VmdHandle << ">"
<< "VmdCF10Code: " << "<" << info.CommonInfo.VmdCF10Code << ">"
<< "VmdCF10CodeDes: " << "<" << info.CommonInfo.VmdCF10CodeDes << ">"
<< "ChannelHandle: " << "<" << info.CommonInfo.ChannelHandle << ">"
<< "ChannelCF10Code: " << "<" << info.CommonInfo.ChannelCF10Code << ">"
<< "ChannelCF10CodeDes: " << "<" << info.CommonInfo.ChannelCF10CodeDes << ">"
<< "MedicalClass: " << "<" << info.CommonInfo.MedicalClass << ">"
<< "Context: " << "<" << info.CommonInfo.Context << ">"
<< "Handle: " << "<" << info.CommonInfo.Handle << ">"
<< "Source: " << "<" << info.Source << ">"
<< "Kind: " << "<" << info.Kind << ">"
<< "Priority: " << "<" << info.Priority << ">"
<< "AlertType: " << "<" << info.AlertType << ">"
<< "InitialActivationState: " << "<" << info.InitialActivationState << ">"
<< "SystemAlarmHandle: " << "<" << info.SysAlarmInfo.Handle << ">"
<< "SelfCheckPeriod: " << "<" << info.SysAlarmInfo.SelfCheckPeriod << ">"
<< "MaxPhysiologicalParallelAlarms: " << "<" << info.SysAlarmInfo.MaxPhysiologicalParallelAlarms << ">"
<< "MaxTechnicalParallelAlarms: " << "<" << info.SysAlarmInfo.MaxTechnicalParallelAlarms << ">"
<< std::endl;
}
template <> struct fmt::formatter<MedibusServer::AlarmInfo> : fmt::ostream_formatter {};
std::ostream& operator<<(std::ostream& os, const MedibusServer::MetricInfo& info)
{
return os << "MedibusCode: " << "<" << info.MedibusCode << ">"
<< "MedibusCodePage: " << "<" << info.MedibusCodePage << ">"
<< "CF10TypeCode: " << "<" << info.CF10TypeCode << ">"
<< "CF10TypeCodeDes: " << "<" << info.CF10TypeCodeDes << ">"
<< "UnitCode: " << "<" << info.UnitCode << ">"
<< "VmdHandle: " << "<" << info.VmdHandle << ">"
<< "VmdCF10Code: " << "<" << info.VmdCF10Code << ">"
<< "VmdCF10CodeDes: " << "<" << info.VmdCF10CodeDes << ">"
<< "ChannelHandle: " << "<" << info.ChannelHandle << ">"
<< "ChannelCF10Code: " << "<" << info.ChannelCF10Code << ">"
<< "ChannelCF10CodeDes: " << "<" << info.ChannelCF10CodeDes << ">"
<< "MedicalClass: " << "<" << info.MedicalClass << ">"
<< "Context: " << "<" << info.Context << ">"
<< "Handle: " << "<" << info.Handle << ">"
<< "CurAllowedValueCode: " << "<" << info.CurAllowedValueCode << ">"
<< "CurAllowedValue: " << "<" << info.CurAllowedValue << ">"
<< "Category: " << "<" << info.Category << ">"
<< "Availability: " << "<" << info.Availability << ">"
<< "Derivation: " << "<" << info.Derivation << ">"
<< "Resolution: " << "<" << info.Resolution << ">"
<< "DeterminationPeriod: " << "<" << info.DeterminationPeriod << ">"
<< "MaxDelayTime: " << "<" << info.MaxDelayTime << ">"
<< "LifeTimePeriod: " << "<" << info.LifeTimePeriod << ">"
<< "SamplePeriod: " << "<" << info.SamplePeriod << ">"
<< "LowRange: " << "<" << info.LowRange << ">"
<< "UpperRange: " << "<" << info.UpperRange << ">"
<< std::endl;
}
template <> struct fmt::formatter<MedibusServer::MetricInfo> : fmt::ostream_formatter {};
std::ostream& operator<<(std::ostream& os, const MedibusServer::DeviceInfo& info)
{
return os << "DeviceName: " << "<" << info.DeviceName << ">"
<< "DeviceId: " << "<" << info.DeviceId << ">"
<< "CF10TypeCode: " << "<" << info.CF10TypeCode << ">"
<< "CF10TypeCodeDes: " << "<" << info.CF10TypeCodeDes << ">"
<< "Context: " << "<" << info.Context << ">"
<< std::endl;
}
template <> struct fmt::formatter<MedibusServer::DeviceInfo> : fmt::ostream_formatter {};
namespace MedibusServer
{
enum level_enum : int {
trace = SPDLOG_LEVEL_TRACE,
debug = SPDLOG_LEVEL_DEBUG,
info = SPDLOG_LEVEL_INFO,
warn = SPDLOG_LEVEL_WARN,
err = SPDLOG_LEVEL_ERROR,
critical = SPDLOG_LEVEL_CRITICAL,
off = SPDLOG_LEVEL_OFF,
n_levels
};
class LogHelper : public Singleton<LogHelper>
{
public:
friend class Singleton<LogHelper>;
void Init()
{
m_LogFile = spdlog::rotating_logger_mt("rotatelog", "logs/medibus.log", 1048576 * 5, 3);
}
void LogFile(std::string msg, level_enum logLevel = level_enum::debug)
{
spdlog::set_level(static_cast<spdlog::level::level_enum>(logLevel));
m_LogFile->debug(msg);
}
void LogFile(std::string msg, std::string instanceId, std::string sequenceId, std::string Info) {
m_LogFile->debug("{} Instance Id is {}, Sequence Id is {}, string {}", msg, instanceId, sequenceId, Info);
}
void LogFile(std::string msg, std::string instanceId, std::string sequenceId, EssentialInfo Info) {
m_LogFile->debug("{} Instance Id is {}, Sequence Id is {}, EssentialInfo {}", msg, instanceId, sequenceId, Info );
}
void LogFile(std::string msg, std::string instanceId, std::string sequenceId, MetricInfo Info) {
m_LogFile->debug("{} Instance Id is {}, Sequence Id is {}, MetricInfo {}", msg, instanceId, sequenceId, Info);
}
void LogFile(std::string msg, std::string instanceId, std::string sequenceId, DeviceInfo Info) {
m_LogFile->debug("{} Instance Id is {}, Sequence Id is {}, DeviceInfo {}", msg, instanceId, sequenceId, Info);
}
void LogFile(std::string msg, std::string instanceId, std::string sequenceId, AlarmInfo Info) {
m_LogFile->debug("{} Instance Id is {}, Sequence Id is {}, AlarmInfo {}", msg, instanceId, sequenceId, Info);
}
private:
LogHelper() = default;
~LogHelper() = default;
std::shared_ptr<spdlog::logger> m_LogFile;
};
}