Added file and line information to logger

This commit is contained in:
Bartek Kryza
2021-04-17 17:33:03 +02:00
parent 4e644b8641
commit dd5befa89b
2 changed files with 21 additions and 1 deletions

View File

@@ -17,7 +17,10 @@
*/ */
#pragma once #pragma once
#include <spdlog/spdlog.h>
#include <algorithm> #include <algorithm>
#include <string.h>
#include <string> #include <string>
#include <vector> #include <vector>
@@ -28,6 +31,21 @@ std::string ltrim(const std::string &s);
std::string rtrim(const std::string &s); std::string rtrim(const std::string &s);
std::string trim(const std::string &s); std::string trim(const std::string &s);
#define __FILENAME__ \
(strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#define LOG_WARN(fmt__, ...) \
spdlog::warn(std::string("[{}:{}] ") + fmt__, __FILENAME__, __LINE__, \
##__VA_ARGS__)
#define LOG_INFO(fmt__, ...) \
spdlog::info(std::string("[{}:{}] ") + fmt__, __FILENAME__, __LINE__, \
##__VA_ARGS__)
#define LOG_DBG(fmt__, ...) \
spdlog::debug(std::string("[{}:{}] ") + fmt__, __FILENAME__, __LINE__, \
##__VA_ARGS__)
/** /**
* @brief Split a string using delimiter * @brief Split a string using delimiter
* *

View File

@@ -169,8 +169,10 @@ int main(int argc, char *argv[])
if (returnCode != 0) if (returnCode != 0)
return returnCode; return returnCode;
if (debug_log) if (debug_log) {
spdlog::default_logger_raw()->set_level(spdlog::level::debug); spdlog::default_logger_raw()->set_level(spdlog::level::debug);
spdlog::default_logger_raw()->set_pattern("[%l] %v");
}
return session.run(); return session.run();
} }