Skip to content

Commit

Permalink
refactor: split logger
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Oct 31, 2023
1 parent 2612a72 commit 3cef8f5
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 159 deletions.
4 changes: 2 additions & 2 deletions source/MaaAdbControlUnit/UnitBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ std::optional<std::string> UnitBase::command(const Argv::value& cmd, bool recv_b
LogDebug << VAR(scmd) << VAR(ret) << VAR(pipe_data.size()) << VAR(sock_data.size()) << VAR(duration);

if (!pipe_data.empty() && pipe_data.size() < 4096) {
LogDebug << Logger::separator::newline << "stdout output:" << pipe_data;
LogDebug << MAA_LOG_NS::separator::newline << "stdout output:" << pipe_data;
}
if (recv_by_socket && !sock_data.empty() && sock_data.size() < 4096) {
LogDebug << Logger::separator::newline << "socket output:" << sock_data;
LogDebug << MAA_LOG_NS::separator::newline << "socket output:" << sock_data;
}

if (ret != 0) {
Expand Down
2 changes: 1 addition & 1 deletion source/MaaFramework/Instance/InstanceMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ bool InstanceMgr::run_task(TaskId id, TaskPtr task_ptr)

status_.clear();

Logger::get_instance().flush();
MAA_LOG_NS::Logger::get_instance().flush();

return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions source/MaaFramework/Option/GlobalOptionMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bool GlobalOptionMgr::set_log_dir(MaaOptionValue value, MaaOptionValueSize val_s

LogInfo << "Set log path" << VAR(log_dir_);

Logger::get_instance().start_logging(log_dir_);
MAA_LOG_NS::Logger::get_instance().start_logging(log_dir_);

return true;
}
Expand Down Expand Up @@ -83,7 +83,7 @@ bool GlobalOptionMgr::set_stdout_level(MaaOptionValue value, MaaOptionValueSize

LogInfo << "Set log stdout level" << VAR(level);

Logger::get_instance().set_stdout_level(level);
MAA_LOG_NS::Logger::get_instance().set_stdout_level(level);

return true;
}
Expand Down
22 changes: 11 additions & 11 deletions source/MaaUtils/Logger/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@

#pragma message("MaaUtils MAA_VERSION: " MAA_VERSION)

MAA_NS_BEGIN
MAA_LOG_NS_BEGIN

constexpr Logger::separator Logger::separator::none("");
constexpr Logger::separator Logger::separator::space(" ");
constexpr Logger::separator Logger::separator::tab("\t");
constexpr Logger::separator Logger::separator::newline("\n");
constexpr Logger::separator Logger::separator::comma(",");
constexpr separator separator::none("");
constexpr separator separator::space(" ");
constexpr separator separator::tab("\t");
constexpr separator separator::newline("\n");
constexpr separator separator::comma(",");

static constexpr std::string_view kSplitLine = "-----------------------------";

std::string Logger::LogStream::stdout_string()
std::string LogStream::stdout_string()
{
std::string color;

Expand All @@ -39,11 +39,11 @@ std::string Logger::LogStream::stdout_string()
case level::trace:
break;
}

return color + utf8_to_crt(buffer_.str()) + "\033[0m";
}

std::string_view Logger::LogStream::level_str()
std::string_view LogStream::level_str()
{
switch (lv_) {
case level::fatal:
Expand Down Expand Up @@ -179,9 +179,9 @@ void Logger::log_proc_info()
internal_dbg() << kSplitLine;
}

Logger::LogStream Logger::internal_dbg()
LogStream Logger::internal_dbg()
{
return debug("Logger");
}

MAA_NS_END
MAA_LOG_NS_END
Loading

0 comments on commit 3cef8f5

Please sign in to comment.