c++ 日志类 CCLog(更新)

本文详细介绍了CCLog库的增强功能,包括变参格式字符串的日志输出、静态函数日志输出以及日志等级的添加。通过提供丰富的API,用户可以灵活地在控制台或文件中记录不同级别的日志信息。

主要增加了变参格式字符串的日志输出、静态函数日志输出以及日志等级;


/*
 *  CCLog.h
 *  c++_common_codes
 *
 *  Created by xichen on 12-1-12.
 *  Copyright 2012 cc_team. All rights reserved.
 *	
 *	2012-3-3	add the log level , variable argument string output and 
 *				static log output func
*/
#ifndef CC_LOG_H
#define CC_LOG_H

#include "ccStringBase.h"
#include <cstdio>

typedef enum _LOG_TYPE
{
    LOG_TYPE_CONSOLE,
    LOG_TYPE_FILE,

    LOG_TYPE_MAX
}LOG_TYPE;

typedef enum _LOG_LEVEL
{
	LOG_LEVEL_SERIOUS_ERROR,		// serious error
	LOG_LEVEL_ERROR,				// error
	LOG_LEVEL_WARNING,				// warning
	LOG_LEVEL_INFO,					// info
	
	LOG_LEVEL_MAX
}LOG_LEVEL;

class CCLog
{
public:
    CCLog(const char * fileName = NULL, const char * mode = "wa+");    // by default, open file by "wa+" mode
    ~CCLog();

public:
    unsigned	write(const CCString & str, LOG_LEVEL logLevel = LOG_LEVEL_INFO);
    unsigned	writeLine( const CCString & str , LOG_LEVEL logLevel = LOG_LEVEL_INFO);	// it will write another '\n', comparing to write func above
	unsigned	write(LOG_LEVEL logLevel, const char *str, ...);
	unsigned	writeLine(LOG_LEVEL logLevel, const char *str, ...);
	
	unsigned	writeEndl(LOG_LEVEL logLevel = LOG_LEVEL_INFO);		// it will just write an '\n'
    void		clearAllData();	    // if a file is opened, all contents of the file will be cleared, the file will be opened a second time.

public:
	// the four static log funcs below are just for console output, alse the str will be output immediately
	static		void	logSE(const CCString & str);		// log as serious error
	static		void	logE(const CCString & str);		// log as error
	static		void	logW(const CCString & str);		// log as warning
	static		void	logI(const CCString & str);		// log as info
	
public:
    void	setWriteToConsole();
    void	setWriteToFile();

public:
    LOG_TYPE	getLogType() const { return _logType; }
    CCString	getLogFileName() const { return _fileName; }
	LOG_LEVEL	getLogLevel() const { return _logLevel; }
	void		setLogLevel(LOG_LEVEL newLevel)	{ _logLevel = newLevel; }

public:    
    void	clearConsole()	    
    {
#ifdef _WINDOWS					// windows
		system("cls");	
#elif defined(__APPLE__)		// mac
		system("clear");
#else
		system("clear");
#endif
    }

private:
    CCLog(const CCLog & log);
    CCLog & operator=(const CCLog & log);

private:
    FILE	*_file;
    FILE	*_backupFile;
    CCString	_fileName;
    LOG_TYPE	_logType;
	LOG_LEVEL	_logLevel;
};

#endif

/*
 *  CCLog.cpp
 *  c++_common_codes
 *
 *  Created by xichen on 12-1-12.
 *  Copyright 2012 cc_team. All rights reserved.
 *
*/
#include "ccLog.h"

CCLog::CCLog( const char * fileName /*= NULL*/, const char * mode /*= "wa+"*/ )
{
    if(fileName == NULL)
    {
		_file = _backupFile = NULL;
		_logType = LOG_TYPE_CONSOLE;
		_logLevel = LOG_LEVEL_INFO;
		return;
    }

    _logType = LOG_TYPE_FILE;
	_logLevel = LOG_LEVEL_INFO;
    _file = fopen(fileName, mode);
    _backupFile = _file;
    if(_file == NULL)
	{
		std::cerr << "Open file error" << std::endl;
		exit(-1);
	}
    else
		_fileName = CCString(fileName);
}

