export log formatter.

This commit is contained in:
amass 2023-12-27 21:49:33 +08:00
parent c845c037ef
commit 46836a2d5f
4 changed files with 53 additions and 8 deletions

44
.gitignore vendored Normal file
View File

@ -0,0 +1,44 @@
# C++ objects and libs
*.slo
*.lo
*.o
*.a
*.la
*.lai
*.so
*.dll
*.dylib
# Qt-es
object_script.*.Release
object_script.*.Debug
*_plugin_import.cpp
/.qmake.cache
/.qmake.stash
*.pro.user
*.pro.user.*
*.qbs.user
*.qbs.user.*
*.moc
moc_*.cpp
moc_*.h
qrc_*.cpp
*.qmlc
*.jsc
Makefile*
*build-*
# Qt unit tests
target_wrapper.*
# QtCreator
*.autosave
# QtCreator Qml
*.qmlproject.user
*.qmlproject.user.*
# QtCreator CMake
CMakeLists.txt.user*
build

View File

@ -7,12 +7,10 @@
#include "AndroidBoostLog.h" #include "AndroidBoostLog.h"
#endif #endif
static void logFormatter(boost::log::record_view const &record, boost::log::formatting_ostream &ostream);
BOOST_LOG_GLOBAL_LOGGER_INIT(location_logger, LocationLogger<boost::log::trivial::severity_level>) { BOOST_LOG_GLOBAL_LOGGER_INIT(location_logger, LocationLogger<boost::log::trivial::severity_level>) {
LocationLogger<boost::log::trivial::severity_level> lg; LocationLogger<boost::log::trivial::severity_level> lg;
auto consoleSink = boost::log::add_console_log(); auto consoleSink = boost::log::add_console_log();
consoleSink->set_formatter(&logFormatter); consoleSink->set_formatter(&boost::log::defaultFormatter);
boost::log::add_common_attributes(); boost::log::add_common_attributes();
return lg; return lg;
} }
@ -35,15 +33,13 @@ void initialize(const std::string &filename, const std::string &target, boost::l
oss << filename << "_%Y-%m-%d_%H.%M.%S_%N.log"; oss << filename << "_%Y-%m-%d_%H.%M.%S_%N.log";
auto fileSink = auto fileSink =
add_file_log(keywords::file_name = oss.str(), keywords::auto_flush = true, keywords::target = target); add_file_log(keywords::file_name = oss.str(), keywords::auto_flush = true, keywords::target = target);
fileSink->set_formatter(&logFormatter); fileSink->set_formatter(&defaultFormatter);
#endif #endif
initialized = true; initialized = true;
} }
} }
} // namespace log
} // namespace boost
static void logFormatter(const boost::log::record_view &record, boost::log::formatting_ostream &ostream) { void defaultFormatter(const boost::log::record_view &record, boost::log::formatting_ostream &ostream) {
using namespace boost::log; using namespace boost::log;
std::string level; std::string level;
@ -70,3 +66,6 @@ static void logFormatter(const boost::log::record_view &record, boost::log::form
// Finally, put the record message to the stream // Finally, put the record message to the stream
ostream << record[expressions::smessage]; ostream << record[expressions::smessage];
} }
} // namespace log
} // namespace boost

View File

@ -64,6 +64,8 @@ namespace log {
*/ */
void initialize(const std::string &filename = "logs/app", const std::string &target = "logs", void initialize(const std::string &filename = "logs/app", const std::string &target = "logs",
trivial::severity_level filter = static_cast<trivial::severity_level>(LOG_FILTER_LEVEL)); trivial::severity_level filter = static_cast<trivial::severity_level>(LOG_FILTER_LEVEL));
void defaultFormatter(boost::log::record_view const &record, boost::log::formatting_ostream &ostream);
} // namespace log } // namespace log
} // namespace boost } // namespace boost

2
resource/deploy.sh Normal file → Executable file
View File

@ -3,7 +3,7 @@
base_path=$(pwd) base_path=$(pwd)
qt_prefix_path="/opt/Qt/6.6.1/gcc_64" qt_prefix_path="/opt/Qt/6.6.1/gcc_64"
libraries_root="/opt/Libraries" libraries_root="/opt/Libraries"
if [ $base_path == /home/* ] || [ -n "${DRONE}" ]; then if [ $base_path==/home/* ]; then
build_path=${base_path}/build build_path=${base_path}/build
else else
build_path=/tmp/build build_path=/tmp/build