Self-written C + + Ultra-Lightweight Log class

Source: Internet
Author: User

"Self-written C + + Ultra-Lightweight log class (compatible with vc++6.0, vs2010, vs2015)"

First look at the effect:

"Test file: Test.cpp"

/*Yan Wenshan Time: 2017/07/02 Introduction: This log class powerful: 1, small cute, the whole program (YLOG.H+YLOG.CPP) but more than 100 lines, compared to other online such as log4cpp such as ultra-lightweight; 2, can output each log information log level, Output time (can be accurate to the millisecond level), the program file name, the number of rows, log information (support variable length, standard format%s,%d,%f parameters); 3, strong compatibility, in vc++6.0, VS2010, vs2015 are tested; 4, the constructor is Ylog (const int type, const int level,std::string logname= ""); Type: Defines how each log file will be output, supporting log files before each program runs append (ylog_add) or overwrite (ylog_over) Level: Definable lower levels with trace < INFO < WARNING < ERROR < FATAL < RELEASE six log levels, only if the output level of the Call log output function is higher than the defined lower level Log files in the log file, the lower limit is set to the highest release level will not produce a logfile; LogName: can define the file path of each log output, support relative path and absolute path, the folder does not exist can still create itself; The default is to generate a log file of the corresponding program name under the current folder. */#include"YLog.h"intMain () {//Create log Object log1, log output file is absolute path "d:\\y1.log", if present, append; log output lower level is info levelYlog log1 (Ylog_add, Ylog_info,"D:\\y1.log"); //CreateLog object log2, log output file is "Y2.log" relative path, overwrite if present; Log output lower level is error levelYlog log2 (Ylog_over, Ylog_error,"Y2.log"); intA = the; Doubleb =0.789; STD::stringc ="Hello"; LOG1.W (Yfl,ylog_info,"log output at info level:%d", a);//the info level is no lower than the lower LOG1 info level, and writes to the log file normallya++; LOG1.W (yfl,ylog_warning,"warning level of log output:%d", a);//Normal Writea++; LOG1.W (Yfl,ylog_error,"log output at error level:%d", a);//Normal Writea++; LOG1.W (Yfl,ylog_fatal,"fatal-level log output:%d,%f,%s", A,b,c.c_str ());//Normal WriteLOG2.W (Yfl,ylog_info,"log output at info level:%f", b);//the info level is below the lower log2 error level and does not write to the logb*=Ten; LOG2.W (yfl,ylog_warning,"warning-level log output:%f", b);//do not write to logb*=Ten; LOG2.W (Yfl,ylog_error,"log output at error level:%f", b);//Normal Writeb*=Ten; LOG2.W (Yfl,ylog_fatal,"fatal-level log output:%d,%f,%s", A,b,c.c_str ());//Normal Write    return 0;}

"Output Log 1:d:\\y1.log"

"Output Log 2:y2.log"

The log class is to save the program's running information to the log file for viewing.

This log class features powerful:

1, small cute, full program (YLOG.H+YLOG.CPP) but more than 100 lines, than the other online such as log4cpp such as ultra-lightweight;

2, can output each log information log level, output time (can be accurate to the millisecond level), the program file name, the number of rows, log information (support variable length, standard format%s,%d,%f parameters);

3, strong compatibility, in vc++6.0, vs2010, vs2015 test pass;

4. The constructor is ylog (const int type, const int level,std::string logname= "");

Type: Can define the output mode of each log file, support each time the program runs append (ylog_add) or overwrite (ylog_over) before the log file;

Level: Definable lower level with TRACE < INFO < WARNING < ERROR < FATAL < RELEASE six log levels with strict levels of rigor, Log files are written only when the output level of the Call log output function is higher than the defined lower limit level, and no log file is generated when the lower bound is set to the highest release level;

LogName: Can define the file path of each log output, support relative path and absolute path, the folder does not exist still can create itself, can omit do not write, the default in the current folder to generate the corresponding program name of the log file.

"Attached: Download link http://download.csdn.net/detail/yws_swy/9886382"

Self-written C + + Ultra-Lightweight Log class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.