-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18ef06f
commit 1a37fdb
Showing
17 changed files
with
438 additions
and
379 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,30 @@ | ||
[100%] Running cpplint for Google C++ Style Guide compliance | ||
Done processing include/Auth.h | ||
Done processing include/Counseling.h | ||
Done processing include/DatabaseManager.h | ||
Done processing include/Food.h | ||
Done processing include/Healthcare.h | ||
Done processing include/Outreach.h | ||
Done processing include/RouteController.h | ||
Done processing include/Shelter.h | ||
Done processing src/Auth.cpp | ||
Done processing src/DatabaseManager.cpp | ||
Done processing src/RouteController.cpp | ||
Done processing src/SubscriptionManager.cpp | ||
Done processing src/main.cpp | ||
Done processing src/services/Counseling.cpp | ||
Done processing src/services/Food.cpp | ||
Done processing src/services/Healthcare.cpp | ||
Done processing src/services/Outreach.cpp | ||
Done processing src/services/Shelter.cpp | ||
Done processing test/AuthUnitTests.cpp | ||
Done processing test/CounselingUnitTests.cpp | ||
Done processing test/DataBaseTest.cpp | ||
Done processing test/FoodUnitTests.cpp | ||
Done processing test/HealthcareUnitTests.cpp | ||
Done processing test/IntegrationTests.cpp | ||
Done processing test/OutreachUnitTests.cpp | ||
Done processing test/RouteControllerUnitTests.cpp | ||
Done processing test/ShelterUnitTests.cpp | ||
Done processing test/SubscriptionManagerUnitTests.cpp | ||
[100%] Built target cpplint |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,84 @@ | ||
#pragma once | ||
|
||
#include <stdexcept> | ||
#include <string> | ||
#include <spdlog/spdlog.h> | ||
#include <spdlog/sinks/basic_file_sink.h> | ||
#include <memory> | ||
#include <spdlog/spdlog.h> | ||
|
||
#include <chrono> | ||
#include <iomanip> | ||
#include <filesystem> | ||
#include <iomanip> | ||
#include <memory> | ||
#include <stdexcept> | ||
#include <string> | ||
|
||
class TradingError : public std::runtime_error { | ||
public: | ||
explicit TradingError(const std::string& message) : std::runtime_error(message) {} | ||
public: | ||
explicit TradingError(const std::string& message) | ||
: std::runtime_error(message) {} | ||
}; | ||
|
||
class NetworkError : public TradingError { | ||
public: | ||
explicit NetworkError(const std::string& message) : TradingError("Network error: " + message) {} | ||
public: | ||
explicit NetworkError(const std::string& message) | ||
: TradingError("Network error: " + message) {} | ||
}; | ||
|
||
class APIError : public TradingError { | ||
public: | ||
explicit APIError(const std::string& message) : TradingError("API error: " + message) {} | ||
public: | ||
explicit APIError(const std::string& message) | ||
: TradingError("API error: " + message) {} | ||
}; | ||
|
||
class JSONParseError : public TradingError { | ||
public: | ||
explicit JSONParseError(const std::string& message) : TradingError("JSON parse error: " + message) {} | ||
public: | ||
explicit JSONParseError(const std::string& message) | ||
: TradingError("JSON parse error: " + message) {} | ||
}; | ||
|
||
class Logger { | ||
private: | ||
std::unordered_map<std::string, std::shared_ptr<spdlog::logger>> loggers; | ||
private: | ||
std::unordered_map<std::string, std::shared_ptr<spdlog::logger>> loggers; | ||
|
||
Logger() = default; // Private constructor | ||
|
||
public: | ||
Logger(const Logger&) = delete; | ||
Logger& operator=(const Logger&) = delete; | ||
Logger() = default; // Private constructor | ||
|
||
static Logger& getInstance() { | ||
static Logger instance; | ||
return instance; | ||
} | ||
public: | ||
Logger(const Logger&) = delete; | ||
Logger& operator=(const Logger&) = delete; | ||
|
||
std::shared_ptr<spdlog::logger> getLogger(const std::string& log_name) { | ||
auto it = loggers.find(log_name); | ||
if (it == loggers.end()) { | ||
std::string log_path = "logs/" + log_name + ".log"; | ||
auto logger = spdlog::basic_logger_mt(log_name, log_path, true); | ||
loggers[log_name] = logger; | ||
return logger; | ||
} | ||
return it->second; | ||
} | ||
static Logger& getInstance() { | ||
static Logger instance; | ||
return instance; | ||
} | ||
|
||
template<typename... Args> | ||
void log(const std::string& logger_name, spdlog::level::level_enum level, spdlog::format_string_t<Args...> fmt, Args&&... args) { | ||
auto logger = getLogger(logger_name); | ||
logger->log(level, fmt, std::forward<Args>(args)...); | ||
logger->flush(); | ||
std::shared_ptr<spdlog::logger> getLogger(const std::string& log_name) { | ||
auto it = loggers.find(log_name); | ||
if (it == loggers.end()) { | ||
std::string log_path = "logs/" + log_name + ".log"; | ||
auto logger = spdlog::basic_logger_mt(log_name, log_path, true); | ||
loggers[log_name] = logger; | ||
return logger; | ||
} | ||
return it->second; | ||
} | ||
|
||
void flush(const std::string& logger_name) { | ||
auto logger = getLogger(logger_name); | ||
logger->flush(); | ||
} | ||
template <typename... Args> | ||
void log(const std::string& logger_name, spdlog::level::level_enum level, | ||
spdlog::format_string_t<Args...> fmt, Args&&... args) { | ||
auto logger = getLogger(logger_name); | ||
logger->log(level, fmt, std::forward<Args>(args)...); | ||
logger->flush(); | ||
} | ||
|
||
void flush(const std::string& logger_name) { | ||
auto logger = getLogger(logger_name); | ||
logger->flush(); | ||
} | ||
}; | ||
|
||
#define LOG_INFO(logger_name, ...) Logger::getInstance().log(logger_name, spdlog::level::info, __VA_ARGS__) | ||
#define LOG_WARNING(logger_name, ...) Logger::getInstance().log(logger_name, spdlog::level::warn, __VA_ARGS__) | ||
#define LOG_ERROR(logger_name, ...) Logger::getInstance().log(logger_name, spdlog::level::err, __VA_ARGS__) | ||
#define LOG_CRITICAL(logger_name, ...) Logger::getInstance().log(logger_name, spdlog::level::critical, __VA_ARGS__) | ||
#define LOG_INFO(logger_name, ...) \ | ||
Logger::getInstance().log(logger_name, spdlog::level::info, __VA_ARGS__) | ||
#define LOG_WARNING(logger_name, ...) \ | ||
Logger::getInstance().log(logger_name, spdlog::level::warn, __VA_ARGS__) | ||
#define LOG_ERROR(logger_name, ...) \ | ||
Logger::getInstance().log(logger_name, spdlog::level::err, __VA_ARGS__) | ||
#define LOG_CRITICAL(logger_name, ...) \ | ||
Logger::getInstance().log(logger_name, spdlog::level::critical, __VA_ARGS__) |
Oops, something went wrong.