This repository has been archived on 2025-03-06. You can view files and clone it, but cannot push or open issues or pull requests.
nettrans/util/net_pub.h

37 lines
829 B
C
Raw Normal View History

2024-04-16 21:34:06 +08:00
#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