how to initialize the logger from a shared library

811 views
Skip to first unread message

Jun Li

unread,
Jul 6, 2015, 4:00:03 AM7/6/15
to googl...@googlegroups.com
Hello,

I am using the google logger in the development of my C++ application library in a Linux environment.  When I write test code to test the application library, I can simply invoke the initialization routine right at the beginning of the "main" function:

  FLAGS_log_dir ="/tmp/applicationlog";
  google::InitGoogleLogging(argv[0]);



After I turned the C++ application library into a shared library and then it gets called from Java, the first thing that I did is to have the following function:

static void init_google_logger() {
                                                                                                                      
  FLAGS_log_dir ="/tmp/applicationlog";                                                          
  FLAGS_v = 2;                                                                                      
  google::InitGoogleLogging(NULL);
}

before  any of the LOG() function supported by glog logger,  for example I put :

       init_google_logger();
    
in the initialization function of one of the application classes.


However,  the following message displayed at the console.

WARNING: Logging before InitGoogleLogging() is written to STDERR


ALL of the log functions produce logs correctly, except that  I can not re-direct the log messages to a particular log directory that  I want. 

I did try to use "export" environment variables, for example:

export GLOG_v=1
export GLOG_logtostderr=0
export GLOG_log_dir=/tmp/applicationlog


I found that I can control "verbose logging" correctly via such an environment export, but the log directory re-direction still does not work.


So I like to know how InitGoogleLogging() should be called in a shared library (this shared library will get called by Java), so that I can have a correct log directory re-direction in a runtime environment?


Regards,

Jun





Reply all
Reply to author
Forward
0 new messages