) Use the open-source C ++ logstore-log4cplus on Linux

Source: Internet
Author: User

:Log4cplus: http://sourceforge.net/projects/log4cplus/

Great Chinese documentation: (Can directly go to the family of classification list: http://www.cppblog.com/tx7do/category/1516.html) Open-source log system log4cplus (1)

Open-source log system log4cplus (2)

Open-source log system log4cplus (3)

Open-source log system log4cplus (4)

Open-source log system log4cplus (5)

Open-source log system log4cplus (6)

Open-source log system log4cplus (7)

If the above link is normal, do not read the following contentA waste of time.

1. Introduction

Log4cplus is an open-source log system written in C ++. Its predecessor is the log4j system written in Java, which is protected by Apache software license. The author is Tad E. Smith.

Log4cplus features thread security, flexibility, and multi-granularity control. It can be orientedProgramDebugging, running, testing, and maintenance. You can choose to output information to the screen, file, NT Event Log, or even remote server; regularly backs up logs by specifying a policy.
 
2. Download

The latest log4cplus can be downloaded from the following URL.
Log4cplus: Http://sourceforge.net/projects/log4cplus/

3. Install

# Tar xvzf log4cplus-1.0.4-rc10.tar.gz
# Cd log4cplus-1.0.4-rc10
#./Configure -- prefix =/usr/local
# Make
# Make install
After successful installation, you will see liblog4cplus. A under/usr/local/lib, and a liblog4cplus folder under/usr/local/include.

4. Configuration

Make sure that your makefile contains/usr/local/lib/liblog4cplus. A (static library) or-llog4cplus (dynamic library.

The header file is in the/usr/local/include/log4cplus directory.

To use a dynamic library properly, you must add the library installation path to LD_LIBRARY_PATH and log on as an administrator at/etc/lD. so. add the installation path to Conf. Here is/usr/local/lib, and then execute ldconfig to make the settings take effect.

 

5. Run the test program
Directly run the test program under the tests directory in the source code package

 

6. log4cp Lus content
1. layouts, the basic element of log4cplus, controls the format of the Output Message.
Appenders: Output location.
Logger: log object.
Priorities: priority, including trace, debug, info, warning, error, and fatal.



2. Basic Structure of log4cplus

3. Use steps: a.) to generate an appender object. B.) generate the layout object and bind it to the appender. (Optional) C.) generate a logger object. D.) set the priority of logger. (Optional) E.) Add the appender to be associated with the logger to the logger. F.) Use logger to output information, all information greater than the set priority, and display it in the corresponding layout format on all appender attached to the logger object.
4. the logger object has a hierarchical structure, which is distinguished by name, as follows:Code : Logger test = logger: getinstance ("test ");
Logger subtest = logger: getinstance ("test. subtest"); the object subtest is the sub-object of test. 5. Priority log4cplus: not_set_log_level: accept the default loglevel. If there is a parent logger, It inherits its loglevel.
All_log_level: open all log information output
Trace_log_level: Open trace information output (all_log_level)
Debug_log_level: Open debug information output
Info_log_level: Enable info output
Warn_log_level: open warning information output
Error_log_level: Open error information output
Fatal_log_level: Provides the output of fatal information.
Off_log_level: to disable all log information output, logger can set its priority through setloglevel. When the loglevel of a logger is set to not_set_log_level, the logger inherits the priority of the parent logger. In addition, if multiple logger with the same name is defined, any modifications to one of them will change the other logger at the same time. 6. layout format Output 1.) simplelayout
It is a simple format la er that adds a loglevel and a "-" before the original output information "-". 2.) ttcclayout
The format consists of time, thread ID, logger, and NDC. 3.) patternlayout is a pattern layout with lexical analysis functions, similar to regular expressions. Special predefined identifiers starting with "%" will generate special format information. (1) "%", escape as %. (2) "% C", output the logger name, such as test. subtest. You can also control the display level of the logger name. For example, "test" is output when "% c {1}", where numbers represent layers.
(3) "% d": displays the local time, for example, "18:55:45", % d displays the standard time. You can use % d {...} to define a more detailed display format. For example, % d {% H: % m: % s} indicates that the display duration is hour: minute: second. The
The predefined identifier is as follows:

% A -- indicates the day of a week, abbreviated as "fri"
% A -- indicates the day of the week, such as "Friday"
% B -- represents the number of months, abbreviated form, such as "Oct"
% B -- number of months, "October"
% C -- standard date + time format, such as "sat Oct 16 18:56:19 2004"
% D -- indicates the number of the current month (1-31) "16"
% H -- indicates the current time (0-23), for example, "18"
% I -- indicates the current time (1-12), such as "6"
% J -- indicates the Day (1-366), for example, "290"
% M -- indicates the month January (1-12), for example, "10"
% M -- indicates the minute of the current time (0-59), for example, "59"
% P -- indicates whether it is morning or afternoon, am or PM
% Q -- Millisecond (0-999) in the current time, such as "237"
% Q -- the millisecond (0-999.999) with decimal digits in the current time, for example, "430.732"
% S -- the number of seconds (0-59) of the current time, such as "32"
% U -- indicates the week of the year. It is calculated from Sunday (0-53), for example, "41"
% W -- indicates the number of weeks (0-6, 0 on Sunday), such as "6"
% W -- indicates that this week is the week of this year. It is calculated from Monday as the first day (0-53), for example, "41"
% X -- standard date format, such as "10/16/04"
% X -- standard time format, such as "19:02:34"
% Y -- two-digit year (0-99), for example, "04"
% Y -- four-digit year, for example, "2004"
% Z -- Time Zone name, such as "GMT" (4) "% F", output the name of the file where the current recorder is located, such as "Main. cpp"
(5) "% L", output the row number of the file where the current recorder is located, for example, "51"
(6) "% L", output the name and row number of the file where the current recorder is located, for example, "Main. cpp: 51"
(7) "% m", output original information.
(8) "% N", line break. (9) "% P", output loglevel, such as "debug"
(10) "% t", ID of the thread where the output recorder is located, for example, "1075298944"
(11) "% x", nested diagnostic context NDC (nested diagnostic context) output, context information is displayed from the stack, NDC can use log information of different sources (at the same time) the cross output is differentiated.
(12) format alignment. For example, "%-10 m" indicates left alignment and the width is 10. Of course, other control characters can be used in the same way, for example, "%-12D", "%-5 p", etc. 7 .) appender output location (1) console output leleappender (2) file output fileappender/rollingfileappender/dailyrollingfileappender. fileappender: implements basic file operations. The constructor is as follows: fileappender (filename, mode, immediateflush); <FILENAME> file name
<Mode> file type. Optional file types include app, ate, binary, in, out, And trunc. The default value is trunc, indicating to delete the previous file.
<Immediateflush> buffer refresh flag. rollingfileappender: rollingfileappender (filename, maxfilesize, maxbackupindex, immediateflush)
Filename: File Name
Maxfilesize: Maximum File Size
Maxbackupindex: Maximum number of recorded files
Immediateflush: the buffer refresh flag determines whether to dump based on your preset size. When this size is exceeded, the subsequent log information will be saved to the new file, in addition to defining the size of each record file, you also need to determine the maximum number of such record files (maxbackupindex + 1) required during rollingfileappender Class Object Construction ), when the number of stored files exceeds maxbackupindex + 1, the oldest generated file is deleted to ensure that the total number of files is equal to maxbackupindex + 1. Dailyrollingfileappender: dailyrollingfileappender (filename, schedule, immediateflush, maxbackupindex)

Filename: File Name
SCHEDULE: storage frequency
Immediateflush: cache refresh flag
Maxbackupindex: Maximum number of recorded files

The dailyrollingfileappender Class determines whether to dump based on your preset frequency. When the dump frequency is exceeded, the subsequent log information will be saved to the new file. The frequency package here

 

Source: http://myswirl.blog.163.com/blog/static/51318642201071644948257/

 

Add:

Log4cplus is an excellent open-source logstore Based on C/C ++. Log4cplus is thread-safe and does not need to write logs in the multi-thread state. It is flexible to use. You can set the output location at the log level through the configuration file, and dynamically set the log output level when the program is running, you can control the output of logs as you like, and control logs with multiple granularities. Information can be prioritized to support the entire life cycle of program debugging, operation, testing, and maintenance; you can choose to output information to the screen, file, NT Event Log, or even remote server. You can regularly back up logs by specifying a policy. It can meet the requirements of most developers for the log system and provides comprehensive functions.
: Http://sourceforge.net/projects/log4cplus/files/log4cplus-stable/
Tar-xjf log4cplus-1.0.4.tar.bz2 (extract), switch to the extract path
Install:./configure; Make; make install
The installation is successful. The default path is/usr/local/lib/. The header file is/usr/local/include/log4cplus.
Copy the log4cplus-related libraries under/usr/local/lib to/usr/lib and add the header files to cplus_include_path under/etc/profile.

-Llog4cplus-LRT-lpthread-LRT (or-llog4cplus-lpthread) must be added to use log4cplus for smooth compilation and use;

Reprinted from: http://blog.csdn.net/astraylinux/article/details/7258835

 

Related Article

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.