Skip to content
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

refactor: split logger #91

Merged
merged 5 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions source/MaaDbgControlUnit/CarouselImage/CarouselImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bool CarouselImage::connect()
LogInfo << VAR(images_.size());

if (images_.empty()) {
LogError << "no image" << VAR(path);
LogError << "no image" << VAR(path_);
return false;
}

Expand Down Expand Up @@ -127,7 +127,7 @@ bool CarouselImage::press_key(int key)
std::optional<cv::Mat> CarouselImage::screencap()
{
if (images_.empty()) {
LogError << "no image" << VAR(path);
LogError << "no image" << VAR(path_);
return std::nullopt;
}

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
2 changes: 1 addition & 1 deletion source/MaaFramework/Vision/CustomRecognizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ CustomRecognizer::CustomRecognizer(MaaCustomRecognizerHandle handle, MaaTranspar

CustomRecognizer::ResultsVec CustomRecognizer::analyze() const
{
LogFunc << VAR_VOIDP(recognizer_) << VAR(recognizer_->analyze) << VAR(param_.custom_param);
LogFunc << VAR_VOIDP(recognizer_) << VAR_VOIDP(recognizer_->analyze) << VAR(param_.custom_param);

if (!recognizer_ || !recognizer_->analyze) {
LogError << "Recognizer is null";
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
6 changes: 6 additions & 0 deletions source/include/Conf/Conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@
{
#define MAA_PLATFORM_NS_END }

#define MAA_LOG_NS MAA_NS::LogNS
#define MAA_LOG_NS_BEGIN \
namespace MAA_LOG_NS \
{
#define MAA_LOG_NS_END }

/* MaaFramwork */

#define MAA_RES_NS MAA_NS::ResourceNS
Expand Down
Loading