国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當前位置: 首頁 > news >正文

超市網(wǎng)站模版網(wǎng)絡推廣培訓班

超市網(wǎng)站模版,網(wǎng)絡推廣培訓班,在統(tǒng)計局網(wǎng)站上如何做圖表,wordpress又拍云不講理論,直接上在程序中可用代碼: 一、引入Boost模塊 開發(fā)環(huán)境:Visual Studio 2017 Boost庫版本:1.68.0 安裝方式:Nuget 安裝命令: #只安裝下面幾個即可 Install-package boost -version 1.68.0 Install…

不講理論,直接上在程序中可用代碼:
一、引入Boost模塊

開發(fā)環(huán)境:Visual Studio 2017
Boost庫版本:1.68.0
安裝方式:Nuget
安裝命令:

#只安裝下面幾個即可
Install-package boost -version 1.68.0
Install-package boost_filesystem-vc141 -version 1.68.0
Install-package boost_log_setup-vc141 -version 1.68.0
Install-package boost_log-vc141 -version 1.68.0#這里是其他模塊,可不安裝
Install-package boost_atomic-vc141 -version 1.68.0
Install-package boost_chrono-vc141 -version 1.68.0
Install-package boost_date_time-vc141 -version 1.68.0
Install-package boost_system-vc141 -version 1.68.0
Install-package boost_thread-vc141 -version 1.68.0
Install-package boost_locale-vc141 -version 1.68.0

調用Nuget控制臺:

?

二、引入下面兩個hpp文件
boost_logger.hpp

