Commit 20c5c31a authored by captainwong's avatar captainwong

test pass

parent ed8f8d65
Pipeline #30 failed with stages
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <string> #include <string>
#include "utf8.h" #include "utf8.h"
#include "log.h" #include "log2.h"
#include "chrono_wrapper.h" #include "chrono_wrapper.h"
#include "micro_getter_setter.h" #include "micro_getter_setter.h"
#include "dp.h" #include "dp.h"
......
#pragma once
#include <iostream>
#include "D:/dev_libs/spdlog-0.13.0/include/spdlog/spdlog.h"
#include "D:/dev_libs/spdlog-0.13.0/include/spdlog/sinks/msvc_sink.h"
#include "utf8.h"
namespace jlib{
static const char g_logger_name[] = "logger";
inline void init_logger(const std::string& file_name = "")
{
try {
std::vector<spdlog::sink_ptr> sinks;
#ifdef WIN32
sinks.push_back(std::make_shared<spdlog::sinks::msvc_sink_mt>());
#endif
sinks.push_back(std::make_shared<spdlog::sinks::stdout_sink_mt>());
sinks.push_back(std::make_shared<spdlog::sinks::daily_file_sink_mt>(utf8::a2w(file_name + ".log"), 23, 59));
auto combined_logger = std::make_shared<spdlog::logger>(g_logger_name, begin(sinks), end(sinks));
combined_logger->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [tid %t] [%L] %v");
spdlog::register_logger(combined_logger);
} catch (const spdlog::spdlog_ex& ex) {
std::cerr << "Log initialization failed: " << ex.what() << std::endl;
}
}
#define JLOG_INFO spdlog::get(g_logger_name)->info
#define JLOG_WARN spdlog::get(g_logger_name)->warn
#define JLOG_ERRO spdlog::get(g_logger_name)->error
#define JLOG_CRTC spdlog::get(g_logger_name)->critical
//#define JLOG JLOG_INFO
#define JLOGB(b, l) (b, l)
#define JLOGASC(b, l) (b, l)
class range_log
{
private:
std::string msg_;
std::chrono::steady_clock::time_point begin_;
public:
range_log(const std::string& msg) : msg_(msg) {
JLOG_INFO(msg_ + " in");
begin_ = std::chrono::steady_clock::now();
}
range_log(const std::wstring& msg) : msg_() {
msg_ = utf8::w2a(msg);
JLOG_INFO(msg_ + " in");
begin_ = std::chrono::steady_clock::now();
}
~range_log() {
auto diff = std::chrono::steady_clock::now() - begin_;
auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(diff);
JLOG_INFO("{} out, duration: {}(ms)\n", msg_, msec.count());
}
};
#define AUTO_LOG_FUNCTION jlib::range_log __log_function_object__(__func__);
}
...@@ -78,7 +78,7 @@ private: ...@@ -78,7 +78,7 @@ private:
{ {
if (num_replies_ == 0) { if (num_replies_ == 0) {
total_time_ += std::chrono::milliseconds(5000); total_time_ += std::chrono::milliseconds(5000);
JLOGA("Request timed out"); JLOG_ERRO("Request timed out");
} }
if (!quiting_) { if (!quiting_) {
...@@ -129,12 +129,12 @@ private: ...@@ -129,12 +129,12 @@ private:
<< ": icmp_seq=" << icmp_hdr.sequence_number() << ": icmp_seq=" << icmp_hdr.sequence_number()
<< ", ttl=" << ipv4_hdr.time_to_live() << ", ttl=" << ipv4_hdr.time_to_live()
<< ", time=" << ms << " ms"; << ", time=" << ms << " ms";
JLOGA(ss.str().c_str()); JLOG_INFO(ss.str());
total_time_ += std::chrono::milliseconds(ms); total_time_ += std::chrono::milliseconds(ms);
auto cnt = total_time_.count(); auto cnt = total_time_.count();
ss.str(""); ss.clear(); ss.str(""); ss.clear();
ss << "total_time_ " << cnt; ss << "total_time_ " << cnt;
JLOGA(ss.str().c_str()); JLOG_INFO(ss.str());
} }
if (max_sequence_number_ != 0 && sequence_number_ < max_sequence_number_) if (max_sequence_number_ != 0 && sequence_number_ < max_sequence_number_)
......
#pragma once #pragma once
namespace jlib namespace jlib
{ {
inline const wchar_t* FormatWSAError(int errornumber) inline const wchar_t* FormatWSAError(int errornumber)
...@@ -81,4 +83,9 @@ namespace jlib ...@@ -81,4 +83,9 @@ namespace jlib
} }
} }
inline const char* FormatWSAErrorA(int errornumber)
{
return utf8::w2a(FormatWSAError(errornumber)).c_str();
}
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment