Skip to content

Commit 2de6102

Browse files
committed
fix: fix logger
1 parent f032bb0 commit 2de6102

File tree

2 files changed

+35
-56
lines changed

2 files changed

+35
-56
lines changed

src/pl/Logger.h

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,48 @@
1-
#pragma once
2-
1+
#include <android/log.h>
2+
#include <format>
33
#include <string>
4+
#include <string_view>
5+
46
namespace pl {
57
namespace log {
68

9+
inline constexpr const char *LOG_TAG = "LeviLogger";
10+
711
class Logger {
812
public:
9-
explicit Logger(const std::string &name);
13+
explicit Logger(std::string name) : loggerName(std::move(name)) {}
14+
15+
template <typename... Args>
16+
void info(std::string_view fmt_str, Args &&...args) const {
17+
log(ANDROID_LOG_INFO, fmt_str, std::forward<Args>(args)...);
18+
}
1019

11-
void info(const char *fmt, ...);
12-
void debug(const char *fmt, ...);
13-
void warn(const char *fmt, ...);
14-
void error(const char *fmt, ...);
20+
template <typename... Args>
21+
void debug(std::string_view fmt_str, Args &&...args) const {
22+
log(ANDROID_LOG_DEBUG, fmt_str, std::forward<Args>(args)...);
23+
}
24+
25+
template <typename... Args>
26+
void warn(std::string_view fmt_str, Args &&...args) const {
27+
log(ANDROID_LOG_WARN, fmt_str, std::forward<Args>(args)...);
28+
}
29+
30+
template <typename... Args>
31+
void error(std::string_view fmt_str, Args &&...args) const {
32+
log(ANDROID_LOG_ERROR, fmt_str, std::forward<Args>(args)...);
33+
}
1534

1635
private:
1736
std::string loggerName;
18-
void log(int level, const char *fmt, va_list args);
37+
38+
template <typename... Args>
39+
void log(int android_level, std::string_view fmt_str, Args &&...args) const {
40+
auto msg =
41+
std::format("[{}] {}", loggerName,
42+
std::vformat(fmt_str, std::make_format_args(args...)));
43+
__android_log_print(android_level, LOG_TAG, "%s", msg.c_str());
44+
}
1945
};
46+
2047
} // namespace log
2148
} // namespace pl

src/pl/internal/Logger.cpp

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)