A simple log system C code implementation, log c code

Source: Internet
Author: User

A simple log system C code implementation, log c code

Problem description

To implement a simple Windows-based log system, the style of the content required to be written into the log file is as follows:

[Time] + [file name] + [log level] + log Content

For example:

[2015.02.2514: 35: 13.143] [WriteLog. c] [INFO] This is a test!

"14:35:13. 143 "indicates the current time (accurate to milliseconds)," WriteLog. c "indicates the name of the printed log Content," INFO "indicates the Log Level, and" This is a test!" Is the specific log Content.

 

Algorithm flow

Figure 1 Overall procedure

 

Figure 2 General execution process of log writing

 

C code implementation


Configuration File Content

The configuration file is named Config. ini. Its content is shown in the following figure:

[LOG]

; LogLevel, 0-Fatal 1-Error 2-Warn 3-Info 4-Trace 5-Debug 6-All

LogLevel = 5

; Log dir

LogDir = D :\\ Test

 

"LogLevel" indicates the Log Level, and "LogDir" indicates the path where the log file is stored (Note: do not end with \ at the end ). You must change the values of each configuration item according to your actual needs.

 

Program description

(1) The program is directly compiled and run in VC ++.

(2) the configuration file Config. ini is directly placed in the project directory at the same level as the WriteLog. c file.

(3) You can selectively print some log information by changing the configuration value of "LogLevel.

 

Program running result

(1) set "LogLevel" to 3. The log file content is as follows:

 

(2) Set "LogLevel" to 5. The log file content is as follows:

 

It can be seen that the program can output the corresponding log information according to the configured log level.

 

 

 

(My microblogging: http://weibo.com/zhouzxi? Topnav = 1 & wvr = 5, No.: 245924426, welcome !)


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.