CCLog::~CCLog()
{
    if(_logType == LOG_TYPE_FILE)
    {
		if(_file != NULL)
		{
			fclose(_file);
			return;
		}
		if(_backupFile != NULL)
		{
			fclose(_backupFile);
		}
    }
}

unsigned CCLog::write( const CCString & str , LOG_LEVEL logLevel /* = LOG_LEVEL_INFO */)
{
	if(logLevel > _logLevel)
	{
		std::cerr << "CCLog Internal:logLevel is too big, nothing will logged" << std::endl;
		return 0;
	}
	
    if(_logType == LOG_TYPE_CONSOLE)
    {
		int ret = printf("%s", str.c_str());
		fflush(stdout);
		return ret;	
    }

    fseek(_file, 0, SEEK_END);
    return fwrite(str.c_str(), 1, str.length(),  _file);
}

unsigned CCLog::writeLine( const CCString & str , LOG_LEVEL logLevel /* = LOG_LEVEL_INFO */)
{
	CCString temp = str + "\n";
	return write(temp, logLevel);
}

unsigned	CCLog::write(LOG_LEVEL logLevel, const char *str, ...)
{
	if(logLevel > _logLevel)
	{
		std::cerr << "CCLog Internal:logLevel is too big, nothing will logged" << std::endl;
		return 0;
	}
	
	if(_logType == LOG_TYPE_CONSOLE)
	{
		va_list args;
		va_start (args, str);
		int ret = vfprintf (stdout, str, args);
		va_end (args);
		return ret;
	}
	
	fseek(_file, 0, SEEK_END);
	
	va_list args;
	va_start (args, str);
	int ret = vfprintf (_file, str, args);
	va_end (args);
	return ret;
}

unsigned	CCLog::writeLine(LOG_LEVEL logLevel, const char *str, ...)
{
	if(logLevel > _logLevel)
	{
		std::cerr << "CCLog Internal:logLevel is too big, nothing will logged" << std::endl;
		return 0;
	}
	
	if(_logType == LOG_TYPE_CONSOLE)
	{
		va_list args;
		va_start (args, str);
		int ret = vfprintf (stdout, str, args);
		va_end (args);
		int retEndl = printf("\n");
		return ret + retEndl;
	}
	
	fseek(_file, 0, SEEK_END);
	
	va_list args;
	va_start (args, str);
	int ret = vfprintf (_file, str, args);
	va_end (args);
	int retEndl = vfprintf(_file, "\n", args);
	return ret + retEndl;
}


unsigned CCLog::writeEndl(LOG_LEVEL logLevel /* = LOG_LEVEL_INFO */)
{
	if(logLevel > _logLevel)
	{
		std::cerr << "CCLog Internal:logLevel is too big, nothing will logged" << std::endl;
		return 0;
	}
    return write("\n");
}


void CCLog::clearAllData()
{
    if(_logType == LOG_TYPE_CONSOLE)
		return;

    if(_backupFile != NULL)
		_file = _backupFile;

    fclose(_file);
    _file = fopen(CCString(_fileName), "wt+");	    // clear all the data of file
    _backupFile = _file;
    if(_file == NULL)
		std::cerr << "clearAllData:Open file error" << std::endl;
}

void	CCLog::logSE(const CCString & str)		// log as serious error
{
	std::cerr << "Serious Error:" << str.c_str() << std::endl;
}

void	CCLog::logE(const CCString & str)		// log as error
{
	std::cerr << "Error:" << str.c_str() << std::endl;
}

void	CCLog::logW(const CCString & str)		// log as warning
{
	std::cerr << "Warning:" << str.c_str() << std::endl;
}

