ObsidianDragon - DragonX ImGui Wallet
Full-node GUI wallet for DragonX cryptocurrency. Built with Dear ImGui, SDL3, and OpenGL3/DX11. Features: - Send/receive shielded and transparent transactions - Autoshield with merged transaction display - Built-in CPU mining (xmrig) - Peer management and network monitoring - Wallet encryption with PIN lock - QR code generation for receive addresses - Transaction history with pagination - Console for direct RPC commands - Cross-platform (Linux, Windows)
This commit is contained in:
91
src/util/logger.cpp
Normal file
91
src/util/logger.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
// DragonX Wallet - ImGui Edition
|
||||
// Copyright 2024-2026 The Hush Developers
|
||||
// Released under the GPLv3
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
#include <cstdarg>
|
||||
#include <ctime>
|
||||
#include <chrono>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
namespace dragonx {
|
||||
namespace util {
|
||||
|
||||
Logger::Logger() = default;
|
||||
|
||||
Logger::~Logger()
|
||||
{
|
||||
if (file_.is_open()) {
|
||||
file_.close();
|
||||
}
|
||||
}
|
||||
|
||||
Logger& Logger::instance()
|
||||
{
|
||||
static Logger logger;
|
||||
return logger;
|
||||
}
|
||||
|
||||
bool Logger::init(const std::string& path)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
if (file_.is_open()) {
|
||||
file_.close();
|
||||
}
|
||||
|
||||
file_.open(path, std::ios::out | std::ios::app);
|
||||
initialized_ = file_.is_open();
|
||||
|
||||
if (initialized_) {
|
||||
write("=== Logger initialized ===");
|
||||
}
|
||||
|
||||
return initialized_;
|
||||
}
|
||||
|
||||
void Logger::write(const std::string& message)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
// Get current timestamp
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto time = std::chrono::system_clock::to_time_t(now);
|
||||
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
now.time_since_epoch()) % 1000;
|
||||
|
||||
std::stringstream ss;
|
||||
ss << std::put_time(std::localtime(&time), "%Y-%m-%d %H:%M:%S");
|
||||
ss << '.' << std::setfill('0') << std::setw(3) << ms.count();
|
||||
ss << " | " << message;
|
||||
|
||||
std::string line = ss.str();
|
||||
|
||||
// Write to file if open
|
||||
if (file_.is_open()) {
|
||||
file_ << line << std::endl;
|
||||
file_.flush();
|
||||
}
|
||||
|
||||
// Also write to stdout in debug mode
|
||||
#ifdef DRAGONX_DEBUG
|
||||
printf("%s\n", line.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
void Logger::writef(const char* format, ...)
|
||||
{
|
||||
char buffer[4096];
|
||||
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vsnprintf(buffer, sizeof(buffer), format, args);
|
||||
va_end(args);
|
||||
|
||||
write(buffer);
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace dragonx
|
||||
Reference in New Issue
Block a user