C++ - 단일 헤더 크로스 플랫폼 효율적인 오픈 소스 로깅 라이브러리 Easylogging++의 구성 및 사용

1 간편한 로깅++

Easylogging++는 단일 헤더 파일만 있는 오픈 소스 크로스 플랫폼 로깅 라이브러리입니다. 간단하고 쉽게 통합할 수 있으며, 매우 빠르고, 스레드에 안전하며, 효율적이고, 구성 및 확장이 가능하다는 장점이 있습니다. 이제 이것이 저의 주요 로깅 라이브러리입니다.

1.1 Easylogging++ 다운로드

Github 주소: https://github.com/amrayn/easyloggingpp

Githu 에서 Easylogging++를 다운로드하세요. 다운로드된 파일은 두 개뿐입니다 easylogging++.h.easylogging++.cc

1.1 VS에서 Easylogging++ 구성

프로젝트-속성-C++일반-추가 포함 프로젝트를 마우스 오른쪽 버튼으로 클릭하고 easylogging++.h해당 프로젝트가 있는 디렉터리를 추가합니다.

easylogging++.cc프로젝트에 추가됩니다 .

1.2 Easylogging++ 사용하기

(1) 헤더 파일 포함

// easylogging++
#include "easylogging++.h"
#define ELPP_THREAD_SAFE

(2) Easylogging++ 초기화

INITIALIZE_EASYLOGGINGPP

(3) 로그 출력 구성 설정

static void InitEasyloggingPP()
{
    
    
	el::Configurations conf;

	// 启用日志
	conf.setGlobally(el::ConfigurationType::Enabled, "true");

	//设置日志文件目录以及文件名
	conf.setGlobally(el::ConfigurationType::Filename, "log\\log_%datetime{%Y%M%d %H%m%s}.log");

	//设置日志文件最大文件大小
	conf.setGlobally(el::ConfigurationType::MaxLogFileSize, "20971520");

	//是否写入文件
	conf.setGlobally(el::ConfigurationType::ToFile, "true");

	//是否输出控制台
	conf.setGlobally(el::ConfigurationType::ToStandardOutput, "true");

	//设置日志输出格式
	conf.setGlobally(el::ConfigurationType::Format, "[%datetime] [%loc] [%level] : %msg");

	//设置日志文件写入周期,如下每100条刷新到输出流中
	conf.setGlobally(el::ConfigurationType::LogFlushThreshold, "100");
	
	//设置配置文件
	el::Loggers::reconfigureAllLoggers(conf);
}

(4) 샘플 프로그램

// easylogging++
#include "easylogging++.h"
#define ELPP_THREAD_SAFE

INITIALIZE_EASYLOGGINGPP

static void InitEasyloggingPP()
{
    
    
	el::Configurations conf;

	// 启用日志
	conf.setGlobally(el::ConfigurationType::Enabled, "true");

	//设置日志文件目录以及文件名
	conf.setGlobally(el::ConfigurationType::Filename, "log\\log_%datetime{%Y%M%d %H%m%s}.log");

	//设置日志文件最大文件大小
	conf.setGlobally(el::ConfigurationType::MaxLogFileSize, "20971520");

	//是否写入文件
	conf.setGlobally(el::ConfigurationType::ToFile, "true");

	//是否输出控制台
	conf.setGlobally(el::ConfigurationType::ToStandardOutput, "true");

	//设置日志输出格式
	conf.setGlobally(el::ConfigurationType::Format, "[%datetime] [%loc] [%level] : %msg");

	//设置日志文件写入周期,如下每100条刷新到输出流中
	conf.setGlobally(el::ConfigurationType::LogFlushThreshold, "100");
	
	//设置配置文件
	el::Loggers::reconfigureAllLoggers(conf);
}

int main()
{
    
    
	InitEasyloggingPP();

	LOG(INFO) << "Hello World";
}

관심이 있으시면 제 개인 웹사이트인 https://www.stubbornhuang.com/ 을 방문해 주세요.

추천

출처blog.csdn.net/HW140701/article/details/127532430