Window平台编译log4cpp使用方法记录 (二)

Windows下vs2019使用log4cplus log4cplus编译 在自己的项目中,要使用日志库log4cplus,就必须先把这个日志库编译出静态库或动态库,但给日志库编译时,有几点需要注意。下面从头开始,一步一步记录。 下载 Log4cplus库的下载地址:https://sourceforge.net/projects/log4cplus/files/log4cplus-stable/ 这里日志库下载最新版本,vs也是最新版本即可 配置 (1)进入到 log4cplus-2.0.6\msvc14目录下,运行log4cplus.sln解决方案。 阅读详情

在上篇Window平台编译log4cpp使用方法记录 (一)中完成对下载的源码编译工作,接下来在工程中去应用该功能。

1.新建VS工程

将上篇文章生成的dll和lib文件拷贝到该工程目录里,并在工程项目属性中包含源代码下的include文件夹。

包含头文件:

包含头文件

链接库文件(如果未拷贝到当前工程目录,则需添加库文件目录):

附加库文件

2 演示

#include <stdio.h>
#include "log4cpp/Portability.hh"
#ifdef LOG4CPP_HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <iostream>
#include "log4cpp/Category.hh"
#include "log4cpp/Appender.hh"
#include "log4cpp/FileAppender.hh"
#include "log4cpp/OstreamAppender.hh"
#ifdef LOG4CPP_HAVE_SYSLOG
#include "log4cpp/SyslogAppender.hh"
#endif
#include "log4cpp/Layout.hh"
#include "log4cpp/PatternLayout.hh"
#include "log4cpp/BasicLayout.hh"
#include "log4cpp/Priority.hh"
#include "log4cpp/NDC.hh"
#include "log4cpp/PropertyConfigurator.hh"
#include "log4cpp/FileAppender.hh"
#include "log4cpp/RollingFileAppender.hh"

#pragma comment(lib, "ws2_32.lib")

using namespace std;

int main(int argc, char* argv[])
{

	log4cpp::OstreamAppender* osAppender = new log4cpp::OstreamAppender("osAppender", &cout);
	log4cpp::PatternLayout* pLayOut = new log4cpp::PatternLayout();
	pLayOut->setConversionPattern("%d : %p %c %x: %m%n");
	osAppender->setLayout(pLayOut);

	log4cpp::Category& root = log4cpp::Category::getRoot();
	log4cpp::Category& infoCategory = root.getInstance("infoCategory");
	infoCategory.addAppender(osAppender);
	infoCategory.setPriority(log4cpp::Priority::INFO);

	infoCategory.info("system isrunning");

	infoCategory.warn("system has awarning");

	infoCategory.error("system hasa error, can't find a file");

	infoCategory.fatal("system hasa fatal error,must be shutdown");

	infoCategory.info("systemshutdown,you can find some information in systemlog");

	log4cpp::Category::shutdown();
	return 0;
}

运行结果如下:
在这里插入图片描述

3 错误报警。

如果编译过程中出现 无法解析的外部符号 __imp__closesocket@4 之类的错误,则需再链接库文件时再引入ws2_32.lib,或者在头文件中加入该行: #pragma comment(lib, “ws2_32.lib”)

4.以上就是环境搭建的过程,要生成日志的话可以在网上看下FileAppender和RollingFileAppender的用法。

C++项目实战:Log4cpp日志库在Windows和Linux下的编译踩坑全记录(附解决方案) 本文详细记录了Log4cpp日志库在Windows和Linux下的编译过程及常见问题解决方案,特别针对VS2019和Linux环境中的典型错误提供了实用修复方法。作为C++跨平台开发的日志标杆工具,Log4cpp支持多级日志控制、线程安全和动态配置,是提升项目可维护性的关键组件。 阅读详情

相关推荐

log4cpp日志记录库(windows版本+源码)

自己编译的log4cpp日志库,windows可以使用,详细见readme.txt 自己编译的log4cpp日志库,windows可以使用,详细见readme.txt

log4cpp编译,Windows/Linux

log4cpp是开源的、跨平台的、支持多线程的日志库 Windows下编译  VS2010编译 一、下载       文件名: log4cpp-1.1.1.tar.gz       下载地址:http://sourceforge.net/projects/log4cpp/                           http://sourceforge.net/proje

kanguolaikanguolaik的专栏 6501

log4cpp安装使用大全

VS2008环境下日志工具库log4cpp整理文档,非常齐全,附带例子。

QT使用log4cpp日志库

QT使用log4cpp日志库

m0_68312479的博客 2436

log4cplus 64位 Release/Debug开发包,包含封装C++类

这是一个Log4Cplus开发包,通过源码编译而来,该包包含了64位下Debug/Release 下的lib依赖库及DLL运行库,及配置文件,还有C++封装的接口,非常好用

从PWM到正弦波:RC低通滤波器的魔法转换之旅

