Liunx怎么安装spdlog(这是用来管理日志部分)

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 1个月
简介: Liunx怎么安装spdlog(这是用来管理日志部分)

怎么下载安装包,请参见如何从github上下载对应安装包。(其实就是从GitHub上spdlog 的仓库下载就好)

这里介绍怎样安装spdlog这个日志管理使用的库。

  1. 首先将源码包解压到自己的目录下。
[zry@localhost package]$ ls
date-master  git-2.34.1  ormpp-master  Python-3.8.0  spdlog-1.x  sqlpp11-main


  1. 进入到spdlog解压文件夹内
[zry@localhost package]$ cd spdlog-1.x/
[zry@localhost spdlog-1.x]$ ls
appveyor.yml  bench  build  cmake  CMakeLists.txt  example  include  INSTALL  LICENSE  logos  README.md  scripts  src  tests 
  1. 创建build 目录,用来存放cmake编译 相关内容
[zry@localhost spdlog-1.x]$ mkdir build
  1. 进入到build目录内
[zry@localhost spdlog-1.x]$ cd build/
  1. 进行cmake 编译,命令cmake ..
[zry@localhost build]$ cmake ..
-- The CXX compiler identification is GNU 8.3.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /opt/rh/devtoolset-8/root/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Build spdlog: 1.12.0
-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Build type: Release
-- Generating example(s)
-- Generating install
-- Configuring done
-- Generating done
-- Build files have been written to: /home/zry/package/spdlog-1.x/build


  1. 进行编译 命令make -j
[zry@localhost build]$ make -j
[ 10%] Building CXX object CMakeFiles/spdlog.dir/src/spdlog.cpp.o
[ 20%] Building CXX object CMakeFiles/spdlog.dir/src/stdout_sinks.cpp.o
[ 30%] Building CXX object CMakeFiles/spdlog.dir/src/color_sinks.cpp.o
[ 40%] Building CXX object CMakeFiles/spdlog.dir/src/file_sinks.cpp.o
[ 50%] Building CXX object CMakeFiles/spdlog.dir/src/async.cpp.o
[ 60%] Building CXX object CMakeFiles/spdlog.dir/src/cfg.cpp.o
[ 70%] Building CXX object CMakeFiles/spdlog.dir/src/bundled_fmtlib_format.cpp.o
[ 80%] Linking CXX static library libspdlog.a
[ 80%] Built target spdlog
[ 90%] Building CXX object example/CMakeFiles/example.dir/example.cpp.o
[100%] Linking CXX executable example
[100%] Built target example
  1. 编译完成之后可以进行测试 在 build 目录下会有一个example文件夹,进入后执行./example可以看到测试结果。
[zry@localhost build]$ ls
CMakeCache.txt  cmake_install.cmake  CPackSourceConfig.cmake  libspdlog.a  spdlogConfig.cmake         spdlogConfigVersion.cmake
CMakeFiles      CPackConfig.cmake    example                  Makefile     spdlogConfigTargets.cmake  spdlog.pc
[zry@localhost build]$ cd example/
[zry@localhost example]$ ls
CMakeFiles  cmake_install.cmake  example  Makefile
[zry@localhost example]$ ./example 
[2024-02-26 17:46:12.223] [info] Welcome to spdlog version 1.12.0  !
[2024-02-26 17:46:12.224] [warning] Easy padding in numbers like 00000012
[2024-02-26 17:46:12.224] [critical] Support for int: 42;  hex: 2a;  oct: 52; bin: 101010
[2024-02-26 17:46:12.224] [info] Support for floats 1.23
[2024-02-26 17:46:12.224] [info] Positional args are supported too..
[2024-02-26 17:46:12.224] [info]    right aligned, left     aligned
[2024-02-26 17:46:12.224] [debug] This message should be displayed..
[17:46:12 +08:00] [I] [thread 16553] This an info message with custom format
[2024-02-26 17:46:12.224] [info] ****************** Backtrace Start ******************
[2024-02-26 17:46:12.224] [debug] Backtrace message 90
[2024-02-26 17:46:12.224] [debug] Backtrace message 91
[2024-02-26 17:46:12.224] [debug] Backtrace message 92
[2024-02-26 17:46:12.224] [debug] Backtrace message 93
[2024-02-26 17:46:12.224] [debug] Backtrace message 94
[2024-02-26 17:46:12.224] [debug] Backtrace message 95
[2024-02-26 17:46:12.224] [debug] Backtrace message 96
[2024-02-26 17:46:12.224] [debug] Backtrace message 97
[2024-02-26 17:46:12.224] [debug] Backtrace message 98
[2024-02-26 17:46:12.224] [debug] Backtrace message 99
[2024-02-26 17:46:12.224] [info] ****************** Backtrace End ********************
[2024-02-26 17:46:12.226] [info] Binary example: 
0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
0060: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f
0080: 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f
[2024-02-26 17:46:12.226] [info] Another binary example:00 00 00 00 00 00 00 00 00 00
[2024-02-26 17:46:12.226] [info] Vector example: [1, 2, 3]
[multi_sink_example] [warning] this should appear in both console and file
[2024-02-26 17:46:12.226] [info] user defined type: [my_type i=14]
[2024-02-26 17:46:12.350] [info] Stopwatch: 0.123150527 seconds
[2024-02-26 17:46:12.350] [info] Before opening logs/events-sample.txt
[2024-02-26 17:46:12.350] [info] After opening logs/events-sample.txt
[2024-02-26 17:46:12.350] [info] Before closing logs/events-sample.txt
[2024-02-26 17:46:12.350] [info] After closing logs/events-sample.txt
[2024-02-26 17:46:12.350] [info] End of example.
[2024-02-26 17:46:12.350] [console] [info] End of example.
[zry@localhost example]$ ll -lrt 
总用量 580
-rw-rw-r--. 1 zry zry   8745 2月  26 17:44 Makefile
-rw-rw-r--. 1 zry zry   1282 2月  26 17:44 cmake_install.cmake
drwxrwxr-x. 3 zry zry   4096 2月  26 17:44 CMakeFiles
-rwxrwxr-x. 1 zry zry 567664 2月  26 17:44 example
drwxr-xr-x. 2 zry zry   4096 2月  26 17:46 logs
[zry@localhost example]$ 

