본문 바로가기
Programming/Libraries

C++ Library: spdlog

by 드로니뚜벅이 2022. 10. 7.

C++20 버전부터는 기본 라이브러리(std::format)로 제공하는 기능이기 때문에 최신 컴파일러에서는 필요없을 수 있으나 여전히 std::cout만을 사용하시는 이전 버전 개발자라면 아주 유용하게 사용하실 수 있는 라이브러리입니다.

표준 C에서 printf()처럼 형식지정자를 자유자재로 사용하기 싶지만 std::cout은 어딘지 모르게 사용성이 떨어지기도 하고 익숙해지질 않은 것 같습니다.

 

공개 소스를 컴파일하려면 참고사이트 URL을 참고하세요.

$ git clone https://github.com/gabime/spdlog.git
$ cd spdlog && mkdir build && cd build
$ cmake .. && make -j

 

당연하게도 컴파일을 하면 아래와 같이 헤더 파일이 없어서 오류가 발생합니다.

/home/user/work/asio-socket/http.cc:17:10: fatal error: spdlog/spdlog.h: 그런 파일이나 디렉터리가 없습니다
   17 | #include "spdlog/spdlog.h"
      |          ^~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/client.dir/build.make:76: CMakeFiles/client.dir/http_post.cc.o] 오류 1
make[1]: *** [CMakeFiles/Makefile2:80: CMakeFiles/client.dir/all] 오류 2
make: *** [Makefile:84: all] 오류 2

 

간단히 설치해 주시면 됩니다.

$ sudo apt install libspdlog-dev

 

출력되는 패턴 서식을 바꾸고 싶을 때가 있는데 이것도 아래 참고사이트에 들어가셔서 Wiki 페이지를 참고하시면 됩니다.

 

3. Custom formatting

Fast C++ logging library. Contribute to gabime/spdlog development by creating an account on GitHub.

github.com

 

참고사이트

 

'Programming > Libraries' 카테고리의 다른 글

JSON Parser - RapidJSON  (0) 2022.05.01