-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
9 changed files
with
115 additions
and
23 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
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
49 changes: 49 additions & 0 deletions
49
src/imview/include/imview/component/logging/app_log_handler.hpp
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,49 @@ | ||
/* | ||
* @file app_log_handler.hpp | ||
* @date 12/17/24 | ||
* @brief | ||
* | ||
* @copyright Copyright (c) 2024 Ruixiang Du (rdu) | ||
*/ | ||
|
||
#ifndef APP_LOG_HANDLER_HPP | ||
#define APP_LOG_HANDLER_HPP | ||
|
||
#include "imview/component/logging/log_processor.hpp" | ||
|
||
#include <chrono> | ||
#include <unordered_map> | ||
|
||
namespace quickviz { | ||
enum class LogLevel { kDebug, kInfo, kWarn, kError, kFatal }; | ||
|
||
class AppLogHandler { | ||
using Clock = std::chrono::steady_clock; | ||
using TimePoint = Clock::time_point; | ||
|
||
AppLogHandler() { t0_ = Clock::now(); } | ||
~AppLogHandler() = default; | ||
|
||
public: | ||
static AppLogHandler& GetInstance() { | ||
static AppLogHandler instance; | ||
return instance; | ||
} | ||
|
||
void Log(LogLevel level, const char* fmt, ...); | ||
void Draw(); | ||
|
||
private: | ||
LogProcessor processor_; | ||
TimePoint t0_; | ||
|
||
std::unordered_map<LogLevel, const char*> level_str_map_ = { | ||
{LogLevel::kDebug, "DEBUG"}, | ||
{LogLevel::kInfo, "INFO "}, | ||
{LogLevel::kWarn, "WARN "}, | ||
{LogLevel::kError, "ERROR"}, | ||
{LogLevel::kFatal, "FATAL"}}; | ||
}; | ||
} // namespace quickviz | ||
|
||
#endif // APP_LOG_HANDLER_HPP |
File renamed without changes.
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,37 @@ | ||
/* | ||
* @file app_log_handler.cpp | ||
* @date 12/17/24 | ||
* @brief | ||
* | ||
* @copyright Copyright (c) 2024 Ruixiang Du (rdu) | ||
*/ | ||
|
||
#include "imview/component/logging/app_log_handler.hpp" | ||
|
||
#include <string> | ||
#include <sstream> | ||
#include <iomanip> | ||
|
||
namespace quickviz { | ||
void AppLogHandler::Log(LogLevel level, const char* fmt, ...) { | ||
auto duration = Clock::now() - t0_; | ||
// Split into seconds and fractional nanoseconds | ||
auto seconds = | ||
std::chrono::duration_cast<std::chrono::seconds>(duration).count(); | ||
auto microseconds = | ||
std::chrono::duration_cast<std::chrono::microseconds>(duration).count() % | ||
1'000'000; | ||
|
||
// Format into string | ||
std::ostringstream timestamp; | ||
timestamp << std::setfill('0') << std::setw(10) << seconds | ||
<< "." // Fixed-width seconds | ||
<< std::setfill('0') << std::setw(6) | ||
<< microseconds; // Microseconds | ||
|
||
processor_.AddLog("[%s] [%s] %s\n", timestamp.str().c_str(), | ||
level_str_map_[level], fmt); | ||
} | ||
|
||
void AppLogHandler::Draw() { processor_.Draw("AppLog"); } | ||
} // namespace quickviz |
4 changes: 2 additions & 2 deletions
4
src/app/component/log_processor.cpp → ...w/src/component/logging/log_processor.cpp
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