Add Glog log under Arm-linux system

Source: Internet
Author: User
Tags function definition

I. Introduction of Glog
Glog is a lightweight C + + log library developed by Google that is simple to use and lightweight in the program.
The following features are primarily supported:
1 parameter setting to control logging behavior by setting flag parameters;
2 severity rating, logging based on log severity rating;
3 log information can be recorded conditionally;
4 Conditional Abort program, rich conditions to determine the macro, can be preset program termination conditions;
5 abnormal signal processing. Program abnormal situation, can customize the exception processing process;
6 Support Debug function, can only be used in debug mode;
7 custom log information;
8 thread safety logging mode;
9 system level log records;
Google perror style log information;
11 Thin Log string information.

Here's a record of how glog is used in a working project.

Second, compiling Glog
First download the Glog file: glog-0.3.3.tar.gz, unzip it tar-zxvf glog-0.3.3.tar.gz. Enter its directory to execute the following command:

$ ./configure --host=arm-arago-linux-gnueabi

The –host=arm-arago-linux-gnueabi here indicates the development of the platform, if not run on the corresponding arm, directly run "./configure" can.
Generate makefile, load execute make command. There will be a dynamic library libglog.so.0 of. So in the Glog current directory. Copy it to the target machine's/usr/lib directory.
Note: The compiler and runtime are not the same, the runtime is in the/usr/lib, when the compiler applied to the Glog program will also need to add libglog.so.0 in the compilation library. The path to the compiled library here is:/ti-sdk-am335x/linux-devkit/arm-arago-linux-gnueabi/usr/lib. Otherwise, it is not possible to compile the library when it is compiled, but cannot find the library.
In makefile, you need to add a link to the Glog keyword:-lglog.

@$$GG -fstack-check -fbounds-check -fstack-protector-all -g -o $(application_name) $(TOPOBJS) -lm -lpthread -lxml2 -lrt -lglog

Third, practical application
The above steps are completed before they can be used in the program.
Take a look at some of the initialization operations on Glog.

voidInt_glog (void){Chardefpath[ -] = {0};Charstr[ the] ="MkDir";//Get current path    intCNT = Readlink ("/proc/self/exe", Defpath,sizeof(Defpath));//delete the exe name     for(inti = CNT; I >=0; -I.) {if(Defpath[i] = ='/') {defpath[i+1] =' + '; Break; }    }//Create log folderstrcat(Defpath,"Usr/log");if(Access (Defpath, FILE_F_OK)! =0){strcat(Str,defpath);    System (STR); Usleep100000);}//log InitializationGoogle::initgooglelogging ("New"); Flags_colorlogtostderr =true;//Set the output to screen log to show the corresponding color    //flags_servitysinglelog = true;//used to differentiate log files by rankFlags_logbufsecs =0;//buffered log output, default is 30 seconds, here to output immediatelyFlags_max_log_size =1;//maximum log size is 100MBFlags_stop_logging_if_full_disk =true;//Stop log output when the disk is fully writtenGoogle::setstderrlogging (Google::glog_info);//Set the log at a level higher than google::info output to the screen at the same time    //Log name and output address    Charinfo[ -] = {0};Charwarn[ -] = {0};Charerror[ -] = {0};Charfatal[ -] = {0};strcpy(Info, Defpath);strcpy(Warn, Defpath);strcpy(Error, Defpath);strcpy(Fatal, Defpath);strcat(Info,"/info_");strcat(Warn,"/warning_");strcat(Error,"/error_");strcat(Fatal,"/fatal_");     Google::setlogdestination (Google::glog_info,info);     Google::setlogdestination (Google::glog_warning,warn);     Google::setlogdestination (Google::glog_error,error);     Google::setlogdestination (google::glog_fatal,fatal); LOG (INFO) <<"------------------------------"<<endl; LOG (INFO) <<"---------creat Log!!! ---------\ n "; LOG (INFO) <<"------------------------------"<<endl;}

The library function is called in the initialization code, and the header file in Glog-0.3.3\src\glog needs to be added to the code engineering file, otherwise the function definition cannot be found.
Running the program in this example generates the log file in the Usr/log file under the folder where the program is running. The logs are categorized according to different levels.

Add Glog log under Arm-linux system

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.