void	CCLog::logI(const CCString & str)		// log as info
{
	std::cerr << "Info:" << str.c_str() << std::endl;
}

void CCLog::setWriteToConsole()
{
    _logType = LOG_TYPE_CONSOLE;
}

void CCLog::setWriteToFile()
{
    _logType = LOG_TYPE_FILE;
}


测试代码:

void ccTestLog()
{
#if 1	    // CCLog		// ok
    CCLog * log = new CCLog(NULL);
    log->write("hello");
    log->write("\t1\n");
    log->write("\txichen\n");

    delete log;
#ifdef	_WINDOWS
    log = new CCLog("logtest.txt");
#else
	log = new CCLog("logtest.txt");
#endif
    log->write("ab\t\n1");
    delete log;
#ifdef	_WINDOWS
    log = new CCLog("logtest.txt");
#else
	log = new CCLog("logtest.txt");
#endif
    log->write("xiche\t123");
    log->clearAllData();
    log->write("after clear");
    log->setWriteToConsole();
    log->write("the console info");
    log->setWriteToFile();
    log->write("the file content");
    log->writeEndl();
    log->write("the next line\nhehe");
	
	log->setWriteToConsole();
	log->write(LOG_LEVEL_INFO, "hello %d", 100);
	log->writeLine(LOG_LEVEL_INFO, "hello %d", 100);
	log->writeLine(LOG_LEVEL_INFO, "hello %d", 100);
	
	log->setWriteToFile();
	log->write(LOG_LEVEL_INFO, "hello %d", 100);
	log->writeLine(LOG_LEVEL_INFO, "hello %d", 100);
	
    delete log;
	
	log = new CCLog(NULL);
	log->setLogLevel(LOG_LEVEL_ERROR);
	log->writeLine("serious error 1", LOG_LEVEL_SERIOUS_ERROR);
	log->writeLine("error 1", LOG_LEVEL_ERROR);
	log->writeLine("warning 1", LOG_LEVEL_WARNING);
	log->writeLine("info 1", LOG_LEVEL_INFO);
	
	log->setLogLevel(LOG_LEVEL_INFO);
	log->writeLine("serious error 1", LOG_LEVEL_SERIOUS_ERROR);
	log->writeLine("error 1", LOG_LEVEL_ERROR);
	log->writeLine("warning 1", LOG_LEVEL_WARNING);
	log->writeLine("info 1", LOG_LEVEL_INFO);
	
	log->setLogLevel(LOG_LEVEL_MAX);
	log->writeLine("serious error 1", LOG_LEVEL_SERIOUS_ERROR);
	log->writeLine("error 1", LOG_LEVEL_ERROR);
	log->writeLine("warning 1", LOG_LEVEL_WARNING);
	log->writeLine("info 1", LOG_LEVEL_INFO);
	
	log->clearConsole();
	
	delete	log;
	
	CCLog::logSE("error");
	CCLog::logE("error");
	CCLog::logW("error");
	CCLog::logI("error");
	
	
	
#endif
}

测试代码结果:

Serious Error:error

Error:error

Warning:error

Info:error



注:

1、CCLog以前的版本:

http://blog.youkuaiyun.com/cxsjabcabc/article/details/7294969

