// Source code
#include "spdlog/spdlog.h"
#pragma comment(lib, "libspdlog_MD_2019_x86D_v1.10.0.lib")
int main()
{
spdlog::info("Hello World!");
spdlog::info("Age : {}", 42);
spdlog::info("Between {1} and {0}", "Z", 0);
spdlog::info("Notation Formatting int: {0:d}, hex: {0:x}, oct: {0:o}, bin: {0:b}", 42);
spdlog::info("Padding 1 : {:8d}", 5);
spdlog::info("Padding 2 : {:08x}", 5);
spdlog::info("Floating 1 : {:08.1f}", 1.23456);
spdlog::info("Floating 2 : {:08.2f}", 1.23456);
spdlog::info("Floating 3 : {:8.1f}", 1.23456);
spdlog::info("Floating 4 : {:8.2f}", 1.23456);
return 0;
}
[2022-07-16 17:21:13.351] [info] Hello World!
[2022-07-16 17:21:13.355] [info] Age : 42
[2022-07-16 17:21:13.355] [info] Between 0 and Z
[2022-07-16 17:21:13.356] [info] Notation Formatting int: 42, hex: 2a, oct: 52, bin: 101010
[2022-07-16 17:21:13.356] [info] Padding 1 : 5
[2022-07-16 17:21:13.356] [info] Padding 2 : 00000005
[2022-07-16 17:21:13.357] [info] Floating 1 : 000001.2
[2022-07-16 17:21:13.357] [info] Floating 2 : 00001.23
[2022-07-16 17:21:13.357] [info] Floating 3 : 1.2
[2022-07-16 17:21:13.357] [info] Floating 4 : 1.23
spdlog는 open source formatting library인 fmt를 사용하고 있습니다.
formating 관련한 자세한 부분은 fmt 라이브러리를 참고하시면 됩니다.
spdlog::set_level 함수를 통해서 로그 레벨을 설정할 수 있으며, 설정한 로그 레벨을 포함하여 순위가 높은 로그 레벨만 출력합니다.
spdlog::set_level(spdlog::level::err);
#include "spdlog/spdlog.h"
#pragma comment(lib, "libspdlog_MD_2019_x86D_v1.10.0.lib")
int main()
{
spdlog::trace("Trace Level");
spdlog::debug("Debug Level");
spdlog::info("Info Level");
spdlog::warn("Warn Level");
spdlog::error("Error Level");
spdlog::critical("Critical Level");
return 0;
}
#include "spdlog/spdlog.h"
#include "spdlog/sinks/basic_file_sink.h"
#pragma comment(lib, "libspdlog_MD_2019_x86D_v1.10.0.lib")
int main()
{
auto logger = spdlog::basic_logger_mt("basic_logger", "logs/basic.txt");
spdlog::set_default_logger(logger);
spdlog::trace("Trace Level");
spdlog::debug("Debug Level");
spdlog::info("Info Level");
spdlog::warn("Warn Level");
spdlog::error("Error Level");
spdlog::critical("Critical Level");
return 0;
}
출처 :
- https://whalec.io/open-source/spdlog-%eb%a1%9c%ea%b7%b8%eb%a5%bc-%eb%82%a8%ea%b2%a8%eb%b3%b4%ec%9e%90-1-%ec%86%8c%ec%8a%a4-%eb%b9%8c%eb%93%9c%ed%95%98%ea%b8%b0/
- https://whalec.io/open-source/spdlog-%EB%A1%9C%EA%B7%B8%EB%A5%BC-%EB%82%A8%EA%B2%A8%EB%B3%B4%EC%9E%90-3-%EC%82%AC%EC%9A%A9%EB%B2%95-%EC%95%8C%EC%95%84%EB%B3%B4%EA%B8%B0/