#pragma once #include #include #include #include #include namespace smartbotic::logging { enum class LogLevel { Trace = spdlog::level::trace, Debug = spdlog::level::debug, Info = spdlog::level::info, Warn = spdlog::level::warn, Error = spdlog::level::err, Critical = spdlog::level::critical, Off = spdlog::level::off }; struct LogConfig { std::string name = "smartbotic"; LogLevel level = LogLevel::Info; std::string pattern = "[%Y-%m-%d %H:%M:%S.%e] [%n] [%^%l%$] [%t] %v"; bool console = true; std::string file_path; size_t max_file_size = 10 * 1024 * 1024; // 10MB size_t max_files = 5; }; class Logger { public: static void init(const LogConfig& config); static void shutdown(); static std::shared_ptr get(const std::string& name = ""); // Convenience methods template static void trace(spdlog::format_string_t fmt, Args&&... args) { get()->trace(fmt, std::forward(args)...); } template static void debug(spdlog::format_string_t fmt, Args&&... args) { get()->debug(fmt, std::forward(args)...); } template static void info(spdlog::format_string_t fmt, Args&&... args) { get()->info(fmt, std::forward(args)...); } template static void warn(spdlog::format_string_t fmt, Args&&... args) { get()->warn(fmt, std::forward(args)...); } template static void error(spdlog::format_string_t fmt, Args&&... args) { get()->error(fmt, std::forward(args)...); } template static void critical(spdlog::format_string_t fmt, Args&&... args) { get()->critical(fmt, std::forward(args)...); } static void setLevel(LogLevel level); static void flush(); private: static std::shared_ptr defaultLogger_; static bool initialized_; }; // Scoped logger for component-specific logging class ScopedLogger { public: explicit ScopedLogger(const std::string& component); template void trace(spdlog::format_string_t fmt, Args&&... args) { logger_->trace(fmt, std::forward(args)...); } template void debug(spdlog::format_string_t fmt, Args&&... args) { logger_->debug(fmt, std::forward(args)...); } template void info(spdlog::format_string_t fmt, Args&&... args) { logger_->info(fmt, std::forward(args)...); } template void warn(spdlog::format_string_t fmt, Args&&... args) { logger_->warn(fmt, std::forward(args)...); } template void error(spdlog::format_string_t fmt, Args&&... args) { logger_->error(fmt, std::forward(args)...); } template void critical(spdlog::format_string_t fmt, Args&&... args) { logger_->critical(fmt, std::forward(args)...); } private: std::shared_ptr logger_; }; } // namespace smartbotic::logging // Convenience macros #define LOG_TRACE(...) smartbotic::logging::Logger::trace(__VA_ARGS__) #define LOG_DEBUG(...) smartbotic::logging::Logger::debug(__VA_ARGS__) #define LOG_INFO(...) smartbotic::logging::Logger::info(__VA_ARGS__) #define LOG_WARN(...) smartbotic::logging::Logger::warn(__VA_ARGS__) #define LOG_ERROR(...) smartbotic::logging::Logger::error(__VA_ARGS__) #define LOG_CRITICAL(...) smartbotic::logging::Logger::critical(__VA_ARGS__)