. ├── config.ini ├── demo2example ├── loglib │   ├── ccdeclare.h │   ├── cclog.h │   └── ccsingleton.h ├── makefile ├── source │   ├── getconfig.cpp │   ├── getconfig.h │   ├── subtitdspi.cpp │   ├── subtitdspi.h │   ├── testtitdapi.cpp │   ├── titdapi_req.cpp │   ├── titdapi_req.h │   ├── user.cpp │   ├── user.h │   ├── user_input.cpp │   ├── user_other.cpp │   └── user_prog.cpp ├── spdlog │   └── v1.9.2 │   └── include │   └── spdlog │   ├── async.h │   ├── async_logger.h │   ├── async_logger-inl.h │   ├── cfg │   │   ├── argv.h │   │   ├── env.h │   │   ├── helpers.h │   │   └── helpers-inl.h │   ├── common.h │   ├── common-inl.h │   ├── details │   │   ├── backtracer.h │   │   ├── backtracer-inl.h │   │   ├── circular_q.h │   │   ├── console_globals.h │   │   ├── file_helper.h │   │   ├── file_helper-inl.h │   │   ├── fmt_helper.h │   │   ├── log_msg_buffer.h │   │   ├── log_msg_buffer-inl.h │   │   ├── log_msg.h │   │   ├── log_msg-inl.h │   │   ├── mpmc_blocking_q.h │   │   ├── null_mutex.h │   │   ├── os.h │   │   ├── os-inl.h │   │   ├── periodic_worker.h │   │   ├── periodic_worker-inl.h │   │   ├── registry.h │   │   ├── registry-inl.h │   │   ├── synchronous_factory.h │   │   ├── tcp_client.h │   │   ├── tcp_client-windows.h │   │   ├── thread_pool.h │   │   ├── thread_pool-inl.h │   │   ├── udp_client.h │   │   ├── udp_client-windows.h │   │   └── windows_include.h │   ├── fmt │   │   ├── bin_to_hex.h │   │   ├── bundled │   │   │   ├── args.h │   │   │   ├── chrono.h │   │   │   ├── color.h │   │   │   ├── compile.h │   │   │   ├── core.h │   │   │   ├── fmt.license.rst │   │   │   ├── format.h │   │   │   ├── format-inl.h │   │   │   ├── locale.h │   │   │   ├── os.h │   │   │   ├── ostream.h │   │   │   ├── printf.h │   │   │   ├── ranges.h │   │   │   └── xchar.h │   │   ├── chrono.h │   │   ├── compile.h │   │   ├── fmt.h │   │   ├── ostr.h │   │   ├── ranges.h │   │   └── xchar.h │   ├── formatter.h │   ├── fwd.h │   ├── logger.h │   ├── logger-inl.h │   ├── pattern_formatter.h │   ├── pattern_formatter-inl.h │   ├── sinks │   │   ├── android_sink.h │   │   ├── ansicolor_sink.h │   │   ├── ansicolor_sink-inl.h │   │   ├── base_sink.h │   │   ├── base_sink-inl.h │   │   ├── basic_file_sink.h │   │   ├── basic_file_sink-inl.h │   │   ├── daily_file_sink.h │   │   ├── dist_sink.h │   │   ├── dup_filter_sink.h │   │   ├── hourly_file_sink.h │   │   ├── mongo_sink.h │   │   ├── msvc_sink.h │   │   ├── null_sink.h │   │   ├── ostream_sink.h │   │   ├── qt_sinks.h │   │   ├── ringbuffer_sink.h │   │   ├── rotating_file_sink.h │   │   ├── rotating_file_sink-inl.h │   │   ├── sink.h │   │   ├── sink-inl.h │   │   ├── stdout_color_sinks.h │   │   ├── stdout_color_sinks-inl.h │   │   ├── stdout_sinks.h │   │   ├── stdout_sinks-inl.h │   │   ├── syslog_sink.h │   │   ├── systemd_sink.h │   │   ├── tcp_sink.h │   │   ├── udp_sink.h │   │   ├── wincolor_sink.h │   │   ├── wincolor_sink-inl.h │   │   └── win_eventlog_sink.h │   ├── spdlog.h │   ├── spdlog-inl.h │   ├── stopwatch.h │   ├── tweakme.h │   └── version.h └── userconfig.ini 这是demo2的树形结构,makefile文件如下:#获取.cpp文件 SrcFiles=$(wildcard source/*.cpp spdlog/*.cpp) #使用替换函数获取.o文件 ObjFiles=$(patsubst %.cpp,%.o,$(SrcFiles)) #生成的可执行文件 all:tiexample #目标文件依赖于.o文件 tiexample:$(ObjFiles) g++ -o $@ -I ../../lib -I ./spdlog/v1.9.2/include -I ./loglib -I ./source $(SrcFiles) -Wl,-rpath=../../lib -L ../../lib -l titdapi -lpthread #.o文件依赖于.cpp文件,通配使用,一条就够 %.o:%.cpp g++ -c -I ../../lib -I ./spdlog/v1.9.2/include -I ./loglib -I ./source $< rm *.o ,在demo2目录下输入make,得到的警告信息如下:./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:298:32: 错误:在文件层将‘is_big_endian’声明为‘auto’ inline auto is_big_endian() -> bool { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:298:32: 错误:trailing return type only available with -std=c++11 or -std=gnu++11 In file included from ./spdlog/v1.9.2/include/spdlog/fmt/bundled/core.h:3234:0, from ./spdlog/v1.9.2/include/spdlog/fmt/fmt.h:24, from ./spdlog/v1.9.2/include/spdlog/common.h:45, from ./spdlog/v1.9.2/include/spdlog/spdlog.h:12, from ./loglib/cclog.h:8, from ./loglib/ccdeclare.h:7, from source/subtitdspi.h:8, from source/user.h:4, from source/user_prog.cpp:1: ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:317:24: 警告:defaulted and deleted functions only available with -std=c++11 or -std=gnu++11 [默认启用] fallback_uintptr() = default; ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h: 在构造函数‘fmt::v8::detail::fallback_uintptr::fallback_uintptr(const void*)’中: ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:319:13: 错误:‘bit_cast’在此作用域中尚未声明 *this = bit_cast<fallback_uintptr>(p); ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:319:38: 错误:expected primary-expression before ‘>’ token *this = bit_cast<fallback_uintptr>(p); ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:320:35: 错误:‘is_big_endian’在此作用域中尚未声明 if (const_check(is_big_endian())) { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:320:36: 错误:‘const_check’在此作用域中尚未声明 if (const_check(is_big_endian())) { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h: 在全局域: ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:327:7: 错误:expected nested-name-specifier before ‘uintptr_t’ using uintptr_t = ::uintptr_t; ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:327:17: 错误:expected ‘;’ before ‘=’ token using uintptr_t = ::uintptr_t; ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:327:17: 错误:expected unqualified-id before ‘=’ token ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:328:42: 错误:ISO C++ 不允许声明无型的‘to_uintptr’ [-fpermissive] inline auto to_uintptr(const void* p) -> uintptr_t { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:328:42: 错误:在文件层将‘to_uintptr’声明为‘auto’ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:328:42: 错误:trailing return type only available with -std=c++11 or -std=gnu++11 ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:340:23: 错误:‘constexpr’不是一个型名 template <typename T> constexpr auto max_value() -> T { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:340:23: 附注:C++11 ‘constexpr’ only available with -std=c++11 or -std=gnu++11 ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:343:23: 错误:‘constexpr’不是一个型名 template <typename T> constexpr auto num_bits() -> int { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:343:23: 附注:C++11 ‘constexpr’ only available with -std=c++11 or -std=gnu++11 ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:347:13: 错误:‘constexpr’不是一个型名 template <> constexpr auto num_bits<int128_t>() -> int { return 128; } ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:347:13: 附注:C++11 ‘constexpr’ only available with -std=c++11 or -std=gnu++11 ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:348:13: 错误:‘constexpr’不是一个型名 template <> constexpr auto num_bits<uint128_t>() -> int { return 128; } ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:348:13: 附注:C++11 ‘constexpr’ only available with -std=c++11 or -std=gnu++11 ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:349:13: 错误:‘constexpr’不是一个型名 template <> constexpr auto num_bits<fallback_uintptr>() -> int { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:349:13: 附注:C++11 ‘constexpr’ only available with -std=c++11 or -std=gnu++11 ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:363:1: 错误:expected unqualified-id before ‘using’ using iterator_t = decltype(std::begin(std::declval<T&>())); ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:364:23: 错误:expected unqualified-id before ‘using’ template <typename T> using sentinel_t = decltype(std::end(std::declval<T&>())); ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:368:57: 错误:ISO C++ 不允许声明无型的‘get_data’ [-fpermissive] inline auto get_data(std::basic_string<Char>& s) -> Char* { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:368:57: 错误:在文件层将‘get_data’声明为‘auto’ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:368:57: 错误:trailing return type only available with -std=c++11 or -std=gnu++11 ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:372:69: 错误:ISO C++ 不允许声明无型的‘get_data’ [-fpermissive] inline auto get_data(Container& c) -> typename Container::value_type* { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:372:69: 错误:在文件层将‘get_data’声明为‘auto’ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:372:69: 错误:trailing return type only available with -std=c++11 or -std=gnu++11 ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:384:23: 错误:expected unqualified-id before ‘using’ template <typename T> using checked_ptr = T*; ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:385:23: 错误:‘constexpr’不是一个型名 template <typename T> constexpr auto make_checked(T* p, size_t) -> T* { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:385:23: 附注:C++11 ‘constexpr’ only available with -std=c++11 or -std=gnu++11 In file included from ./spdlog/v1.9.2/include/spdlog/fmt/fmt.h:24:0, from ./spdlog/v1.9.2/include/spdlog/common.h:45, from ./spdlog/v1.9.2/include/spdlog/spdlog.h:12, from ./loglib/cclog.h:8, from ./loglib/ccdeclare.h:7, from source/subtitdspi.h:8, from source/user.h:4, from source/user_prog.cpp:1: ./spdlog/v1.9.2/include/spdlog/fmt/bundled/core.h:344:30: 错误:‘enable_if_t’未声明 # define FMT_ENABLE_IF(...) enable_if_t<(__VA_ARGS__), int> = 0 ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:392:31: 附注:in expansion of macro ‘FMT_ENABLE_IF’ template <typename Container, FMT_ENABLE_IF(is_contiguous<Container>::value)> ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/core.h:344:41: 错误:expected ‘>’ before ‘<’ token # define FMT_ENABLE_IF(...) enable_if_t<(__VA_ARGS__), int> = 0 ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:392:31: 附注:in expansion of macro ‘FMT_ENABLE_IF’ template <typename Container, FMT_ENABLE_IF(is_contiguous<Container>::value)> ^ In file included from ./spdlog/v1.9.2/include/spdlog/fmt/bundled/core.h:3234:0, from ./spdlog/v1.9.2/include/spdlog/fmt/fmt.h:24, from ./spdlog/v1.9.2/include/spdlog/common.h:45, from ./spdlog/v1.9.2/include/spdlog/spdlog.h:12, from ./loglib/cclog.h:8, from ./loglib/ccdeclare.h:7, from source/subtitdspi.h:8, from source/user.h:4, from source/user_prog.cpp:1: ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:398:8: 错误:expected type-specifier before ‘checked_ptr’ -> checked_ptr<typename Container::value_type> { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:398:8: 错误:expected initializer before ‘checked_ptr’ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:406:21: 错误:ISO C++ 不允许声明无型的‘reserve’ [-fpermissive] inline auto reserve(buffer_appender<T> it, size_t n) -> buffer_appender<T> { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:406:21: 错误:在文件层将‘reserve’声明为‘auto’ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:406:21: 错误:‘fmt::v8::detail::reserve’声明为‘inline’变量 ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:406:21: 错误:‘int fmt::v8::detail::reserve’声明为模板 ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:406:21: 错误:‘buffer_appender’在此作用域中尚未声明 ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:406:38: 错误:expected primary-expression before ‘>’ token inline auto reserve(buffer_appender<T> it, size_t n) -> buffer_appender<T> { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:406:40: 错误:‘it’在此作用域中尚未声明 inline auto reserve(buffer_appender<T> it, size_t n) -> buffer_appender<T> { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:406:51: 错误:expected primary-expression before ‘n’ inline auto reserve(buffer_appender<T> it, size_t n) -> buffer_appender<T> { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:413:1: 错误:‘constexpr’不是一个型名 constexpr auto reserve(Iterator& it, size_t) -> Iterator& { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:413:1: 附注:C++11 ‘constexpr’ only available with -std=c++11 or -std=gnu++11 ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:418:1: 错误:expected unqualified-id before ‘using’ using reserve_iterator = ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:422:1: 错误:‘constexpr’不是一个型名 constexpr auto to_pointer(OutputIt, size_t) -> T* { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:422:1: 附注:C++11 ‘constexpr’ only available with -std=c++11 or -std=gnu++11 ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:425:39: 错误:ISO C++ 不允许声明无型的‘to_pointer’ [-fpermissive] template <typename T> auto to_pointer(buffer_appender<T> it, size_t n) -> T* { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:425:39: 错误:在文件层将‘to_pointer’声明为‘auto’ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:425:39: 错误:‘int fmt::v8::detail::to_pointer’声明为模板 ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:425:39: 错误:‘buffer_appender’在此作用域中尚未声明 ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:425:56: 错误:expected primary-expression before ‘>’ token template <typename T> auto to_pointer(buffer_appender<T> it, size_t n) -> T* { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:425:58: 错误:‘it’在此作用域中尚未声明 template <typename T> auto to_pointer(buffer_appender<T> it, size_t n) -> T* { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:425:69: 错误:expected primary-expression before ‘n’ template <typename T> auto to_pointer(buffer_appender<T> it, size_t n) -> T* { ^ In file included from ./spdlog/v1.9.2/include/spdlog/fmt/fmt.h:24:0, from ./spdlog/v1.9.2/include/spdlog/common.h:45, from ./spdlog/v1.9.2/include/spdlog/spdlog.h:12, from ./loglib/cclog.h:8, from ./loglib/ccdeclare.h:7, from source/subtitdspi.h:8, from source/user.h:4, from source/user_prog.cpp:1: ./spdlog/v1.9.2/include/spdlog/fmt/bundled/core.h:344:30: 错误:‘enable_if_t’未声明 # define FMT_ENABLE_IF(...) enable_if_t<(__VA_ARGS__), int> = 0 ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:433:31: 附注:in expansion of macro ‘FMT_ENABLE_IF’ template <typename Container, FMT_ENABLE_IF(is_contiguous<Container>::value)> ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/core.h:344:41: 错误:expected ‘>’ before ‘<’ token # define FMT_ENABLE_IF(...) enable_if_t<(__VA_ARGS__), int> = 0 ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:433:31: 附注:in expansion of macro ‘FMT_ENABLE_IF’ template <typename Container, FMT_ENABLE_IF(is_contiguous<Container>::value)> ^ In file included from ./spdlog/v1.9.2/include/spdlog/fmt/bundled/core.h:3234:0, from ./spdlog/v1.9.2/include/spdlog/fmt/fmt.h:24, from ./spdlog/v1.9.2/include/spdlog/common.h:45, from ./spdlog/v1.9.2/include/spdlog/spdlog.h:12, from ./loglib/cclog.h:8, from ./loglib/ccdeclare.h:7, from source/subtitdspi.h:8, from source/user.h:4, from source/user_prog.cpp:1: ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:435:27: 错误:‘checked_ptr’未声明 checked_ptr<typename Container::value_type>) ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:435:38: 错误:expected ‘,’ or ‘...’ before ‘<’ token checked_ptr<typename Container::value_type>) ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:436:13: 错误:ISO C++ 不允许声明无型的‘base_iterator’ [-fpermissive] -> std::back_insert_iterator<Container> { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:436:13: 错误:在文件层将‘base_iterator’声明为‘auto’ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:436:13: 错误:trailing return type only available with -std=c++11 or -std=gnu++11 ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:441:1: 错误:‘constexpr’不是一个型名 constexpr auto base_iterator(Iterator, Iterator it) -> Iterator { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:441:1: 附注:C++11 ‘constexpr’ only available with -std=c++11 or -std=gnu++11 ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:449:8: 错误:ISO C++ 不允许声明无型的‘fill_n’ [-fpermissive] -> OutputIt { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:449:8: 错误:在文件层将‘fill_n’声明为‘auto’ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:449:8: 错误:trailing return type only available with -std=c++11 or -std=gnu++11 ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:454:65: 错误:ISO C++ 不允许声明无型的‘fill_n’ [-fpermissive] FMT_CONSTEXPR20 auto fill_n(T* out, Size count, char value) -> T* { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:454:65: 错误:在文件层将‘fill_n’声明为‘auto’ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:454:65: 错误:trailing return type only available with -std=c++11 or -std=gnu++11 ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:465:28: 警告:scoped enums only available with -std=c++11 or -std=gnu++11 [默认启用] enum char8_type : unsigned char {}; ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:470:68: 错误:ISO C++ 不允许声明无型的‘copy_str_noinline’ [-fpermissive] OutputIt out) -> OutputIt { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:470:68: 错误:在文件层将‘copy_str_noinline’声明为‘auto’ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:470:68: 错误:trailing return type only available with -std=c++11 or -std=gnu++11 ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:492:18: 错误:ISO C++ 不允许声明无型的‘utf8_decode’ [-fpermissive] -> const char* { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:492:18: 错误:在文件层将‘utf8_decode’声明为‘auto’ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:492:18: 错误:trailing return type only available with -std=c++11 or -std=gnu++11 ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:523:1: 错误:‘constexpr’不是一个型名 constexpr uint32_t invalid_code_point = ~uint32_t(); ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:523:1: 附注:C++11 ‘constexpr’ only available with -std=c++11 or -std=gnu++11 ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:528:39: 错误:变量或字段‘for_each_codepoint’声明为 void FMT_CONSTEXPR void for_each_codepoint(string_view s, F f) { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:528:39: 错误:‘string_view’在此作用域中尚未声明 ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:528:56: 错误:expected primary-expression before ‘f’ FMT_CONSTEXPR void for_each_codepoint(string_view s, F f) { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:559:57: 错误:ISO C++ 不允许声明无型的‘compute_width’ [-fpermissive] inline auto compute_width(basic_string_view<Char> s) -> size_t { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:559:57: 错误:在文件层将‘compute_width’声明为‘auto’ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:559:57: 错误:trailing return type only available with -std=c++11 or -std=gnu++11 ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:564:43: 错误:‘fmt::v8::detail::compute_width’声明为‘inline’变量 FMT_CONSTEXPR inline size_t compute_width(string_view s) { ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:564:43: 错误:‘string_view’在此作用域中尚未声明 ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:564:58: 错误:expected ‘,’ or ‘;’ before ‘{’ token FMT_CONSTEXPR inline size_t compute_width(string_view s) { ^ In file included from ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format.h:3099:0, from ./spdlog/v1.9.2/include/spdlog/fmt/bundled/core.h:3234, from ./spdlog/v1.9.2/include/spdlog/fmt/fmt.h:24, from ./spdlog/v1.9.2/include/spdlog/common.h:45, from ./spdlog/v1.9.2/include/spdlog/spdlog.h:12, from ./loglib/cclog.h:8, from ./loglib/ccdeclare.h:7, from source/subtitdspi.h:8, from source/user.h:4, from source/user_prog.cpp:1: ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format-inl.h:191:30: 错误:expected ‘}’ before end of line # pragma GCC diagnostic push ^ ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format-inl.h:191:30: 错误:expected ‘}’ before end of line ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format-inl.h:191:30: 错误:expected ‘}’ before end of line ./spdlog/v1.9.2/include/spdlog/fmt/bundled/format-inl.h:191:30: 错误:expected declaration before end of line make: *** [source/user_prog.o] 错误 1,请问要怎么修改才能正确运行demo2?
最新发布
06-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值