Replies: 3 comments 3 replies
-
void setupLogging() {
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs.txt", true);
file_sink->set_level(spdlog::level::info);
file_sink->set_pattern("[%Y-%m-%d %H:%M:%S] [%l] %v");
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
console_sink->set_level(spdlog::level::info);
console_sink->set_pattern("%^[%Y-%m-%d %H:%M:%S] [%l] %v%$");
auto logger = std::make_shared<spdlog::logger>("multi_sink", spdlog::sinks_init_list{file_sink, console_sink});
spdlog::register_logger(logger);
spdlog::set_default_logger(logger);
} I think I got it. Thank you. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I have another question, how do I get it to show the file, function, line number or even thread it's in? |
Beta Was this translation helpful? Give feedback.
0 replies
-
#include <spdlog/spdlog.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/sinks/basic_file_sink.h>
void setupLogging() {
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs.txt", true);
file_sink->set_level(spdlog::level::debug);
file_sink->set_pattern("[%Y-%m-%d %H:%M:%S] [%@] [%!] [%o] [%l] %v");
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
console_sink->set_level(spdlog::level::debug);
console_sink->set_pattern("%^[%Y-%m-%d %H:%M:%S] [%@] [%!] [%o] [%l] %v%$");
auto logger = std::make_shared<spdlog::logger>("multi_sink", spdlog::sinks_init_list{file_sink, console_sink});
spdlog::register_logger(logger);
spdlog::set_default_logger(logger);
}
int main() {
setupLogging();
spdlog::info("INFO");
spdlog::warn("WRAN");
spdlog::error("ERROR");
} output: [2024-10-28 13:58:59] [] [] [0] [info] INFO
[2024-10-28 13:58:59] [] [] [0] [warning] WRAN
[2024-10-28 13:58:59] [] [] [0] [error] ERROR I know you could probably use a macro like SPDLOG_LOGGER_INFO to have this information in the output file. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to know how I can easily set up the global terminal of spdlog? I wanted to have color and the terminal associated with the file, and I tried to do that, but I couldn't.
Beta Was this translation helpful? Give feedback.
All reactions