0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C++のDebugログ出力

Last updated at Posted at 2019-09-04

boost logを使う場合、Debugログをログファイルに出力するマクロの定義です。

#include <boost/log/trivial.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/utility/setup/file.hpp>

#define LOG_INIT                                                                                           \
    boost::log::register_simple_formatter_factory<boost::log::trivial::severity_level, char>("Severity");  \
    boost::log::add_common_attributes();                                                                   \
    boost::log::add_file_log(“xxxx.log", boost::log::keywords::format = "[%TimeStamp%][%Severity%]%Message%", boost::log::keywords::auto_flush = true)

#define LOG_FILENAME    (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#define LOG_LOCATION    "[" << LOG_FILENAME << ":" << __LINE__ << ":" << __FUNCTION__ << "] "

#define DEBUG_LOG(X)   BOOST_LOG_TRIVIAL(debug) << LOG_LOCATION << X

DEBUG_LOG("Core::initialize finished")を叩くと

以下のようなフォーマットのログをxxxx.logファイルに出力され、出力する場所、時間をはっきりわかりますね

[2019-08-27 13:58:04.801361][debug][Core.cpp:74:Core::initialize] Core::initialize finished
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?