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.
Reapply "Implement logger interface"
This reverts commit bb95d6d: Implement logger interface - 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 In addition to that this commit this also: - Fixes build on Windows - Changes log strategy to be lazy, so we can log strings without impact performance if logging is disabled Change-Id: If58d9c1ee7ea11390d858bd9815e6b9b11a9bee9
- Loading branch information
Showing
15 changed files
with
1,300 additions
and
14 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
54 changes: 54 additions & 0 deletions
54
...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,54 @@ | ||
/* | ||
* Copyright (C) 2020-2022 Dremio Corporation | ||
* | ||
* See "LICENSE" for license information. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <functional> | ||
#include <string> | ||
|
||
#include <spdlog/fmt/bundled/format.h> | ||
|
||
#define __LAZY_LOG(LEVEL, ...) do { \ | ||
driver::odbcabstraction::Logger *logger = driver::odbcabstraction::Logger::GetInstance(); \ | ||
if (logger) { \ | ||
logger->log(driver::odbcabstraction::LogLevel::LogLevel_##LEVEL, [&]() { \ | ||
return fmt::format(__VA_ARGS__); \ | ||
}); \ | ||
} \ | ||
} while(0) | ||
#define LOG_DEBUG(...) __LAZY_LOG(DEBUG, __VA_ARGS__) | ||
#define LOG_INFO(...) __LAZY_LOG(INFO, __VA_ARGS__) | ||
#define LOG_ERROR(...) __LAZY_LOG(ERROR, __VA_ARGS__) | ||
#define LOG_TRACE(...) __LAZY_LOG(TRACE, __VA_ARGS__) | ||
#define LOG_WARN(...) __LAZY_LOG(WARN, __VA_ARGS__) | ||
|
||
namespace driver { | ||
namespace odbcabstraction { | ||
|
||
enum LogLevel { | ||
LogLevel_TRACE, | ||
LogLevel_DEBUG, | ||
LogLevel_INFO, | ||
LogLevel_WARN, | ||
LogLevel_ERROR, | ||
LogLevel_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::function<std::string(void)> &build_message) = 0; | ||
}; | ||
|
||
} // namespace odbcabstraction | ||
} // namespace driver |
42 changes: 42 additions & 0 deletions
42
.../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,42 @@ | ||
/* | ||
* 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::function<std::string(void)> &build_message) 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
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.