7 #include "fwAtomsPatch/infos/Logger.hpp" 10 #include <fwRuntime/profile/Profile.hpp> 11 #include <fwTools/Os.hpp> 13 #include <boost/filesystem.hpp> 14 #include <boost/log/attributes.hpp> 15 #include <boost/log/expressions.hpp> 16 #include <boost/log/expressions/formatters/date_time.hpp> 17 #include <boost/log/keywords/channel.hpp> 18 #include <boost/log/sinks.hpp> 19 #include <boost/log/sources/channel_logger.hpp> 20 #include <boost/log/sources/global_logger_storage.hpp> 21 #include <boost/log/support/date_time.hpp> 22 #include <boost/log/trivial.hpp> 23 #include <boost/log/utility/setup/common_attributes.hpp> 24 #include <boost/log/utility/setup/file.hpp> 25 #include <boost/parameter/keyword.hpp> 27 #include <android/log.h> 38 BOOST_LOG_GLOBAL_LOGGER(lg_channel,
39 ::boost::log::sources::channel_logger<std::string>);
41 BOOST_LOG_GLOBAL_LOGGER_CTOR_ARGS(lg_channel,
42 ::boost::log::sources::channel_logger_mt<std::string>,
43 (std::string(
"patch")));
45 Logger::StreamPtrType Logger::s_stream = ::boost::make_shared< Logger::StreamType >();
48 #define LOG_TAG "Logger" 49 #define LOGSTREAM(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) 51 Logger::StreamPtrType Logger::s_stream;
55 Logger Logger::s_logger;
61 namespace expr = ::boost::log::expressions;
62 namespace keywords = ::boost::log::keywords;
65 namespace bfile = ::boost::filesystem;
68 ::fwRuntime::profile::Profile::sptr profile = ::fwRuntime::profile::getCurrentProfile();
71 std::string appName =
"default";
75 appName = profile->getName();
78 const bfile::path appPrefDir = ::fwTools::os::getUserDataDir(
"fw4spl", appName,
true);
80 FW_RAISE_IF(
"Unable to define User's data directory", appPrefDir.empty());
82 if (!bfile::exists(appPrefDir))
84 bfile::create_directories(appPrefDir);
87 ::boost::log::add_file_log (
89 keywords::file_name = appPrefDir.string() +
"/PATCH.log",
91 keywords::rotation_size = 10 * 1024 * 1024,
93 keywords::time_based_rotation = ::boost::log::sinks::file::rotation_at_time_point(0, 0, 0),
97 <<
"[" << expr::format_date_time< ::boost::posix_time::ptime >(
"TimeStamp",
"%d.%m.%Y %H:%M:%S.%f")
98 <<
"][" << expr::format_date_time< ::boost::posix_time::ptime >(
"Uptime",
"%H:%M:%S.%f")
99 <<
"][" << expr::attr< std::string >(
"Channel")
100 <<
"] " << expr::smessage
103 keywords::auto_flush =
true,
104 keywords::filter = (expr::attr< std::string >(
"Channel") ==
"patch")
108 typedef ::boost::log::sinks::synchronous_sink< ::boost::log::sinks::text_ostream_backend > text_sink;
109 ::boost::shared_ptr< text_sink > pSink = ::boost::make_shared< text_sink >();
112 pSink->locked_backend()->add_stream(s_stream);
115 ::boost::log::core::get()->add_sink(pSink);
127 Logger::StreamPtrType Logger::getStream()
137 BOOST_LOG_STREAM(lg_channel::get()) <<
"PATCH_ERROR" <<
": " << message;
139 LOGSTREAM(
"BADCAST: %s", message.c_str());
148 BOOST_LOG_STREAM(lg_channel::get()) <<
"BADCAST" <<
": " << message;
150 LOGSTREAM(
"BADCAST: %s", message.c_str());
159 BOOST_LOG_STREAM(lg_channel::get()) <<
"OUTOFRANGE" <<
": " << message;
161 LOGSTREAM(
"BADCAST: %s", message.c_str());
170 BOOST_LOG_STREAM(lg_channel::get()) <<
"INFO" <<
": " << message;
172 LOGSTREAM(
"BADCAST: %s", message.c_str());
181 BOOST_LOG_STREAM(lg_channel::get()) <<
"ADD_ATTR" <<
": " << message;
183 LOGSTREAM(
"BADCAST: %s", message.c_str());
192 BOOST_LOG_STREAM(lg_channel::get()) <<
"ERASE_ATTR" <<
": " << message;
194 LOGSTREAM(
"BADCAST: %s", message.c_str());
203 BOOST_LOG_STREAM(lg_channel::get()) <<
"REPLACE_ATTR" <<
": " << message;
205 LOGSTREAM(
"BADCAST: %s", message.c_str());
FWATOMSPATCH_API void badCast(const std::string &message)
Bad cast message.
FWATOMSPATCH_API void eraseAttribute(const std::string &message)
Erase attribute message.
FWATOMSPATCH_API void outOfRange(const std::string &message)
Out of range message.
FWATOMSPATCH_API ~Logger()
Logger destructor.
Contains base functionalities used to transform objects from a version to another.
FWATOMSPATCH_API void info(const std::string &message)
Information message.
FWATOMSPATCH_API void addAttribute(const std::string &message)
New attribute message.
FWATOMSPATCH_API void replaceAttribute(const std::string &message)
Replace attribute message.
FWATOMSPATCH_API void error(const std::string &message)
Error message.