-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
build(android): support android platform (config and logging) #3741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
9fc1b7a
cba9317
85b7fc2
2be4663
aeaf88e
0351cf3
4b823bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -15,11 +15,17 @@ | |||
#include <boost/log/expressions.hpp> | ||||
#include <boost/log/sinks.hpp> | ||||
#include <boost/log/sources/severity_logger.hpp> | ||||
#include <display_device/logging.h> | ||||
|
||||
// local includes | ||||
#include "logging.h" | ||||
|
||||
// conditional includes | ||||
#ifdef __ANDROID__ | ||||
#include <android/log.h> | ||||
#else | ||||
#include <display_device/logging.h> | ||||
#endif | ||||
mengyanshou marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
|
||||
extern "C" { | ||||
#include <libavutil/log.h> | ||||
} | ||||
|
@@ -97,22 +103,67 @@ namespace logging { | |||
os << "["sv << std::put_time(<, "%Y-%m-%d %H:%M:%S.") << boost::format("%03u") % ms.count() << "]: "sv | ||||
<< log_type << view.attribute_values()[message].extract<std::string>(); | ||||
} | ||||
#ifdef __ANDROID__ | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This whole section is not correct way to log to android via boost. You need to create a custom sink (like here https://gist.github.com/cawka/ca21d79605bf51621d6206d2cd76b638) and then probably replace the default sink ( Line 110 in 5da5293
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I will try to modify this part, but it will be a little later. Thank you for your review |
||||
namespace sinks = boost::log::sinks; | ||||
namespace expr = boost::log::expressions; | ||||
|
||||
void android_log(const std::string &message, int severity) { | ||||
android_LogPriority android_priority; | ||||
mengyanshou marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
switch (severity) { | ||||
case 0: | ||||
android_priority = ANDROID_LOG_VERBOSE; | ||||
break; | ||||
case 1: | ||||
android_priority = ANDROID_LOG_DEBUG; | ||||
break; | ||||
case 2: | ||||
android_priority = ANDROID_LOG_INFO; | ||||
break; | ||||
case 3: | ||||
android_priority = ANDROID_LOG_WARN; | ||||
break; | ||||
case 4: | ||||
android_priority = ANDROID_LOG_ERROR; | ||||
break; | ||||
case 5: | ||||
android_priority = ANDROID_LOG_FATAL; | ||||
break; | ||||
default: | ||||
android_priority = ANDROID_LOG_UNKNOWN; | ||||
break; | ||||
} | ||||
__android_log_print(android_priority, "Sunshine", "%s", message.c_str()); | ||||
} | ||||
|
||||
// custom sink backend for android | ||||
struct android_sink_backend: public sinks::basic_sink_backend<sinks::concurrent_feeding> { | ||||
void consume(const bl::record_view &rec) { | ||||
int log_sev = rec[severity].get(); | ||||
const std::string log_msg = rec[expr::smessage].get(); | ||||
// log to android | ||||
android_log(log_msg, log_sev); | ||||
} | ||||
}; | ||||
#endif | ||||
|
||||
[[nodiscard]] std::unique_ptr<deinit_t> init(int min_log_level, const std::string &log_file) { | ||||
if (sink) { | ||||
// Deinitialize the logging system before reinitializing it. This can probably only ever be hit in tests. | ||||
deinit(); | ||||
} | ||||
|
||||
#ifndef __ANDROID__ | ||||
setup_av_logging(min_log_level); | ||||
setup_libdisplaydevice_logging(min_log_level); | ||||
#endif | ||||
Comment on lines
+155
to
+158
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it compile if you remove the |
||||
|
||||
sink = boost::make_shared<text_sink>(); | ||||
|
||||
#ifndef SUNSHINE_TESTS | ||||
boost::shared_ptr<std::ostream> stream {&std::cout, boost::null_deleter()}; | ||||
sink->locked_backend()->add_stream(stream); | ||||
#endif | ||||
|
||||
sink->locked_backend()->add_stream(boost::make_shared<std::ofstream>(log_file)); | ||||
sink->set_filter(severity >= min_log_level); | ||||
sink->set_formatter(&formatter); | ||||
|
@@ -122,9 +173,15 @@ namespace logging { | |||
sink->locked_backend()->auto_flush(true); | ||||
|
||||
bl::core::get()->add_sink(sink); | ||||
|
||||
#ifdef __ANDROID__ | ||||
auto android_sink = boost::make_shared<sinks::synchronous_sink<android_sink_backend>>(); | ||||
bl::core::get()->add_sink(android_sink); | ||||
#endif | ||||
return std::make_unique<deinit_t>(); | ||||
} | ||||
|
||||
#ifndef __ANDROID__ | ||||
void setup_av_logging(int min_log_level) { | ||||
if (min_log_level >= 1) { | ||||
av_log_set_level(AV_LOG_QUIET); | ||||
|
@@ -182,6 +239,7 @@ namespace logging { | |||
} | ||||
}); | ||||
} | ||||
#endif | ||||
|
||||
void log_flush() { | ||||
if (sink) { | ||||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless there are some compilation issues, I would not touch the
display_device
. This functionSunshine/src/display_device.cpp
Line 615 in 5da5293
This means that every
display_device
function will either do nothing or act as a "pass-trough". Same for logging - nothing should be logged viasetup_libdisplaydevice_logging
, so maybe just keep it as it is?