分享一个有趣的 学习链接:https://xxetb.xet.tech/s/HY8za


相关实践学习
日志服务之数据清洗与入湖
本教程介绍如何使用日志服务接入NGINX模拟数据,通过数据加工对数据进行清洗并归档至OSS中进行存储。
目录
相关文章
|
2月前
|
关系型数据库 MySQL Java
ChaosBlade常见问题之安装日志中一直报错某个数据库表不存在如何解决
ChaosBlade 是一个开源的混沌工程实验工具,旨在通过模拟各种常见的硬件、软件、网络、应用等故障,帮助开发者在测试环境中验证系统的容错和自动恢复能力。以下是关于ChaosBlade的一些常见问题合集:
|
15天前
spdlog 日志库部分源码说明——让你可以自定义的指定自动切换日志时间
spdlog 日志库部分源码说明——让你可以自定义的指定自动切换日志时间
24 7
|
15天前
|
C++
spdlog 日志库部分源码说明——日志格式设定,DIY你自己喜欢的调试信息,你能调试的远比你想象的还要丰富
spdlog 日志库部分源码说明——日志格式设定,DIY你自己喜欢的调试信息,你能调试的远比你想象的还要丰富
38 6
|
10天前
|
监控 网络协议 Linux
技术好文共享::Linux系统日志管理日志转储
技术好文共享::Linux系统日志管理日志转储
12 0
|
2月前
|
C++
C++11日志之spdlog
C++11日志之spdlog
43 1
|
2月前
|
C++
c++日志工具spdLog
c++日志工具spdLog
20 1
|
2月前
|
算法 Java 测试技术
【深入探究 C++ 日志库性能比较】glog、log4cplus 和 spdlog 的日志输出性能分析
【深入探究 C++ 日志库性能比较】glog、log4cplus 和 spdlog 的日志输出性能分析
546 0
|
2月前
|
XML 运维 监控
【深入探究 C++ 日志库清理策略】glog、log4cplus 和 spdlog 的日志文件管理策略
【深入探究 C++ 日志库清理策略】glog、log4cplus 和 spdlog 的日志文件管理策略
213 0
|
10天前
|
存储 关系型数据库 MySQL
|
3天前
|
Java 测试技术 Apache
《手把手教你》系列基础篇(八十六)-java+ selenium自动化测试-框架设计基础-Log4j实现日志输出(详解教程)
【7月更文挑战第4天】Apache Log4j 是一个广泛使用的 Java 日志框架,它允许开发者控制日志信息的输出目的地、格式和级别。Log4j 包含三个主要组件:Loggers(记录器)负责生成日志信息,Appenders(输出源)确定日志输出的位置(如控制台、文件、数据库等),而 Layouts(布局)则控制日志信息的格式。通过配置 Log4j,可以灵活地定制日志记录行为。
18 4