mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-07 22:02:12 +08:00
logger: use fmt for gnutls, pjsip logging
Change-Id: Ic282ac90339ecff26b8b195626059d2bf4f02d28
This commit is contained in:

committed by
Adrien Beraud

parent
98cbdd359f
commit
33f4269115
@ -585,10 +585,10 @@ Logger::vlog(int level, const char* file, int line, bool linefeed, const char* f
|
||||
}
|
||||
|
||||
void
|
||||
Logger::write(int level, const char* file, int line, std::string&& message)
|
||||
Logger::write(int level, const char* file, int line, bool linefeed, std::string&& message)
|
||||
{
|
||||
/* Timestamp is generated here. */
|
||||
Msg msg(level, file, line, true, std::move(message));
|
||||
Msg msg(level, file, line, linefeed, std::move(message));
|
||||
|
||||
log_to_if_enabled(ConsoleLog::instance(), msg);
|
||||
log_to_if_enabled(SysLog::instance(), msg);
|
||||
|
42
src/logger.h
42
src/logger.h
@ -22,12 +22,14 @@
|
||||
#include <fmt/core.h>
|
||||
#include <fmt/format.h>
|
||||
#include <fmt/chrono.h>
|
||||
#include <fmt/compile.h>
|
||||
#include <fmt/printf.h>
|
||||
#if __has_include(<fmt/std.h>)
|
||||
#include <fmt/std.h>
|
||||
#else
|
||||
#include <fmt/ostream.h>
|
||||
#endif
|
||||
|
||||
#include <opendht/logger.h>
|
||||
#include <cinttypes> // for PRIx64
|
||||
#include <cstdarg>
|
||||
@ -117,10 +119,10 @@ public:
|
||||
}
|
||||
|
||||
LIBJAMI_PUBLIC
|
||||
static void write(int level, const char* file, int line, std::string&& message);
|
||||
static void write(int level, const char* file, int line, bool linefeed, std::string&& message);
|
||||
|
||||
static inline void writeDht(dht::log::LogLevel level, std::string&& message) {
|
||||
write(dhtLevel(level), nullptr, 0, std::move(message));
|
||||
write(dhtLevel(level), nullptr, 0, true, std::move(message));
|
||||
}
|
||||
static inline std::shared_ptr<dht::log::Logger> dhtLogger() {
|
||||
return std::make_shared<dht::Logger>(&Logger::writeDht);
|
||||
@ -175,22 +177,36 @@ namespace log {
|
||||
|
||||
template<typename S, typename... Args>
|
||||
void info(const char* file, int line, S&& format, Args&&... args) {
|
||||
Logger::write(LOG_INFO, file, line, fmt::format(std::forward<S>(format), std::forward<Args>(args)...));
|
||||
Logger::write(LOG_INFO, file, line, true, fmt::format(std::forward<S>(format), std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template<typename S, typename... Args>
|
||||
void dbg(const char* file, int line, S&& format, Args&&... args) {
|
||||
Logger::write(LOG_DEBUG, file, line, fmt::format(std::forward<S>(format), std::forward<Args>(args)...));
|
||||
Logger::write(LOG_DEBUG, file, line, true, fmt::format(std::forward<S>(format), std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template<typename S, typename... Args>
|
||||
void warn(const char* file, int line, S&& format, Args&&... args) {
|
||||
Logger::write(LOG_WARNING, file, line, fmt::format(std::forward<S>(format), std::forward<Args>(args)...));
|
||||
Logger::write(LOG_WARNING, file, line, true, fmt::format(std::forward<S>(format), std::forward<Args>(args)...));
|
||||
}
|
||||
template<typename S, typename... Args>
|
||||
void error(const char* file, int line, S&& format, Args&&... args) {
|
||||
Logger::write(LOG_ERR, file, line, true, fmt::format(std::forward<S>(format), std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template<typename S, typename... Args>
|
||||
void error(const char* file, int line, S&& format, Args&&... args) {
|
||||
Logger::write(LOG_ERR, file, line, fmt::format(std::forward<S>(format), std::forward<Args>(args)...));
|
||||
void xinfo(const char* file, int line, S&& format, Args&&... args) {
|
||||
Logger::write(LOG_INFO, file, line, false, fmt::format(std::forward<S>(format), std::forward<Args>(args)...));
|
||||
}
|
||||
template<typename S, typename... Args>
|
||||
void xdbg(const char* file, int line, S&& format, Args&&... args) {
|
||||
Logger::write(LOG_DEBUG, file, line, false, fmt::format(std::forward<S>(format), std::forward<Args>(args)...));
|
||||
}
|
||||
template<typename S, typename... Args>
|
||||
void xwarn(const char* file, int line, S&& format, Args&&... args) {
|
||||
Logger::write(LOG_WARNING, file, line, false, fmt::format(std::forward<S>(format), std::forward<Args>(args)...));
|
||||
}
|
||||
template<typename S, typename... Args>
|
||||
void xerror(const char* file, int line, S&& format, Args&&... args) {
|
||||
Logger::write(LOG_ERR, file, line, false, fmt::format(std::forward<S>(format), std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
}
|
||||
@ -201,10 +217,10 @@ void error(const char* file, int line, S&& format, Args&&... args) {
|
||||
#define JAMI_WARN(...) ::jami::Logger::log(LOG_WARNING, __FILE__, __LINE__, true, ##__VA_ARGS__)
|
||||
#define JAMI_ERR(...) ::jami::Logger::log(LOG_ERR, __FILE__, __LINE__, true, ##__VA_ARGS__)
|
||||
|
||||
#define JAMI_XINFO(...) ::jami::Logger::log(LOG_INFO, __FILE__, __LINE__, false, ##__VA_ARGS__)
|
||||
#define JAMI_XDBG(...) ::jami::Logger::log(LOG_DEBUG, __FILE__, __LINE__, false, ##__VA_ARGS__)
|
||||
#define JAMI_XWARN(...) ::jami::Logger::log(LOG_WARNING, __FILE__, __LINE__, false, ##__VA_ARGS__)
|
||||
#define JAMI_XERR(...) ::jami::Logger::log(LOG_ERR, __FILE__, __LINE__, false, ##__VA_ARGS__)
|
||||
#define JAMI_XINFO(formatstr, ...) ::jami::log::xinfo(__FILE__, __LINE__, FMT_COMPILE(formatstr), ##__VA_ARGS__)
|
||||
#define JAMI_XDBG(formatstr, ...) ::jami::log::xdbg(__FILE__, __LINE__, FMT_COMPILE(formatstr), ##__VA_ARGS__)
|
||||
#define JAMI_XWARN(formatstr, ...) ::jami::log::xwarn(__FILE__, __LINE__, FMT_COMPILE(formatstr), ##__VA_ARGS__)
|
||||
#define JAMI_XERR(formatstr, ...) ::jami::log::xerror(__FILE__, __LINE__, FMT_COMPILE(formatstr), ##__VA_ARGS__)
|
||||
|
||||
#define JAMI_LOG(formatstr, ...) ::jami::log::info(__FILE__, __LINE__, FMT_STRING(formatstr), ##__VA_ARGS__)
|
||||
#define JAMI_DEBUG(formatstr, ...) if(::jami::Logger::debugEnabled()) { ::jami::log::dbg(__FILE__, __LINE__, FMT_STRING(formatstr), ##__VA_ARGS__); }
|
||||
|
@ -223,11 +223,11 @@ setSipLogLevel()
|
||||
pj_log_set_log_func([](int level, const char* data, int len) {
|
||||
auto msg = std::string_view(data, len);
|
||||
if (level < 2)
|
||||
JAMI_ERROR("{}", msg);
|
||||
JAMI_XERR("{}", msg);
|
||||
else if (level < 4)
|
||||
JAMI_WARNING("{}", msg);
|
||||
JAMI_XWARN("{}", msg);
|
||||
else
|
||||
JAMI_LOG("{}", msg);
|
||||
JAMI_XDBG("{}", msg);
|
||||
});
|
||||
}
|
||||
|
||||
@ -247,7 +247,7 @@ setGnuTlsLogLevel()
|
||||
|
||||
gnutls_global_set_log_level(level);
|
||||
gnutls_global_set_log_function([](int level, const char* msg) {
|
||||
JAMI_XDBG("[%d]GnuTLS: %s", level, msg);
|
||||
JAMI_XDBG("[{:d}]GnuTLS: {:s}", level, msg);
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user