#pragma once#include <string>
#include <fstream>
#include <iostream>
#include <boost/filesystem.hpp>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/core/null_deleter.hpp>
#include <boost/log/core.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/sinks/async_frontend.hpp>
#include <boost/log/sinks/text_ostream_backend.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/support/date_time.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/attributes/current_thread_id.hpp>
#include <boost/log/attributes/current_process_name.hpp>
#include <boost/log/attributes/attribute.hpp>
#include <boost/log/attributes/attribute_cast.hpp>
#include <boost/log/attributes/attribute_value.hpp>
#include <boost/log/sinks/async_frontend.hpp>// Related headersQDebug
#include <boost/log/sinks/unbounded_fifo_queue.hpp>
#include <boost/log/sinks/unbounded_ordering_queue.hpp>
#include <boost/log/sinks/bounded_fifo_queue.hpp>
#include <boost/log/sinks/bounded_ordering_queue.hpp>
#include <boost/log/sinks/drop_on_overflow.hpp>
#include <boost/log/sinks/block_on_overflow.hpp>//這里是logger的頭文件,后面根據(jù)實際路徑引入
#include "logger.hpp"//引入各種命名空間
namespace logging = boost::log;
namespace src = boost::log::sources;
namespace expr = boost::log::expressions;
namespace sinks = boost::log::sinks;
namespace keywords = boost::log::keywords;
namespace attrs = boost::log::attributes;
//建立日志源,支持嚴重屬性
thread_local static boost::log::sources::severity_logger<log_level> lg;#define BOOST_LOG_Q_SIZE 1000//創(chuàng)建輸出槽:synchronous_sink是同步前端,允許多個線程同時寫日志,后端無需考慮多線程問題
typedef sinks::asynchronous_sink<sinks::text_file_backend, sinks::bounded_fifo_queue<BOOST_LOG_Q_SIZE, sinks::block_on_overflow>> sink_t;
static std::ostream &operator<<(std::ostream &strm, log_level level)
{static const char *strings[] ={"debug","info","warn","error","critical"};if (static_cast<std::size_t>(level) < sizeof(strings) / sizeof(*strings))strm << strings[level];elsestrm << static_cast<int>(level);return strm;
}
class boost_logger : public logger_iface
{
public:boost_logger(const std::string& dir) : m_level(log_level::error_level), dir(dir){}~boost_logger(){}/*** 日志初始化*/void init() override{//判斷日志文件所在路徑是否存在if (boost::filesystem::exists(dir) == false){boost::filesystem::create_directories(dir);}//添加公共屬性logging::add_common_attributes();//獲取日志庫核心core = logging::core::get();//創(chuàng)建后端,并設值日志文件相關控制屬性boost::shared_ptr<sinks::text_file_backend> backend = boost::make_shared<sinks::text_file_backend>(keywords::open_mode = std::ios::app, // 采用追加模式keywords::file_name = dir + "/%Y%m%d_%N.log", //歸檔日志文件名keywords::rotation_size = 10 * 1024 * 1024, //超過此大小自動建立新文件keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0), //每隔指定時間重建新文件keywords::min_free_space = 100 * 1024 * 1024  //最低磁盤空間限制);if (!_sink){_sink.reset(new sink_t(backend));//向日志源添加槽core->add_sink(_sink);}//添加線程ID公共屬性core->add_global_attribute("ThreadID", attrs::current_thread_id());//添加進程公共屬性core->add_global_attribute("Process", attrs::current_process_name());//設置過濾器_sink->set_filter(expr::attr<log_level>("Severity") >= m_level);// 如果不寫這個,它不會實時的把日志寫下去,而是等待緩沖區(qū)滿了,或者程序正常退出時寫下// 這樣做的好處是減少IO操作,提高效率_sink->locked_backend()->auto_flush(true); // 使日志實時更新//這些都可在配置文件中配置_sink->set_formatter(expr::stream<< "["<< expr::attr<std::string>("Process") << ":" << expr::attr<attrs::current_thread_id::value_type>("ThreadID") << ":"<< expr::attr<unsigned int>("LineID") << "]["<< expr::format_date_time<boost::posix_time::ptime>("TimeStamp", "%Y-%m-%d %H:%M:%S.%f") << "]["<< expr::attr<log_level>("Severity") << "] "<< expr::smessage);}/*** 停止記錄日志*/void stop() override{warn_log("boost logger stopping");_sink->flush();_sink->stop();core->remove_sink(_sink);}/*** 設置日志級別*/void set_log_level(log_level level) override{m_level = level;if (_sink){_sink->set_filter(expr::attr<log_level>("Severity") >= m_level);}}log_level get_log_level() override{return m_level;}void debug_log(const std::string &msg) override{BOOST_LOG_SEV(lg, debug_level) << msg << std::endl;}void info_log(const std::string &msg) override{BOOST_LOG_SEV(lg, info_level) << blue << msg << normal << std::endl;}void warn_log(const std::string &msg) override{BOOST_LOG_SEV(lg, warn_level) << yellow << msg << normal << std::endl;}void error_log(const std::string &msg) override{BOOST_LOG_SEV(lg, error_level) << red << msg << normal << std::endl;}void critical_log(const std::string &msg) override{BOOST_LOG_SEV(lg, critical_level) << red << msg << normal << std::endl;}private:log_level m_level;boost::shared_ptr<logging::core> core;boost::shared_ptr<sink_t> _sink;//日志文件路徑const std::string& dir;
};

logger.hpp

#pragma once
#define BOOST_ALL_DYN_LINK#include <string>   // std::string
#include <iostream> // std::cout
#include <fstream>
#include <sstream> // std::ostringstream
#include <memory>typedef std::basic_ostringstream<char> tostringstream;
static const char black[] = {0x1b, '[', '1', ';', '3', '0', 'm', 0};
static const char red[] = {0x1b, '[', '1', ';', '3', '1', 'm', 0};
static const char yellow[] = {0x1b, '[', '1', ';', '3', '3', 'm', 0};
static const char blue[] = {0x1b, '[', '1', ';', '3', '4', 'm', 0};
static const char normal[] = {0x1b, '[', '0', ';', '3', '9', 'm', 0};
#define ACTIVE_LOGGER_INSTANCE (*activeLogger::getLoggerAddr())
// note: this will replace the logger instace. If this is not the first time to set the logger instance.
// Please make sure to delete/free the old instance.
#define INIT_LOGGER(loggerImpPtr)              \{                                           \ACTIVE_LOGGER_INSTANCE = loggerImpPtr;    \ACTIVE_LOGGER_INSTANCE->init();           \}
#define CHECK_LOG_LEVEL(logLevel) (ACTIVE_LOGGER_INSTANCE ? ((ACTIVE_LOGGER_INSTANCE->get_log_level() <= log_level::logLevel##_level) ? true : false) : false)
#define SET_LOG_LEVEL(logLevel)                                                   \{                                                                              \if (ACTIVE_LOGGER_INSTANCE)                                                  \(ACTIVE_LOGGER_INSTANCE->set_log_level(log_level::logLevel##_level));      \}
#define DESTROY_LOGGER                      \{                                        \if (ACTIVE_LOGGER_INSTANCE)            \{                                      \ACTIVE_LOGGER_INSTANCE->stop();      \delete ACTIVE_LOGGER_INSTANCE;       \}                                      \}enum log_level
{debug_level = 0,info_level,warn_level,error_level,critical_level
};class logger_iface
{
public:logger_iface(void) = default;virtual ~logger_iface(void) = default;logger_iface(const logger_iface &) = default;logger_iface &operator=(const logger_iface &) = default;public:virtual void init() = 0;virtual void stop() = 0;virtual void set_log_level(log_level level) = 0;virtual log_level get_log_level() = 0;virtual void debug_log(const std::string &msg) = 0;virtual void info_log(const std::string &msg) = 0;virtual void warn_log(const std::string &msg) = 0;virtual void error_log(const std::string &msg) = 0;virtual void critical_log(const std::string &msg) = 0;
};class activeLogger
{
public:static logger_iface **getLoggerAddr(){static logger_iface *activeLogger;return &activeLogger;}
};#define __LOGGING_ENABLED#ifdef __LOGGING_ENABLED
#define __LOG(level, msg)                                                       \\{                                                                            \tostringstream var;                                                        \var << "[" << __FILE__ << ":" << __LINE__ << ":" << __func__ << "] \n"     \<< msg;                                                                  \if (ACTIVE_LOGGER_INSTANCE)                                                \ACTIVE_LOGGER_INSTANCE->level##_log(var.str());                          \}
#else
#define __LOG(level, msg)
#endif /* __LOGGING_ENABLED */

三、使用樣例

#include "logger/boost_logger.hpp"
#include "logger/simpleLogger.hpp"void testCustomLogger() {//初始化日志對象:日志路徑后期從配置文件讀取const std::string logDir = "E:\\log";INIT_LOGGER(new boost_logger(logDir));//設置過濾級別(可以讀取配置文件)SET_LOG_LEVEL(debug);//輸出各級別日志,(void *)ACTIVE_LOGGER_INSTANCE:代表激活的日志實例(可不寫)__LOG(critical, "hello logger!"<< "this is critical log" << (void *)ACTIVE_LOGGER_INSTANCE);__LOG(debug, "hello logger!!!!!!!!!!!!!!!"<< "this is debug log");
}

