diff --git a/docs/source/about/advanced_usage.rst b/docs/source/about/advanced_usage.rst index 4b0f7fed..ab46db3a 100644 --- a/docs/source/about/advanced_usage.rst +++ b/docs/source/about/advanced_usage.rst @@ -93,6 +93,20 @@ min_log_level min_log_level = info +log_path +^^^^^^^^ + +**Description** + The path where the sunshine log is stored. + +**Default** + ``sunshine.log`` + +**Example** + .. code-block:: text + + log_path = sunshine.log + Controls -------- diff --git a/src/config.cpp b/src/config.cpp index bc387d97..5bc04159 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -336,6 +336,7 @@ sunshine_t sunshine { platf::appdata().string() + "/sunshine.conf", // config file {}, // cmd args 47989, + platf::appdata().string() + "/sunshine.log", // log file }; bool endline(char ch) { @@ -788,7 +789,7 @@ void apply_config(std::unordered_map &&vars) { path_f(vars, "pkey", nvhttp.pkey); path_f(vars, "cert", nvhttp.cert); string_f(vars, "sunshine_name", nvhttp.sunshine_name); - + path_f(vars, "log_path", config::sunshine.log_file); path_f(vars, "file_state", nvhttp.file_state); // Must be run after "file_state" diff --git a/src/config.h b/src/config.h index 6d4d69be..7b1c705e 100644 --- a/src/config.h +++ b/src/config.h @@ -122,6 +122,7 @@ struct sunshine_t { } cmd; std::uint16_t port; + std::string log_file; }; extern video_t video; diff --git a/src/confighttp.cpp b/src/confighttp.cpp index d6b60c0f..8df67249 100644 --- a/src/confighttp.cpp +++ b/src/confighttp.cpp @@ -274,6 +274,17 @@ void getApps(resp_https_t response, req_https_t request) { response->write(content); } +void getLogs(resp_https_t response, req_https_t request) { + if(!authenticate(response, request)) return; + + print_req(request); + + std::string content = read_file(config::sunshine.log_file.c_str()); + SimpleWeb::CaseInsensitiveMultimap headers; + headers.emplace("Content-Type", "text/plain"); + response->write(SimpleWeb::StatusCode::success_ok, content, headers); +} + void saveApp(resp_https_t response, req_https_t request) { if(!authenticate(response, request)) return; @@ -648,6 +659,7 @@ void start() { server.resource["^/troubleshooting$"]["GET"] = getTroubleshootingPage; server.resource["^/api/pin$"]["POST"] = savePin; server.resource["^/api/apps$"]["GET"] = getApps; + server.resource["^/api/logs$"]["GET"] = getLogs; server.resource["^/api/apps$"]["POST"] = saveApp; server.resource["^/api/config$"]["GET"] = getConfig; server.resource["^/api/config$"]["POST"] = saveConfig; diff --git a/src/main.cpp b/src/main.cpp index 114502ed..886149e8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -101,6 +101,7 @@ int entry(const char *name, int argc, char *argv[]) { } } // namespace version + void log_flush() { sink->flush(); } @@ -219,6 +220,7 @@ int main(int argc, char *argv[]) { boost::shared_ptr stream { &std::cout, NoDelete {} }; sink->locked_backend()->add_stream(stream); + sink->locked_backend()->add_stream(boost::make_shared(config::sunshine.log_file)); sink->set_filter(severity >= config::sunshine.min_log_level); sink->set_formatter([message = "Message"s, severity = "Severity"s](const bl::record_view &view, bl::formatting_ostream &os) { diff --git a/src/main.h b/src/main.h index 89c4dbdc..3fec1f83 100644 --- a/src/main.h +++ b/src/main.h @@ -3,6 +3,7 @@ #ifndef SUNSHINE_MAIN_H #define SUNSHINE_MAIN_H +#include #include #include "thread_pool.h" @@ -50,6 +51,4 @@ MAIL(idr); MAIL(rumble); #undef MAIL } // namespace mail - - #endif // SUNSHINE_MAIN_H diff --git a/src_assets/common/assets/web/config.html b/src_assets/common/assets/web/config.html index 7475ad83..99e71a92 100644 --- a/src_assets/common/assets/web/config.html +++ b/src_assets/common/assets/web/config.html @@ -49,6 +49,20 @@ The minimum log level printed to standard out + +
+ + +
+ The file where the current logs of Sunshine are stored. +
+
-
+ +
+
+

Logs

+
+
+

See the logs uploaded by Sunshine

+ +
+
+
+ {{actualLogs}} +
+
+
+
+ +