git clone https://github.com/microsoft/vcpkg C:\vcpkg
cd vcpkg
bootstrap-vcpkg.bat
vcpkg integrate install
vcpkg install folly:x64-windows
vcpkg install folly:x64-windows --head
#include <folly/portability/Windows.h>
#include <folly/init/Init.h>
#include <folly/logging/Init.h>
#include <folly/logging/xlog.h>
#include <folly/logging/StreamHandlerFactory.h>
#include <folly/logging/FileHandlerFactory.h>
#include <print>
int main(int argc, char** argv)
{
SetConsoleOutputCP(CP_UTF8);
folly::Init init(&argc, &argv);
auto& db = folly::LoggerDB::get();
db.registerHandlerFactory(std::make_unique<folly::StreamHandlerFactory>(), true);
db.registerHandlerFactory(std::make_unique<folly::FileHandlerFactory>(), true);
try {
folly::initLogging(R"JSON(
{
"handlers": {
"hconsole": {
"type": "stream",
"options": {
"stream": "stderr",
"formatter": "glog"
}
},
"hfile": {
"type": "file",
"options": {
"path": "logs/myapp_{Y}{m}{d}_{H}{M}{S}.log",
"formatter": "glog",
"level": "INFO",
"max_file_size": 10485760,
"max_files": 30,
"buffer_size": 1048576,
"append": true,
"timestamp_precision": "millisecond"
}
}
},
"categories": {
".": {
"level": "DBG",
"handlers": [
"hconsole",
"hfile"
]
}
}
}
)JSON");
}
catch (const std::exception& ex) {
std::println(stderr, "[log-init] {}", ex.what());
return -1;
}
XLOG(INFO) << "info";
XLOGF(INFO, "formatted info={}", 1000);
XLOG(DBG) << "debug";
XLOG(WARN) << "warning";
XLOG(ERR) << "error";
return 0;
}
구성 속성 -> C/C++ ->
1. -> 전처리기 -> 전처리기 정의 -> GLOG_USE_GLOG_EXPORT
2. -> 외부 include 지시문 -> 외부 헤더 경고 수준 -> 모든 경고 해제(/external:W0)
3. -> 명령줄 - > /utf-8 추가
'Language > C++' 카테고리의 다른 글
| [poco] 로그 예제 (0) | 2025.07.22 |
|---|---|
| [C++20] std::span (0) | 2025.05.25 |
| [C++] 함수 const 선언 정리 (0) | 2024.09.12 |