8 #pragma warning(disable : 4996) // warning for sprintf() in Boost.log 12 #include <boost/log/core.hpp> 13 #include <boost/log/attributes.hpp> 14 #include <boost/log/sinks/sink.hpp> 15 #include <boost/log/sources/global_logger_storage.hpp> 16 #include <boost/log/sources/logger.hpp> 17 #include <boost/log/sources/severity_logger.hpp> 18 #include <boost/log/utility/setup/common_attributes.hpp> 19 #include <boost/log/expressions.hpp> 20 #include <boost/log/trivial.hpp> 21 #include <boost/log/utility/setup/console.hpp> 22 #include <boost/log/utility/setup/file.hpp> 23 #include <boost/log/expressions/formatters/date_time.hpp> 24 #include <boost/log/support/date_time.hpp> 25 #include <boost/log/attributes/current_thread_id.hpp> 26 #include <boost/log/attributes/current_process_id.hpp> 27 #include <boost/log/attributes/timer.hpp> 29 #include <android/log.h> 33 #include "fwCore/log/SpyLogger.hpp" 40 SpyLogger SpyLogger::s_spyLogger;
43 BOOST_LOG_GLOBAL_LOGGER(lg, ::boost::log::sources::severity_logger_mt< ::boost::log::trivial::severity_level >);
44 BOOST_LOG_GLOBAL_LOGGER_DEFAULT(lg, ::boost::log::sources::severity_logger_mt< ::boost::log::trivial::severity_level >);
46 #define LOG_TAG "SpyLogger" 47 #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) 48 #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) 49 #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) 50 #define LOGF(...) __android_log_print(ANDROID_LOG_FATAL, LOG_TAG, __VA_ARGS__) 51 #define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__) 56 SpyLogger::SpyLogger()
59 ::boost::log::add_common_attributes();
60 ::boost::log::core::get()
61 ->add_global_attribute(
"Uptime", ::boost::log::attributes::timer());
67 void SpyLogger::createBasicConfiguration()
70 this->addFileAppender();
72 this->addStreamAppender();
78 void SpyLogger::addStreamAppender( std::ostream &os, LevelType level )
81 namespace expr = ::boost::log::expressions;
82 namespace keywords = ::boost::log::keywords;
84 typedef ::boost::posix_time::ptime::time_duration_type DurationType;
86 ::boost::log::add_console_log (
90 << expr::attr<unsigned int>(
"LineID")
91 <<
"][" << expr::format_date_time< DurationType >(
"Uptime",
"%H:%M:%S.%f")
92 <<
"][" << expr::attr< ::boost::log::trivial::severity_level >(
"Severity")
93 <<
"] " << expr::smessage
95 keywords::filter = expr::attr< ::boost::log::trivial::severity_level >(
"Severity") >=
96 static_cast < ::boost::log::trivial::severity_level > (level),
98 keywords::auto_flush =
true 111 void SpyLogger::addFileAppender(
const std::string & logFile, LevelType level)
114 namespace expr = ::boost::log::expressions;
115 namespace keywords = ::boost::log::keywords;
117 typedef ::boost::posix_time::ptime::time_duration_type DurationType;
119 ::boost::log::add_file_log (
121 keywords::file_name = logFile,
123 keywords::rotation_size = 10 * 1024 * 1024,
125 keywords::time_based_rotation = ::boost::log::sinks::file::rotation_at_time_point(0, 0, 0),
129 <<
"[" << expr::format_date_time< ::boost::posix_time::ptime >(
"TimeStamp",
"%d.%m.%Y %H:%M:%S.%f")
130 <<
"][" << expr::format_date_time< DurationType >(
"Uptime",
"%H:%M:%S.%f")
131 <<
"][" << expr::attr< ::boost::log::attributes::current_process_id::value_type >(
"ProcessID")
132 <<
"][" << expr::attr< ::boost::log::attributes::current_thread_id::value_type >(
"ThreadID")
133 <<
"][" << expr::attr< ::boost::log::trivial::severity_level >(
"Severity")
134 <<
"] " << expr::smessage
136 keywords::filter = expr::attr< ::boost::log::trivial::severity_level >(
"Severity") >=
137 static_cast < ::boost::log::trivial::severity_level > (level),
139 keywords::auto_flush =
true 146 void SpyLogger::setLevel(LevelType level)
149 ::boost::log::core::get()->set_filter
151 ::boost::log::expressions::attr< ::boost::log::trivial::severity_level >(
"Severity")
152 >= static_cast < ::boost::log::trivial::severity_level > (level)
159 void SpyLogger::trace(
const std::string & mes,
const char * file,
int line)
162 BOOST_LOG_SEV(lg::get(), ::boost::log::trivial::trace) << file <<
":" << line <<
": "<< mes;
164 LOGI(
"t: %s(%d): %s", file, line, mes.c_str());
170 void SpyLogger::debug(
const std::string & mes,
const char * file,
int line)
173 BOOST_LOG_SEV(lg::get(), ::boost::log::trivial::debug) << file <<
":" << line <<
": "<< mes;
175 LOGI(
"i: %s(%d): %s", file, line, mes.c_str());
181 void SpyLogger::info(
const std::string & mes,
const char * file,
int line)
184 BOOST_LOG_SEV(lg::get(), ::boost::log::trivial::info) << file <<
":" << line <<
": "<< mes;
186 LOGI(
"i: %s(%d): %s", file, line, mes.c_str());
192 void SpyLogger::warn(
const std::string & mes,
const char * file,
int line)
195 BOOST_LOG_SEV(lg::get(), ::boost::log::trivial::warning) << file <<
":" << line <<
": "<< mes;
197 LOGW(
"w: %s(%d): %s", file, line, mes.c_str());
203 void SpyLogger::error(
const std::string & mes,
const char * file,
int line)
206 BOOST_LOG_SEV(lg::get(), ::boost::log::trivial::error) << file <<
":" << line <<
": "<< mes;
208 LOGE(
"e: %s(%d): %s", file, line, mes.c_str());
214 void SpyLogger::fatal(
const std::string & mes,
const char * file,
int line)
217 BOOST_LOG_SEV(lg::get(), ::boost::log::trivial::fatal) << file <<
":" << line <<
": "<< mes;
219 LOGF(
"f: %s(%d): %s", file, line, mes.c_str());
225 void SpyLogger::log(
const std::string & mes,
const char * file,
int line)
228 BOOST_LOG_SEV(lg::get(), ::boost::log::trivial::error) << file <<
":" << line <<
": "<< mes;
230 LOGI(
"i: %s(%d): %s", file, line, mes.c_str());
This file defines fwCore base macros.
This namespace fwCore provides common foundations for FW4SPL.