mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
new command 'log show' to dump out last log messages. useful for serial when you've missed the startup messages
This commit is contained in:
@@ -51,6 +51,12 @@ static inline EMSESP & to_app(Shell & shell) {
|
||||
|
||||
static void console_log_level(Shell & shell, const std::vector<std::string> & arguments) {
|
||||
if (!arguments.empty()) {
|
||||
// special command called show which dumps out the contents of the web log buffer
|
||||
if (arguments[0] == "show") {
|
||||
EMSESP::webLogService.show(shell);
|
||||
return;
|
||||
}
|
||||
|
||||
uuid::log::Level level;
|
||||
|
||||
if (uuid::log::parse_level_lowercase(arguments[0], level)) {
|
||||
|
||||
@@ -154,7 +154,7 @@ MAKE_WORD_CUSTOM(typeid_mandatory, "<type ID>")
|
||||
MAKE_WORD_CUSTOM(deviceid_mandatory, "<deviceID>")
|
||||
MAKE_WORD_CUSTOM(device_type_optional, "[device]")
|
||||
MAKE_WORD_CUSTOM(invalid_log_level, "Invalid log level")
|
||||
MAKE_WORD_CUSTOM(log_level_optional, "[level]")
|
||||
MAKE_WORD_CUSTOM(log_level_optional, "[level | show]")
|
||||
MAKE_WORD_CUSTOM(name_mandatory, "<name>")
|
||||
MAKE_WORD_CUSTOM(name_optional, "[name]")
|
||||
MAKE_WORD_CUSTOM(new_password_prompt1, "Enter new password: ")
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
#include "emsesp.h"
|
||||
|
||||
using ::uuid::console::Shell;
|
||||
|
||||
namespace emsesp {
|
||||
|
||||
WebLogService::WebLogService(AsyncWebServer * server, SecurityManager * securityManager)
|
||||
@@ -135,6 +137,43 @@ void WebLogService::operator<<(std::shared_ptr<uuid::log::Message> message) {
|
||||
});
|
||||
}
|
||||
|
||||
// dumps out the contents of log buffer to shell console
|
||||
void WebLogService::show(Shell & shell) {
|
||||
if (log_messages_.empty())
|
||||
return;
|
||||
|
||||
shell.println();
|
||||
shell.println("Last Log:");
|
||||
shell.println();
|
||||
|
||||
for (const auto & message : log_messages_) {
|
||||
log_message_id_tail_ = message.id_;
|
||||
// Serial.printf("%s", message.content_->text.c_str());
|
||||
// Serial.println();
|
||||
|
||||
shell.print(uuid::log::format_timestamp_ms(message.content_->uptime_ms, 3));
|
||||
shell.printf(" %c %lu: [%s] ", uuid::log::format_level_char(message.content_->level), message.id_, message.content_->name);
|
||||
|
||||
if ((message.content_->level == uuid::log::Level::ERR) || (message.content_->level == uuid::log::Level::WARNING)) {
|
||||
shell.print(COLOR_RED);
|
||||
shell.println(message.content_->text);
|
||||
shell.print(COLOR_RESET);
|
||||
} else if (message.content_->level == uuid::log::Level::INFO) {
|
||||
shell.print(COLOR_YELLOW);
|
||||
shell.println(message.content_->text);
|
||||
shell.print(COLOR_RESET);
|
||||
} else if (message.content_->level == uuid::log::Level::DEBUG) {
|
||||
shell.print(COLOR_CYAN);
|
||||
shell.println(message.content_->text);
|
||||
shell.print(COLOR_RESET);
|
||||
} else {
|
||||
shell.println(message.content_->text);
|
||||
}
|
||||
}
|
||||
|
||||
shell.println();
|
||||
}
|
||||
|
||||
void WebLogService::loop() {
|
||||
if (!events_.count() || log_messages_.empty()) {
|
||||
return;
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#define EMSESP_FETCH_LOG_PATH "/rest/fetchLog"
|
||||
#define EMSESP_LOG_SETTINGS_PATH "/rest/logSettings"
|
||||
|
||||
using ::uuid::console::Shell;
|
||||
|
||||
namespace emsesp {
|
||||
|
||||
class WebLogService : public uuid::log::Handler {
|
||||
@@ -42,6 +44,7 @@ class WebLogService : public uuid::log::Handler {
|
||||
bool compact() const;
|
||||
void compact(bool compact);
|
||||
void loop();
|
||||
void show(Shell & shell);
|
||||
|
||||
virtual void operator<<(std::shared_ptr<uuid::log::Message> message);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user