C++ 什么是提升日志,如何获取以及如何构建它
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6076405/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is boost log, how to get it and how to build it
提问by Cookie
So I heard good things about boost log. This claims its existence:
所以我听说了关于 boost log 的好消息。这声称它的存在:
http://boost-log.sourceforge.net/libs/log/doc/html/index.html
http://boost-log.sourceforge.net/libs/log/doc/html/index.html
This is the tutorial:
这是教程:
http://boost-log.sourceforge.net/libs/log/doc/html/log/tutorial.html#log.tutorial.trivial
http://boost-log.sourceforge.net/libs/log/doc/html/log/tutorial.html#log.tutorial.trivial
However, boost log is not part of boost. Hence not in the regular boost branch.
但是,boost log 不是 boost 的一部分。因此不在常规的 boost 分支中。
One can download boost log separately from here:
可以从这里单独下载 boost 日志:
http://sourceforge.net/projects/boost-log/
http://sourceforge.net/projects/boost-log/
I might just be too inexperienced, but I find the installation instructions very poor. Nonetheless, after downloading and copying the folders boost and lib into the boost folder, I can run bootstrap and bjam. This fails with errors relating to Boost.Filesystem versions, similar to the ones mentioned here:
我可能只是太缺乏经验,但我发现安装说明非常糟糕。尽管如此,在下载并复制文件夹 boost 和 lib 到 boost 文件夹后,我可以运行 bootstrap 和 bjam。这会因与 Boost.Filesystem 版本相关的错误而失败,类似于此处提到的错误:
http://boost.2283326.n4.nabble.com/Boost-Log-compilation-on-msvc-2010-fail-td3488502.html
http://boost.2283326.n4.nabble.com/Boost-Log-compilation-on-msvc-2010-fail-td3488502.html
The recommendation from Andrew Semashev (in above link) is to "Please use Boost.Log v2 (from SVN trunk)."
Andrew Semashev(在上面的链接中)的建议是“请使用 Boost.Log v2(来自 SVN 主干)”。
Looking at https://boost-log.svn.sourceforge.net/svnroot/boost-log, I can only see version 1.
查看https://boost-log.svn.sourceforge.net/svnroot/boost-log,我只能看到版本 1。
Looking at http://svn.boost.org/svn/boost/sandbox/, I can find boost logging v2 by John Torjo. However, just from the syntax that might not be the boost log v2 that Andrew Semashev is talking about.
查看http://svn.boost.org/svn/boost/sandbox/,我可以找到 John Torjo 的 boost logging v2。但是,仅从可能不是 Andrew Semashev 所谈论的 boost log v2 的语法来看。
Seeing that I spend way too many hours on this already, I figured I'd get some help, and maybe some other people might profit from this post and the answers and save themselves some time. I don't think it has been answered before, and answers like these change I supposed.
看到我已经在这上面花费了太多时间,我想我会得到一些帮助,也许其他一些人可能会从这篇文章和答案中受益并节省一些时间。我认为以前没有人回答过这个问题,我认为这些答案会发生变化。
So, here goes: What is boost log v2 that Andrew Semashev is talking about? Is it the same as John Torjo's? If not, where I can find it? And how do I build it?
那么,这里是:Andrew Semashev 所说的 boost log v2 是什么?它和约翰·托尔乔的一样吗?如果没有,我在哪里可以找到它?我该如何构建它?
Thanks
谢谢
P.S. I should mention this is on Windows with Visual Studio Express 2010
PS我应该提到这是在带有Visual Studio Express 2010的Windows上
P.P.S. Guess "version 2", which is apparently just the SVN, also has problems, but with this line (see Sergio's answer below)
PPS Guess “版本 2”,显然只是 SVN,也有问题,但有这条线(见下面塞尔吉奥的回答)
<toolset>msvc:<define>BOOST_FILESYSTEM_VERSION=2
<toolset>msvc:<define>BOOST_FILESYSTEM_VERSION=2
in the bjam file at least I can compile. However, this file
在 bjam 文件中,至少我可以编译。然而,这个文件
#include <boost/log/trivial.hpp>
int main(int, char*[])
{
BOOST_LOG_TRIVIAL(trace) << "A trace severity message";
BOOST_LOG_TRIVIAL(debug) << "A debug severity message";
BOOST_LOG_TRIVIAL(info) << "An informational severity message";
BOOST_LOG_TRIVIAL(warning) << "A warning severity message";
BOOST_LOG_TRIVIAL(error) << "An error severity message";
BOOST_LOG_TRIVIAL(fatal) << "A fatal severity message";
}
straight out of the tutorial, albeit now compiling and linking, doesn't produce any output...
直接从教程中出来,虽然现在正在编译和链接,但不会产生任何输出......
采纳答案by sergio
boost log v2 is simply what you get by checking out trunk, according to what Andrey says in the post you link.
根据安德烈在您链接的帖子中所说的,boost log v2 就是您通过检查主干获得的内容。
indeed, it seems that this version too has got problems compiling against boost::filesystem v3.
事实上,这个版本似乎在针对 boost::filesystem v3 编译时也有问题。
if this is also your case, one workaround is compiling after adding
如果这也是你的情况,一种解决方法是在添加后编译
<define>BOOST_FILESYSTEM_VERSION=2
to the jamfile.
到果酱文件。
if this does not work, then, check whether you are building a single threaded or multi-threaded version of the libraries. multi-threadred boost-log should be more tested (according to Andrey).
如果这不起作用,那么请检查您正在构建库的单线程版本还是多线程版本。应该对多线程 boost-log 进行更多测试(根据 Andrey)。
hope this helps... I have not tried it...
希望这会有所帮助...我还没有尝试过...
EDIT:
编辑:
where to add the ?
在哪里添加?
I would add it to the requirements
section of boost-log/libs/log/build/Jamfile.v2
, shared
subsection:
我将它添加到requirements
的部分boost-log/libs/log/build/Jamfile.v2
,shared
该款:
project boost/log
: source-location ../src
: requirements
<link>shared:<define>BOOST_LOG_DLL
<link>shared:<define>BOOST_FILESYSTEM_VERSION=2
EDIT: from Cookie's comment, BOOST_FILESYSTEM_VERSION=2
should be specified as
编辑:来自 Cookie 的评论,BOOST_FILESYSTEM_VERSION=2
应指定为
<link>msvc:<define>BOOST_FILESYSTEM_VERSION=2
not in shared
.
不在shared
。
回答by yasouser
This is the method I followed to install Boost.Log in my Linux box. One important note before you build and install Boost libraries: Make sure you have installed a threading library like pthreads
. Most package managers should have them.
这是我在 Linux 机器中安装 Boost.Log 所遵循的方法。在构建和安装 Boost 库之前的一个重要注意事项:确保您已经安装了一个线程库,如pthreads
. 大多数包管理器都应该拥有它们。
Here are the build steps:
以下是构建步骤:
If you have installed Boost already from source, then its fine continue to next step. Otherwise download it from here(preferably the latest version (v1.46). I used v1.45). Extract the boost libraries at say: /opt
. We can build the libraries along with Boost.Log.
如果您已经从源代码安装了 Boost,则可以继续下一步。否则从这里下载(最好是最新版本(v1.46)。我使用的是 v1.45)。在 say: 处提取 boost 库/opt
。我们可以与 Boost.Log 一起构建库。
- Download Boost.Log from Sourceforge.
- Extract the Boost.Log source archive in a folder – say
/opt
. Copy the log folder in:/opt/boost-log-1.0/boost
to your boost source directory/opt/Boost_1_45_0/boost
(assuming that you have extracted it in/opt
). - Copy the log folder in:
/opt/boost-log-1.0/libs
to your boost libs directory/opt/Boost_1_45_0/libs
(assuming that you have extracted it in/opt
). If you haven't installed other Boost libraries, then follow these steps:cd /opt/Boost_1_45_0
.bootstrap.sh --show-libraries
— this will list all the libraries that will be built and installed. You should seelog
listed as part of it..bootstrap.sh --with-libraries=all --prefix=/usr/local --includedir=/usr/local/include --libdir=/usr/local/lib
./bjam install
- 从Sourceforge下载 Boost.Log 。
- 将 Boost.Log 源存档解压缩到一个文件夹中——比如
/opt
. 将 log 文件夹复制/opt/boost-log-1.0/boost
到您的 boost 源目录中/opt/Boost_1_45_0/boost
(假设您已将其解压缩到 中/opt
)。 - 将 log 文件夹 in: 复制
/opt/boost-log-1.0/libs
到您的 boost libs 目录/opt/Boost_1_45_0/libs
(假设您已将其解压缩到 中/opt
)。如果您尚未安装其他 Boost 库,请按照以下步骤操作:cd /opt/Boost_1_45_0
.bootstrap.sh --show-libraries
— 这将列出将要构建和安装的所有库。您应该看到log
列为其中的一部分。.bootstrap.sh --with-libraries=all --prefix=/usr/local --includedir=/usr/local/include --libdir=/usr/local/lib
./bjam install
Finally make sure $LD_LIBRARY_PATH
has /usr/local/lib
(the path specified in bjam
to install the built libraries) as part of it. If it is not edit your ~/.bashrc
and add the following:
最后确保$LD_LIBRARY_PATH
有/usr/local/lib
(在bjam
安装构建库中指定的路径)作为它的一部分。如果不是编辑您的~/.bashrc
并添加以下内容:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH
回答by Dimitris Dakopoulos
After lots of searching and testing this what I found out.
经过大量搜索和测试,我发现了这一点。
Download desired Boost (I tested it on stable release 1.51)
Checkout boost-log from hereand copy
<boost-log>/boost/log
and<boost-log>/libs/log
to<boost>/boost/log
and<boost>/libs
Make sure you have a supported compiler(my problem was that!. It worked with gcc 4.1.7)
Run
./bootstrap.sh --with-libraries=all --prefix=<dir_to_install>
and
./b2 address-model=32
下载所需的 Boost(我在稳定版 1.51 上对其进行了测试)
结帐升压日志从这里及复印件
<boost-log>/boost/log
,并<boost-log>/libs/log
要<boost>/boost/log
和<boost>/libs
确保你有一个受支持的编译器(我的问题是!它适用于 gcc 4.1.7)
跑
./bootstrap.sh --with-libraries=all --prefix=<dir_to_install>
和
./b2 address-model=32
If everything goes according to plan, a directory <boost>/stage/libs
will be created with the compiled libraries (including libboost_log.so)
如果一切按计划进行,<boost>/stage/libs
将使用已编译的库(包括 libboost_log.so)创建一个目录
Notes:
笔记:
I'm not sure why but prefix didn't work. I was expecting to see the libraries built there.
Use
b2
notbjam
.No need to alter
Jamfile
in<boost-log>
.I got a bunch of warnings but no when building log.
我不知道为什么,但前缀不起作用。我期待看到在那里建造的图书馆。
使用
b2
不bjam
。不需要改变
Jamfile
在<boost-log>
。我收到了一堆警告,但在构建日志时没有。
I hope it helps somebody.
我希望它可以帮助某人。
回答by eatyourgreens
Unknown symbol in text_file_backend.cpp at line 1197 while building boost-log-1-1 with boost 1.51.0
使用 boost 1.51.0 构建 boost-log-1-1 时,第 1197 行 text_file_backend.cpp 中的未知符号
I am using Windows MSVC 2010, but I suspect that the problem I had may be common to other platforms as well. I copied the boost.log sources into the boost 1.51 source tree and ran bootstrap.bat and .\b2 as per the instructions. The build failed, complaining that get_generic_category() is an unknown symbol in text_file_backend.cpp at line 1197
我使用的是 Windows MSVC 2010,但我怀疑我遇到的问题可能在其他平台上也很常见。我将 boost.log 源复制到 boost 1.51 源树中,并按照说明运行 bootstrap.bat 和 .\b2 。构建失败,抱怨 get_generic_category() 是 text_file_backend.cpp 中第 1197 行的未知符号
I changed line 1197 of text_file_backend.cpp so that it now reads
我更改了 text_file_backend.cpp 的第 1197 行,以便它现在读取
system::error_code(system::errc::io_error, system::generic_category()));
and I re-ran the build. The build worked.
我重新运行了构建。构建成功了。
I hope this helps someone else who has trouble building the boost-log library with boost 1.51
我希望这可以帮助那些在使用 boost 1.51 构建 boost-log 库时遇到问题的人
Please see http://www.boost.org/doc/libs/1_51_0/libs/system/doc/reference.html#Deprecated-namesfor more information about this change.
有关此更改的更多信息,请参阅http://www.boost.org/doc/libs/1_51_0/libs/system/doc/reference.html#Deprecated-names。
Edit: I just tried again using the boost-log sources direct from Subversion trunk, and it compiled OK. So the solution is: ignore boost-log 1.1 and use the Subversion trunk.
编辑:我刚刚再次尝试使用直接来自 Subversion 主干的 boost-log 源,并且编译正常。所以解决办法是:忽略boost-log 1.1,使用Subversion主干。
回答by Timo Geusch
If I interpret Andrew's answer correctly, his recommendation is to not use one of the packaged version of Boost.Log but do an SVN checkout from the boost-log SVN repository on SourceForge. I had a quick look at the files in the trunk there and can't find any reference to a v1.
如果我正确解释了 Andrew 的回答,他的建议是不要使用 Boost.Log 的打包版本之一,而是从 SourceForge 上的 boost-log SVN 存储库进行 SVN 检出。我快速查看了那里后备箱中的文件,但找不到任何对 v1.x 文件的引用。
And no, I'm pretty sure that he isn't talking about John Torjo's Boost.Log v2, but a newer version of his Boost.Log that hasn't been packaged for a release yet.
不,我很确定他不是在谈论 John Torjo 的 Boost.Log v2,而是他的 Boost.Log 的一个更新版本,还没有打包发布。
We are using Boost.Log and I'm pretty happy with it so far; your question actually helped me figure out what to do in order to build Boost.Log with 1.46.1...
我们正在使用 Boost.Log,到目前为止我对它很满意;您的问题实际上帮助我弄清楚了如何使用 1.46.1 构建 Boost.Log ...