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

[easylog][improve]remove some define #422

Merged
merged 2 commits into from
Aug 22, 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
11 changes: 4 additions & 7 deletions include/ylt/easylog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,15 @@
#include <utility>
#include <vector>

#ifdef HAS_STD_FORMAT
#if __has_include(<format>)
#include <format>
#endif
#endif

#ifdef HAS_FMT_LIB
#if __has_include(<fmt/format.h>)
#ifndef FMT_HEADER_ONLY
#define FMT_HEADER_ONLY
#include <fmt/format.h>
#endif

#endif

#include "easylog/appender.hpp"
Expand Down Expand Up @@ -232,7 +229,7 @@ inline void add_appender(std::function<void(std::string_view)> fn) {
ELOGV_IMPL(easylog::Severity::severity, Id, __VA_ARGS__, "\n")
#endif

#if defined(HAS_FMT_LIB) || defined(HAS_STD_FORMAT)
#if __has_include(<fmt/format.h>) || __has_include(<format>)

#define ELOGFMT_IMPL0(severity, Id, prefix, format_str, ...) \
if (!easylog::logger<Id>::instance().check_severity(severity)) { \
Expand All @@ -249,12 +246,12 @@ inline void add_appender(std::function<void(std::string_view)> fn) {
} \
}

#ifdef HAS_FMT_LIB
#if __has_include(<fmt/format.h>)
#define ELOGFMT_IMPL(severity, Id, ...) \
ELOGFMT_IMPL0(severity, Id, fmt, __VA_ARGS__)
#endif

#ifdef HAS_STD_FORMAT
#if __has_include(<format>)
#define ELOGFMT_IMPL(severity, Id, ...) \
ELOGFMT_IMPL0(severity, Id, std, __VA_ARGS__)
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/easylog/tests/test_easylog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ TEST_CASE("test basic") {
auto id = std::this_thread::get_id();
ELOG_INFO << buf << ", " << str << ", " << sv << ", " << id;

#if defined(HAS_FMT_LIB) || defined(HAS_STD_FORMAT)
#if __has_include(<fmt/format.h>) || (__has_include(<format>) && !defined(__APPLE__))
ELOGFMT(INFO, "{} {}", 20, 42);
ELOGFMT(INFO, "it is a long string test {} {}", 42, "fmt");
#endif
Expand Down
9 changes: 2 additions & 7 deletions website/docs/zh/easylog/easylog_introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,8 @@ ELOG(INFO) << "easylog " << 42;
// printf输出
ELOGV(INFO, "easylog %d", 42);

// fmt::format 输出
#if defined(HAS_FMT_LIB)
ELOGFMT(INFO, "easylog {}", 42);
#endif

// std::format 输出
#if defined(HAS_STD_FORMAT)
// fmt::format/std::format 输出
#if __has_include(<fmt/format.h>) || __has_include(<format>)
ELOGFMT(INFO, "easylog {}", 42);
#endif
```
Expand Down
Loading