我已经使用自己的cmake文件而不是jamfile成功构建了一个增强示例 rotating_file (boost 1.63)。然后我添加了以下修改:
#include <boost/log/sources/global_logger_storage.hpp>
...
//before main
BOOST_LOG_GLOBAL_LOGGER(my_logger, src::logger)
...
//src::logger lg;
src::logger& lg = my_logger::get();
程序还包含以下行:
#define BOOST_ALL_DYN_LINK
以下是cmake libs:
target_link_libraries(test "libboost_log.so"
"libboost_log_setup.so"
"libboost_date_time.so"
"libboost_filesystem.so"
"libboost_system.so"
"libboost_thread.so")
这一行:
src::logger& lg = my_logger::get();
产生
global_logger_storage.hpp:154: error: undefined reference to `my_logger::construct_logger()'
有什么问题?
修改
我以这种方式添加接收器和其他属性:
logging::core::get()->add_sink(sink);
logging::core::get()->add_global_attribute("TimeStamp", attrs::local_clock());
logging::core::get()->add_global_attribute("RecordID", attrs::counter< unsigned int >());
所以在BOOST_LOG_GLOBAL_LOGGER_INIT结束时我只需添加:
src::logger logger;
return logger;
有效。
答案 0 :(得分:4)
您需要致电BOOST_LOG_GLOBAL_LOGGER_INIT。在一个项目中,我在标题中有以下内容:
import googleapiclient
import httplib2
from oauth2client.service_account import ServiceAccountCredentials
from googleapiclient.discovery import build
YOUTUBE_API_SERVICE_NAME = "youtube"
YOUTUBE_API_VERSION = "v3"
scopes = ['https://www.googleapis.com/auth/youtube',
'https://www.googleapis.com/auth/youtubepartner',
'https://www.googleapis.com/auth/youtube.force-ssl']
credentials = ServiceAccountCredentials.from_json_keyfile_name(
'secrets.json', scopes)
youtube_admin = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, http=credentials.authorize(httplib2.Http()))
try:
playlist_insert_response = youtube_admin.playlistItems().insert(
part="snippet",
body={
'snippet': {
'playlistId': '<playlist id>',
'resourceId': {
'kind': 'youtube#video',
'videoId': '<video id>'
},
'position': 0
}
}
).execute()
except googleapiclient.errors.HttpError as err:
print(vars(err))
在源文件中我有:
// register a global logger
BOOST_LOG_GLOBAL_LOGGER(logger, boost::log::sources::severity_logger_mt<boost::log::trivial::severity_level>)
当我注释掉BOOST_LOG_GLOBAL_LOGGER_INIT时,我得到了和你一样的错误。我的演绎能力告诉我BOOST_LOG_GLOBAL_LOGGER_INIT提供了你(我们)需要的定义。