Skip to content
Open
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 include/spdlog/bin_to_hex.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
// logger->info("Some buffer {:X}", spdlog::to_hex(std::begin(buf), std::end(buf)));
// logger->info("Some buffer {:X}", spdlog::to_hex(std::begin(buf), std::end(buf), 16));

namespace spdlog {
SPDLOG_NAMESPACE_BEGIN
namespace details {

template <typename It>
Expand Down Expand Up @@ -86,7 +86,7 @@ inline details::dump_info<It> to_hex(const It range_begin, const It range_end, s
return details::dump_info<It>(range_begin, range_end, size_per_line);
}

} // namespace spdlog
SPDLOG_NAMESPACE_END

template <typename T>
struct fmt::formatter<spdlog::details::dump_info<T>, char> {
Expand Down
11 changes: 6 additions & 5 deletions include/spdlog/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <string>
#include <string_view>

#include "./namespace.h"
#include "./source_loc.h"
#include "fmt/base.h"
#include "fmt/xchar.h"
Expand Down Expand Up @@ -41,7 +42,7 @@
#define SPDLOG_FUNCTION static_cast<const char *>(__FUNCTION__)
#endif

namespace spdlog {
SPDLOG_NAMESPACE_BEGIN

class formatter;

Expand Down Expand Up @@ -96,15 +97,15 @@ constexpr std::array<std::string_view, levels_count> level_string_views{"trace",
"error", "critical", "off"};
constexpr std::array<std::string_view, levels_count> short_level_names{"T", "D", "I", "W", "E", "C", "O"};

[[nodiscard]] constexpr std::string_view to_string_view(spdlog::level lvl) noexcept {
[[nodiscard]] constexpr std::string_view to_string_view(level lvl) noexcept {
return level_string_views.at(level_to_number(lvl));
}

[[nodiscard]] constexpr std::string_view to_short_string_view(spdlog::level lvl) noexcept {
[[nodiscard]] constexpr std::string_view to_short_string_view(level lvl) noexcept {
return short_level_names.at(level_to_number(lvl));
}

[[nodiscard]] SPDLOG_API spdlog::level level_from_str(const std::string &name) noexcept;
[[nodiscard]] SPDLOG_API level level_from_str(const std::string &name) noexcept;

//
// Color mode used by sinks with color support.
Expand Down Expand Up @@ -138,4 +139,4 @@ class SPDLOG_API spdlog_ex : public std::exception {
[[noreturn]] SPDLOG_API void throw_spdlog_ex(const std::string &msg, int last_errno);
[[noreturn]] SPDLOG_API void throw_spdlog_ex(std::string msg);

} // namespace spdlog
SPDLOG_NAMESPACE_END
4 changes: 2 additions & 2 deletions include/spdlog/details/async_log_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "./log_msg.h"

namespace spdlog {
SPDLOG_NAMESPACE_BEGIN
namespace details {

// Extend log_msg with internal buffer to store its payload.
Expand All @@ -32,4 +32,4 @@ class SPDLOG_API async_log_msg : public log_msg {
};

} // namespace details
} // namespace spdlog
SPDLOG_NAMESPACE_END
4 changes: 2 additions & 2 deletions include/spdlog/details/circular_q.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <spdlog/common.h>

namespace spdlog {
SPDLOG_NAMESPACE_BEGIN
namespace details {
template <typename T>
class circular_q {
Expand Down Expand Up @@ -118,4 +118,4 @@ class circular_q {
}
};
} // namespace details
} // namespace spdlog
SPDLOG_NAMESPACE_END
4 changes: 2 additions & 2 deletions include/spdlog/details/err_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "spdlog/common.h"

// by default, prints the error to stderr, at max rate of 1/sec thread safe
namespace spdlog {
SPDLOG_NAMESPACE_BEGIN
namespace details {
class SPDLOG_API err_helper {
err_handler custom_err_handler_;
Expand All @@ -28,4 +28,4 @@ class SPDLOG_API err_helper {
void set_err_handler(err_handler handler);
};
} // namespace details
} // namespace spdlog
SPDLOG_NAMESPACE_END
4 changes: 2 additions & 2 deletions include/spdlog/details/file_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "../common.h"
#include "../file_event_handlers.h"

namespace spdlog {
SPDLOG_NAMESPACE_BEGIN
namespace details {

// Helper class for file sinks.
Expand Down Expand Up @@ -41,4 +41,4 @@ class SPDLOG_API file_helper {
file_event_handlers event_handlers_;
};
} // namespace details
} // namespace spdlog
SPDLOG_NAMESPACE_END
6 changes: 3 additions & 3 deletions include/spdlog/details/fmt_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
#include "../common.h"

// Some fmt helpers to efficiently format and pad ints and strings
namespace spdlog {
SPDLOG_NAMESPACE_BEGIN
namespace details {
namespace fmt_helper {

inline void append_string_view(spdlog::string_view_t view, memory_buf_t &dest) {
inline void append_string_view(string_view_t view, memory_buf_t &dest) {
const auto *buf_ptr = view.data();
dest.append(buf_ptr, buf_ptr + view.size());
}
Expand Down Expand Up @@ -113,4 +113,4 @@ ToDuration time_fraction(log_clock::time_point tp) {

} // namespace fmt_helper
} // namespace details
} // namespace spdlog
SPDLOG_NAMESPACE_END
4 changes: 2 additions & 2 deletions include/spdlog/details/log_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "../common.h"

namespace spdlog {
SPDLOG_NAMESPACE_BEGIN
namespace details {
struct SPDLOG_API log_msg {
log_msg() = default;
Expand All @@ -30,4 +30,4 @@ struct SPDLOG_API log_msg {
string_view_t payload;
};
} // namespace details
} // namespace spdlog
SPDLOG_NAMESPACE_END
6 changes: 3 additions & 3 deletions include/spdlog/details/mpmc_blocking_q.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "./circular_q.h"

namespace spdlog {
SPDLOG_NAMESPACE_BEGIN
namespace details {

template <typename T>
Expand Down Expand Up @@ -165,8 +165,8 @@ class mpmc_blocking_queue {
std::mutex queue_mutex_;
std::condition_variable push_cv_;
std::condition_variable pop_cv_;
spdlog::details::circular_q<T> q_;
circular_q<T> q_;
std::atomic<size_t> discard_counter_{0};
};
} // namespace details
} // namespace spdlog
SPDLOG_NAMESPACE_END
6 changes: 4 additions & 2 deletions include/spdlog/details/null_mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

#pragma once

#include <spdlog/namespace.h>

#include <atomic>
#include <utility>

// null, no cost dummy "mutex" and dummy "atomic" log level
namespace spdlog {
SPDLOG_NAMESPACE_BEGIN
namespace details {
struct null_mutex {
void lock() const {}
Expand All @@ -34,4 +36,4 @@ struct null_atomic {
};

} // namespace details
} // namespace spdlog
SPDLOG_NAMESPACE_END
6 changes: 3 additions & 3 deletions include/spdlog/details/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
#include "../common.h"
#include "../filename_t.h"

namespace spdlog {
SPDLOG_NAMESPACE_BEGIN
namespace details {
namespace os {

SPDLOG_API spdlog::log_clock::time_point now() noexcept;
SPDLOG_API log_clock::time_point now() noexcept;

SPDLOG_API std::tm localtime(const std::time_t &time_tt) noexcept;

Expand Down Expand Up @@ -125,4 +125,4 @@ SPDLOG_API std::string filename_to_str(const filename_t &filename);

} // namespace os
} // namespace details
} // namespace spdlog
SPDLOG_NAMESPACE_END
4 changes: 2 additions & 2 deletions include/spdlog/details/tcp_client_unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "../common.h"
#include "./os.h"

namespace spdlog {
SPDLOG_NAMESPACE_BEGIN
namespace details {
class tcp_client_unix {
int socket_ = -1;
Expand Down Expand Up @@ -198,4 +198,4 @@ class tcp_client_unix {
}
};
} // namespace details
} // namespace spdlog
SPDLOG_NAMESPACE_END
4 changes: 2 additions & 2 deletions include/spdlog/details/tcp_client_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#pragma comment(lib, "Mswsock.lib")
#pragma comment(lib, "AdvApi32.lib")

namespace spdlog {
SPDLOG_NAMESPACE_BEGIN
namespace details {
class tcp_client_unix {
SOCKET socket_ = INVALID_SOCKET;
Expand Down Expand Up @@ -206,4 +206,4 @@ class tcp_client_unix {
}
};
} // namespace details
} // namespace spdlog
SPDLOG_NAMESPACE_END
4 changes: 2 additions & 2 deletions include/spdlog/details/udp_client_unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <cstring>
#include <string>

namespace spdlog {
SPDLOG_NAMESPACE_BEGIN
namespace details {

class udp_client_unix {
Expand Down Expand Up @@ -78,4 +78,4 @@ class udp_client_unix {
}
};
} // namespace details
} // namespace spdlog
SPDLOG_NAMESPACE_END
4 changes: 2 additions & 2 deletions include/spdlog/details/udp_client_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#pragma comment(lib, "AdvApi32.lib")
#endif

namespace spdlog {
SPDLOG_NAMESPACE_BEGIN
namespace details {
class udp_client_unix {
static constexpr int TX_BUFFER_SIZE = 1024 * 10;
Expand Down Expand Up @@ -95,4 +95,4 @@ class udp_client_unix {
}
};
} // namespace details
} // namespace spdlog
SPDLOG_NAMESPACE_END
5 changes: 3 additions & 2 deletions include/spdlog/file_event_handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
#include <functional>

#include "./filename_t.h"
#include "./namespace.h"

namespace spdlog {
SPDLOG_NAMESPACE_BEGIN
struct file_event_handlers {
file_event_handlers()
Comment on lines 5 to 10
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See 1d52715

: before_open(nullptr),
Expand All @@ -17,4 +18,4 @@ struct file_event_handlers {
std::function<void(const filename_t &filename, std::FILE *file_stream)> before_close;
std::function<void(const filename_t &filename)> after_close;
};
} // namespace spdlog
SPDLOG_NAMESPACE_END
6 changes: 4 additions & 2 deletions include/spdlog/filename_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include <filesystem>

#include "./namespace.h"

#ifdef _WIN32
// In windows, add L prefix for filename literals (e.g. L"filename.txt")
#define SPDLOG_FILENAME_T_INNER(s) L##s
Expand All @@ -13,6 +15,6 @@
#define SPDLOG_FILENAME_T(s) s
#endif

namespace spdlog {
SPDLOG_NAMESPACE_BEGIN
using filename_t = std::filesystem::path;
} // namespace spdlog
SPDLOG_NAMESPACE_END
Comment on lines 16 to +20
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See 1d52715

4 changes: 2 additions & 2 deletions include/spdlog/formatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

#include "./details/log_msg.h"

namespace spdlog {
SPDLOG_NAMESPACE_BEGIN

class formatter {
public:
virtual ~formatter() = default;
virtual void format(const details::log_msg &msg, memory_buf_t &dest) = 0;
virtual std::unique_ptr<formatter> clone() const = 0;
};
} // namespace spdlog
SPDLOG_NAMESPACE_END
6 changes: 4 additions & 2 deletions include/spdlog/fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

#pragma once

namespace spdlog {
#include "./namespace.h"

SPDLOG_NAMESPACE_BEGIN
class logger;
Comment on lines 4 to 9
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See 1d52715

class formatter;
enum class level;
Expand All @@ -12,4 +14,4 @@ namespace sinks {
class sink;
}

} // namespace spdlog
SPDLOG_NAMESPACE_END
4 changes: 2 additions & 2 deletions include/spdlog/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "details/log_msg.h"
#include "sinks/sink.h"

namespace spdlog {
SPDLOG_NAMESPACE_BEGIN

class SPDLOG_API logger {
public:
Expand Down Expand Up @@ -207,4 +207,4 @@ class SPDLOG_API logger {
void flush_() noexcept;
};

} // namespace spdlog
SPDLOG_NAMESPACE_END
23 changes: 23 additions & 0 deletions include/spdlog/namespace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)

#pragma once

// SPDLOG_NS__ is the outermost namespace token used to qualify spdlog names
// in contexts outside a SPDLOG_NAMESPACE_BEGIN block (e.g. logging macros).
// Override it to rename the outer namespace.
#ifndef SPDLOG_NS__
#define SPDLOG_NS__ spdlog
#endif
// SPDLOG_NAMESPACE_BEGIN / SPDLOG_NAMESPACE_END delimit every spdlog
// declaration, defaulting to "namespace SPDLOG_NS__ { ... }".
// Override both to use a more complex namespace expression, e.g. to wrap
// symbols in an inline sub-namespace (keeps "spdlog::" accessible):
// #define SPDLOG_NAMESPACE_BEGIN namespace spdlog::inline my_copy {
// #define SPDLOG_NAMESPACE_END }
#ifndef SPDLOG_NAMESPACE_BEGIN
#define SPDLOG_NAMESPACE_BEGIN namespace SPDLOG_NS__ {
#endif
#ifndef SPDLOG_NAMESPACE_END
#define SPDLOG_NAMESPACE_END }
#endif
Loading
Loading