37 lines
829 B
C
37 lines
829 B
C
|
#ifndef NET_PUB_HPP
|
||
|
#define NET_PUB_HPP
|
||
|
|
||
|
#include <spdlog/sinks/rotating_file_sink.h>
|
||
|
#include <spdlog/spdlog.h>
|
||
|
|
||
|
#include <memory>
|
||
|
#include <mutex>
|
||
|
|
||
|
typedef std::shared_ptr<spdlog::logger> NetLog;
|
||
|
class CNetPub {
|
||
|
public:
|
||
|
static NetLog getInstance()
|
||
|
{
|
||
|
if (log_) {
|
||
|
return log_;
|
||
|
}
|
||
|
mutex_->lock();
|
||
|
if (log_) {
|
||
|
mutex_->unlock();
|
||
|
return log_;
|
||
|
}
|
||
|
log_ = spdlog::rotating_logger_mt("nettrans", "log/nettrans.log",
|
||
|
1024 * 100, 5);
|
||
|
log_->set_pattern("[%Y-%m-%d %H:%M:%S.%e][%l]: %v");
|
||
|
log_->set_level(spdlog::level::info);
|
||
|
mutex_->unlock();
|
||
|
return log_;
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
static NetLog log_;
|
||
|
static std::shared_ptr<std::mutex> mutex_;
|
||
|
};
|
||
|
|
||
|
#endif
|