本文详细介绍了如何利用RC低通滤波器将STM32F103生成的PWM信号转换为高质量正弦波的技术原理与实践方法。通过分析滤波器设计、参数计算、硬件实现及Proteus仿真验证,为嵌入式开发者提供了一套完整的PWM转正弦波解决方案,适用于电机控制、音频信号生成等多种应用场景。

jupi8的博客 380

Windows下使用cmake编译log4cplus

在解压后的log4cplus根目录下新建build目录; cmd窗口下进入build目录,执行命令:cmake …/ 进行编译; 说明:cmake 后不指定编译器类型的话,默认生成的是vc的工程,如果使用其它编译器,需要在参数中指定编译器类型,如:指定使用MinGW编译器,命令为:cmake -G “MinGW Makefiles” …/。 命令执行成功后,在build目录下会生成vc工程文件,如下: 打开log4cplus解决方案文件,编译,即可生成log4cplus的库文件。

qq_43248127的博客 972

[Vue][面试]谈谈你对MVC、MVP和MVVM的理解

谈谈你对MVC、MVP和MVVM的理解 答题思路:此题涉及知识点很多,很难说清楚,说透彻,因为MVC,MVP这些我们前端程序员自己甚至都没用过。但是恰恰反映了前端这些年从无到有, 从有到优的变迁过程,因此沿此思路回答将十分清除。 Web1.0时代 在web1.0时代,并没有前端的概念。开发一个web应用多数采用ASP.NET/Java/PHP编写,项目通常由多个aspx/jsp/php文件构成,每个文件中同时包含了HTML、CSS、JavaScript、C#/Java/PHP代码, 系统整体架构可能如下图所

你好,欢迎光临! 723

C++ Log4cpp跨平台日志库使用记录(Window与Linux)

介绍log4cpp的项目用法,将在项目中常用的用法代码写下来分享!

cpp_learner的博客 8031

Qt 6.5实战:用QMediaPlayer搞定RTSP监控流播放(附LAV Filters解码器避坑指南)

本文详细介绍了如何在Qt 6.5中使用QMediaPlayer实现低延迟RTSP监控流播放,并提供了LAV Filters解码器的配置避坑指南。通过优化缓冲策略和硬件加速设置,显著提升视频流的播放性能和稳定性,适用于工业视觉检测和安防监控等实时场景。

weixin_33712987的博客 398

AD21导出gerber文件

文件–>制造输出–>Gerber Files 文件–>制造输出–>Gerber Files 通用、光圈和高级跟第一步一样 3.文件–>制造输出–>NC Drill Files 这个默认就可以了 主要参考视频来自bilibili添加链接描述 此篇博客主要是写给自己好记的,无其他商业用途 ...

新手小杨 1万+

Window平台编译log4cpp使用方法记录 (一)

1. 源码下载 先在网上下载源代码,点击:下载链接,下载后解压如下图,打开msvc10文件夹,源码是用vs2010打开,此处安装的是vs2019,打开会自动提示升级该项目,点击确定即可。 2 右击log4cpp项目选择生成,首次编译会出现一些错误,解决方法如下: 错误1:无法打开输入文件“Debug\NTEventLogCategories.res”。 解决方法:①在log4cpp项目工程中找到NTEventLogCategories.mc文件,选择该文件上然后右键选择属性,在弹出窗口中找到“配置属性–&

ASCE_Python的博客 1985

DeepSeek+Dify实战:零代码构建智能SQL生成器

本文详细介绍了如何利用DeepSeek和Dify零代码构建智能SQL生成器,帮助非技术人员通过自然语言查询数据库。文章涵盖从数据准备、知识库设计到Agent配置的全流程,并提供了优化技巧和实际应用案例,显著提升团队数据查询效率。

weixin_29311017的博客 418

C++日志框架log4cpp

C++日志框架log4cpp 使用说明详见log4cpp官网。 windows平台编译log4cpp库详见连接:https://blog.youkuaiyun.com/qq_35682844/article/details/87880923 附件中包括x64 release的库文件。 编写log4cpp.properties配置文件,如下文: #-------定义rootCategory的属性------- #指定rootCategory的log优先级是ERROR,其Appenders有两个,分别是cons

quietbxj的博客 1183

基于FPGA的PCIe核系列:FPGA root模式生成工程例子分析(1)

一、 PCIE系统架构 1.1 PCIE分层结构 PCIE结构 1.2 TLP包 四种TLP类型。 Memory (内存空间操作) IO (IO空间操作) Configuration (配置操作) Message (信息操作) 四种类型TLP,如果有需要响应,称为Non-Posted TLP,如果没有需要响应,称为Posted TLP。 TLP包类型 1.2.1 TLP结构 TLP数据格式 1.2.2 Header各个字段的含义 Header格式 ...

huangshanhu的博客 3432

零基础用AHK操作Excel:从数据读取到自动填写(附完整脚本解析)

