forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add an interface for logger - Define Macro for each log level in the interface - Add an implementation from the logger interface - Add the spdlog dependency to the CMakeLists.txt Change-Id: Ibf1426c86e6e28903619cba328bd6998d4c4f74d
- Loading branch information
1 parent
591b83e
commit 60dd060
Showing
14 changed files
with
1,304 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...odbc/flightsql-odbc-clone/flightsql-odbc/odbcabstraction/include/odbcabstraction/logger.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (C) 2020-2022 Dremio Corporation | ||
* | ||
* See "LICENSE" for license information. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <map> | ||
#include <string> | ||
|
||
#include <boost/algorithm/string.hpp> | ||
#include <spdlog/fmt/bundled/format.h> | ||
|
||
#include <odbcabstraction/spi/connection.h> | ||
|
||
#define LOG_DEBUG(...) driver::odbcabstraction::Logger::GetInstance()->log(driver::odbcabstraction::LogLevel::DEBUG, __VA_ARGS__); | ||
#define LOG_INFO(...) driver::odbcabstraction::Logger::GetInstance()->log(driver::odbcabstraction::LogLevel::INFO, __VA_ARGS__); | ||
#define LOG_ERROR(...) driver::odbcabstraction::Logger::GetInstance()->log(driver::odbcabstraction::LogLevel::ERROR, __VA_ARGS__); | ||
#define LOG_TRACE(...) driver::odbcabstraction::Logger::GetInstance()->log(driver::odbcabstraction::LogLevel::TRACE, __VA_ARGS__); | ||
#define LOG_WARN(...) driver::odbcabstraction::Logger::GetInstance()->log(driver::odbcabstraction::LogLevel::WARN, __VA_ARGS__); | ||
|
||
namespace driver { | ||
namespace odbcabstraction { | ||
|
||
enum LogLevel { TRACE, DEBUG, INFO, WARN, ERROR, OFF }; | ||
|
||
class Logger { | ||
protected: | ||
Logger() = default; | ||
|
||
public: | ||
static Logger *GetInstance(); | ||
static void SetInstance(std::unique_ptr<Logger> logger); | ||
|
||
virtual ~Logger() = default; | ||
|
||
virtual void log(LogLevel level, const std::string &message) = 0; | ||
|
||
virtual bool checkLogLevel(LogLevel called) = 0; | ||
|
||
template <typename... Args> | ||
void log(LogLevel level, fmt::format_string<Args...> fmt, Args &&... args) { | ||
if(checkLogLevel(level)) { | ||
log(level, fmt::format(fmt, args...)); | ||
} | ||
}; | ||
}; | ||
|
||
} // namespace odbcabstraction | ||
} // namespace driver |
44 changes: 44 additions & 0 deletions
44
.../flightsql-odbc-clone/flightsql-odbc/odbcabstraction/include/odbcabstraction/spd_logger.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (C) 2020-2022 Dremio Corporation | ||
* | ||
* See "LICENSE" for license information. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "odbcabstraction/logger.h" | ||
|
||
#include <cstdint> | ||
#include <string> | ||
|
||
#include <spdlog/spdlog.h> | ||
|
||
namespace driver { | ||
namespace odbcabstraction { | ||
|
||
class SPDLogger : public Logger { | ||
protected: | ||
std::shared_ptr<spdlog::logger> logger_; | ||
|
||
public: | ||
static const std::string LOG_LEVEL; | ||
static const std::string LOG_PATH; | ||
static const std::string MAXIMUM_FILE_SIZE; | ||
static const std::string FILE_QUANTITY; | ||
static const std::string LOG_ENABLED; | ||
|
||
SPDLogger() = default; | ||
~SPDLogger(); | ||
SPDLogger(SPDLogger &other) = delete; | ||
|
||
void operator=(const SPDLogger &) = delete; | ||
void init(int64_t fileQuantity, int64_t maxFileSize, | ||
const std::string &fileNamePrefix, LogLevel level); | ||
|
||
void log(LogLevel level, const std::string &message) override; | ||
|
||
bool checkLogLevel(LogLevel called) override; | ||
}; | ||
|
||
} // namespace odbcabstraction | ||
} // namespace driver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
flightsql-odbc/flightsql-odbc/flightsql-odbc-clone/flightsql-odbc/odbcabstraction/logger.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (C) 2020-2022 Dremio Corporation | ||
* | ||
* See "LICENSE" for license information. | ||
*/ | ||
|
||
|
||
#include <odbcabstraction/logger.h> | ||
|
||
namespace driver { | ||
namespace odbcabstraction { | ||
|
||
static std::unique_ptr<Logger> odbc_logger_ = nullptr; | ||
|
||
Logger *Logger::GetInstance() { | ||
return odbc_logger_.get(); | ||
} | ||
|
||
void Logger::SetInstance(std::unique_ptr<Logger>logger) { | ||
odbc_logger_ = std::move(logger); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.