http://m.aloenet.com.cn/news/36070.html

相關文章:

  • 鄭州網(wǎng)站推廣排名公司浙江關鍵詞優(yōu)化
  • 萬網(wǎng)網(wǎng)站建設購買過程汽車推廣軟文
  • 怎么自己的電腦做網(wǎng)站服務器百度網(wǎng)站是什么
  • 阿里巴巴怎么做公司網(wǎng)站我為什么不建議年輕人做銷售
  • 網(wǎng)站建設 資訊動態(tài)電商軟文范例100字
  • 網(wǎng)站文化建設軟文新聞發(fā)布網(wǎng)站
  • 徐州企業(yè)網(wǎng)站設計免費的網(wǎng)站推廣在線推廣
  • 歐美設計網(wǎng)站推薦百度推廣賬號怎么申請
  • 如何寫好網(wǎng)站開發(fā)技術文檔頭條新聞今日頭條官方版本
  • 網(wǎng)站建設本科畢業(yè)設計論文鄭州網(wǎng)站推廣排名公司
  • 發(fā)果怎么做視頻網(wǎng)站四川省最新疫情情況
  • 一個網(wǎng)站怎么做鏡像站熱點事件
  • wordpress播放器源碼徐州seo外包
  • 動態(tài)網(wǎng)站建設簡介谷歌排名網(wǎng)站優(yōu)化
  • 廣西專業(yè)做網(wǎng)站的公司軟件排名工具
  • 網(wǎng)站建設技術服務清單網(wǎng)絡營銷有哪些
  • 企業(yè)介紹微網(wǎng)站怎么做短視頻營銷推廣策略
  • c 網(wǎng)站開發(fā)框架百度小說風云榜今天
  • 企業(yè)網(wǎng)站建設合同書模板可以引流推廣的app
  • 云瓣科技做網(wǎng)站本地網(wǎng)絡seo公司
  • 網(wǎng)站后臺登陸代碼百度關鍵詞seo排名
  • 用js做跳轉到其他網(wǎng)站優(yōu)化公司怎么優(yōu)化網(wǎng)站的
  • 大場網(wǎng)站建設seo最好的工具
  • 國外做的比較好看的網(wǎng)站2022年度最火關鍵詞
  • 西安網(wǎng)站建設開發(fā)查派谷歌seo排名公司
  • 依波手表價格 官方網(wǎng)站360搜索優(yōu)化
  • 網(wǎng)站建設客戶告知書長春網(wǎng)站優(yōu)化團隊
  • 鄭州區(qū)塊鏈數(shù)字錢包網(wǎng)站開發(fā)多少錢廣州網(wǎng)頁制作
  • 網(wǎng)站管理建設的總結抖音代運營
  • 做定制校服的網(wǎng)站煙臺seo快速排名