You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.0 KiB
C++

#pragma once
#include "nlohmann/json.hpp"
#include "GeneralUtils.h"
namespace mitech::utils::logging
{
constexpr auto MAX_FILESIZE_MB = 1;
constexpr auto MAX_RUNNING_NUMBER = 99;
using stLogOption = struct _stLogOption
{
bool enable{ false };
// daily 1:30am
bool daily_log{ false };
int daily_hour{ 1 };
int daily_minute{ 30 };
// rotating 1MB 99 files
int filesize_mb{ MAX_FILESIZE_MB };
int rotating_files{ MAX_RUNNING_NUMBER };
//
bool debug_console{ false };
int flush_level{ 6 }; // default : 6=off
//
std::string path_file{};
};
using stLogGlobal = struct _stLogGlobal
{
int flush_interval_s{ 3 };
int flush_level{ 6 }; // 6=off
};
}
namespace mitech::utils::logging
{
using namespace nlohmann;
using namespace nsUtils;
void from_json(const json& j, stLogOption& x);
void to_json(json& j, const stLogOption& x);
void from_json(const json& j, stLogGlobal& x);
void to_json(json& j, const stLogGlobal& x);
inline void from_json(const json& j, stLogOption& x)
{
getValue(j, "enable", x.enable);
getValue(j, "daily_log", x.daily_log);
getValue(j, "daily_hour", x.daily_hour);
getValue(j, "daily_minute", x.daily_minute);
}
inline void to_json(json& j, const stLogOption& x)
{
j = nlohmann::json{
{ "enable", x.enable},
{ "daily_log", x.daily_log},
{ "daily_hour", x.daily_hour},
{ "daily_minute", x.daily_minute }
};
}
//
inline void from_json(const json& j, stLogGlobal& x)
{
getValue(j, "flush_interval_s", x.flush_interval_s);
getValue(j, "flush_level", x.flush_level);
}
inline void to_json(json& j, const stLogGlobal& x)
{
j = nlohmann::json{
{ "flush_interval_s", x.flush_interval_s },
{ "flush_level", x.flush_level }
};
}
}