本文为零基础用户详细介绍了如何使用AutoHotkey(AHK)通过COM接口高效操作Excel,实现从数据自动读取到填写的完整自动化流程。文章包含完整的脚本解析、环境搭建指南、核心代码逐行讲解以及实际应用案例,帮助办公人员大幅提升数据处理效率,告别重复劳动。

weixin_29202213的博客 553

Linux和Windows(VS 2019)下安装使用Log4cpp日志库

Log4cpp是个基于LGPL的开源项目,移植自Java的日志处理跟踪项目log4j,并保持了API上的一致。其类似的支持库还包括Java(log4j),C++(log4cpp、log4cplus),C(log4c),python(log4p)等。•提供了可扩展的多种日志记录方式;•提供了NDC(嵌套诊断上下文),可用于多线程、多场景的跟踪调试;•提供了完整的日志动态优先级控制,可随时调整需要记录的日志优先级;•可通过配置文件完成所有配置并动态加载;

m0_65635427的博客 2332

wireshark抓包分析TCP协议和用Fiddler抓包Https分析

wireshark抓包分析TCP协议和用Fiddler抓包Https分析 1.实验说明: 以某种游戏的客户端连接服务器、断开服务器为例,用wireshark抓包分析TCP协议的三次握手连接、四次握手断开,与计算机网络原理进行验证;用Fiddler抓包,分析验证一个HTTPS网站的TCP连接过程 2.实验过程: wireshark实验: (1)实验准备:安装《洛克王国》游戏客户端, 运行洛克王国客户端,打开内存资源管理器查看PID 根据PID查看洛克王国服务端的IP地址和端口号 并打开命令行运行以下命令: n

qq_42032327的博客 1257

VS2017编译配置和使用LOG4CPP

1.环境 (1)Windows7 64bit (2)VS2017 (3)log4cpp-1.1.3.tar.gz 2.编译 参考:http://www.jiazi.cn/blog/?id=55 解压log4cpp-1.1.3.tar.gz 得到log4cpp文件夹 该版本指供了msvc6,msvc7(2003),msvc10(2010)的编译解决方案,其它编译解决方案可以从中选择一个进行调整。...

卡木 1762

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

log4cpp

body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gray; border-width: 2px 0 2px 0;} th{border: 1p...

dfuw13072的博客 91

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

log4cplus在windows下的编译,以及配置文件的用法

上一篇文章介绍了log4cpp库在Windows系统下的编译和使用,在学习过程中发现在log4系列的库中,log4cpp相比之下比较旧,更新也少,最近一次更新也要追溯到2017年了。而同样适用于c++的log4cplus库更新则频繁得多,功能看上去也更强大,于是乎就有了改用log4cplus的想法。 本以为log4cplus就是log4cpp的兼容升级版,但实际试下来感觉区别不小。其强大的功能(如确保线程安全,动态监控配置文件设置,将日志传到远程服务器等)使得它的用法和需要注意的问题也在一定程度上复杂化.

TinyHou的博客 5218

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

【小沐学C++】C++实现日志功能:log4c(Win10+VS2017+CMake)

Log4c 是一个 C 库,用于灵活地记录到文件、系统日志和其他目标。它以 Log for Java 库 ( http://jakarta.apache.org/log4j/ ) 为模型,尽可能接近其 API。这是对 Log4j 的简短介绍,它描述了 API 和设计原理。 Mark Mendel 以不同的理念开始了一个并行的 log4c 项目。该设计是面向宏观的,更轻更快,非常适合内核开发。 Log4c 也可从 SourceForge ( http://www.sourceforge.net/proje

爱看书的小沐 4918

VS2017编译log4cpp 64bit

参考:https://blog.youkuaiyun.com/Wite_Chen/article/details/79078663 源码下载:https://sourceforge.net/projects/log4cpp/files/ 1、打开工程log4cpp\msvc10\msvc10.sln,全部升级。 2、如图打开配置增加一行HAVE_SNPRINTF。  3、修改目标编译平台 rele...

mccoy39082的博客 2206

windowss使用log4cplus源码编译成dll添加到自己项目中

下载log4cplus 最新的log4cplus可以从以下网址下载 http://sourceforge.net/pro...

weixin_43277501的博客 601

log4z 快速使用教程

#include "../log4z.h" #include #include using namespace zsummer::log4z; int main(int argc, char *argv[]) { //启动LOG4Z //没有添加任何日志记录器的情况下 LOG4Z会默认构建一个. ILog4zManager::GetInstance()

冷月宫主的专栏 4954

log4cpp性能测试

没有搜到别人的测试,这个项目已经不更新了, 自己测试一下性能: window10 + vs2017: 4个线程,每个线程10000条数据,共1.7秒 单线程40000条是1.6秒; #include <iostream> #include "Mylog.h" #include "Timer.h" #include <thread> #include <vector> #pragma comment(lib, "log4cppD.lib") using name

robinfoxnan的专栏 446
上一篇: Window平台编译log4cpp使用方法记录 (一)
下一篇: 设计模式之单例模式
照书抄代码
博客等级 码龄8年 32粉丝 50原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值