Log4cpp在Linux下载编译

简介: Log4cpp在Linux下载编译

下载地址:https://sourceforge.net/projects/log4cpp/files/latest/download

解压:

tar -zxvf log4cpp-1.1.4rc2.tar.gz

编译:

cd log4cpp
./configure
make
make check
sudo make install
sudo ldconfig

默认安装路径:

头文件:/usr/local/include/log4cpp
库文件:/usr/local/lib

测试范例:

//test.cpp
#include "log4cpp/Category.hh"
#include "log4cpp/FileAppender.hh"
#include "log4cpp/BasicLayout.hh"
int main()
{
    //1.实例化一个layout对象
    log4cpp::Layout *layout = new log4cpp::BasicLayout();
    //2.初始化一个appender对象
    log4cpp::Appender *appender = new log4cpp::FileAppender("FileAppender", "./log4cpp1.log");
    //3.把layout对象附在appender对象上
    appender->setLayout(layout);
    //4.实例化一个category对象
    log4cpp::Category &warn_log = log4cpp::Category::getInstance("test");
    //5.设置additivity为false,替换已有的appender
    warn_log.setAdditivity(false);
    //5.把appender对象附到category上
    warn_log.setAppender(appender);
    //6.设置category的优先级,低于此优先级的日志不被记录
    warn_log.setPriority(log4cpp::Priority::WARN);
    //记录一些日志
    warn_log.info("Program info which cannot be writen");
    warn_log.debug("This debuf message will fail to write");
    warn_log.alert("Alert info");
    //其他记录日志方式
    warn_log.log(log4cpp::Priority::WARN, "This will be a logged warning");
    log4cpp::Priority::PriorityLevel priority;
    bool this_is_critical = true;
    if (this_is_critical)
        priority = log4cpp::Priority::CRIT;
    else
        priority = log4cpp::Priority::DEBUG;
    warn_log.log(priority, "Importance depends on context");
    warn_log.critStream() << "This will show up << as "
                            << 1 << " critical message";
    //clean up and flush all appenders
    log4cpp::Category::shutdown();
    return 0;
}

编译:

g++ -o test test.cpp -llog4cpp -lpthread
相关文章
|
5天前
|
Linux 开发工具 C语言
Linux 安装 gcc 编译运行 C程序
Linux 安装 gcc 编译运行 C程序
24 0
|
26天前
|
Linux Shell
Linux手动清理Linux脚本日志定时清理日志和log文件执行表达式
Linux手动清理Linux脚本日志定时清理日志和log文件执行表达式
79 1
|
2月前
|
Ubuntu Linux 编译器
Linux应用开发基础知识——交叉编译与gcc编译(一)
Linux应用开发基础知识——交叉编译与gcc编译(一)
65 0
Linux应用开发基础知识——交叉编译与gcc编译(一)
|
1月前
|
Shell Linux C语言
【Shell 命令集合 网络通讯 】Linux 查看系统中的UUCP日志文件 uulog命令 使用指南
【Shell 命令集合 网络通讯 】Linux 查看系统中的UUCP日志文件 uulog命令 使用指南
29 0
|
1月前
|
监控 Shell Linux
【Shell 命令集合 系统管理 】Linux 自动轮转(log rotation)日志文件 logrotate命令 使用指南
【Shell 命令集合 系统管理 】Linux 自动轮转(log rotation)日志文件 logrotate命令 使用指南
51 0
|
4天前
|
Linux 开发工具 Android开发
Docker系列(1)安装Linux系统编译Android源码
Docker系列(1)安装Linux系统编译Android源码
7 0
|
12天前
|
SQL 监控 安全
Linux&Windows 日志分析 陇剑杯 CTF
Linux&Windows 日志分析 陇剑杯 CTF
|
23天前
|
关系型数据库 MySQL Linux
linux特定服务日志
Linux系统的服务日志在`/var/log`目录下,如系统日志(`/var/log/syslog`或`/var/log/messages`)、认证日志(`/var/log/auth.log`)、SSH日志(`/var/log/auth.log`或`/var/log/secure`)。Web服务器(Apache和Nginx)的访问和错误日志、MySQL错误日志、Postfix及Dovecot邮件服务器日志也在此处。日志位置可能因发行版和服务配置而异,不确定时可查服务配置或用`grep`搜索。使用`logrotate`可管理日志文件大小。
22 6
|
27天前
|
运维 监控 安全
linux日志分析与追踪
在Linux中,日志分析涉及检查 `/var/log` 下的不同文件,如`messages`、`auth.log`、`kern.log`等,以及Web服务器和数据库日志。使用`tail`、`grep`、`awk`等工具实时查看和搜索日志,`logrotate`管理日志大小,`journalctl`处理Systemd日志,而`Splunk`等工具则用于集中式分析。分析技巧包括异常检测、时间关联和阈值监控。安全事件追踪结合登录失败日志、网络嗅探和IDS/IPS。日志链路追踪在分布式系统中尤为重要,帮助定位服务调用问题。有效的日志管理和分析能增强系统安全和故障排除能力。
23 7
|
1月前
|
Linux 开发工具 C语言
【研究Qt webengine 模块编译】linux 交叉编译qt5.12的webengine模块成功的条件
【研究Qt webengine 模块编译】linux 交叉编译qt5.12的webengine模块成功的条件
62 1