I have an application that uses Glog. I can use environmental variables or Gflags to change the logging directory of this application. In this application, I link to another library that also uses Glog. The way I changed the directory of the application logging does not also change the logging directory of this linked library. Does anyone know of how to change the Glog logging directory of a linked library?
EDIT:
In my main executable for the application, I begin with:
int main( int argc, char* argv[] ) {
google::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]);
...}
An environmental variable GLOG_log_dir is set to a folder in my application directory. Immediately, I can start using things like this line from my main executable:
if(!FLAGS_localizer) {
LOG(INFO) << "Localizer not initialized. To initialize, use parameter -localizer";
}
When I go to my specified log folder, I see a file like gui.engr2-13-197-dhcp.int.colorado.edu.username.log.INFO.20160511-124903.19677
that contains all the LOG(INFO)
calls in my application. Now I have one linked library (a communication sublayer) that contains Glog calls and these calls are all correctly written to that same ..log.INFO...
file I could look at above. Since the logging is coming from different files, the log file looks like this:
I0511 12:49:03.570866 1955471360 gui.cpp:31] Localizer not initialized. To initialize, use parameter -localizer
from my main executable and like this:
I0511 12:49:08.030144 1955471360 Node.cpp:1050] Found 1 URLs for nodes
I0511 12:49:08.030184 1955471360 Node.cpp:1057] node at 10.201.13.197:5555
I0511 12:49:08.030200 1955471360 Node.cpp:1085] Connecting to 10.201.13.197:5555
I0511 12:49:08.030308 1955471360 Node.cpp:1095] 'MochaGui' connected to remote node: 10.201.13.197:5555
from my linked library that works. I have another linked library (the one causing the problem) that is linked in cmake in the same way as the working linked library, except its Glog calls are not written at all to this log file. I would expect them to look similar but have the header [IO511 <time> Localizer.cpp:<lineNo>]
, instead of the same with "Node.cpp" (Node is the working linked library). For instance, I use my (non-working) linked library to initialize a Localizer like this:
Localizer::Localizer()
{
//FLAGS_log_dir = "/Users/username/Documents/ARPGDependencies/MochaGui/logs";
//google::InitGoogleLogging("Localizer");
m_bIsStarted = false;
m_pNode = new node::node;
m_pNode->init("commander_node");
if( m_pNode->advertise("command") == false ){
LOG(ERROR) << "Error setting up publisher.";
}
LOG(INFO) << "New Localizer created.";
}
I tried to manually set the log directory for this particular object, but those lines are commented out because it did not have any effect. I know this constructor is being called because I call it in my application header file like this:
Localizer m_Localizer;
But the LOG(INFO) << "New Localizer created.";
cannot be found anywhere in the log files that are being created. So my question is, how do I get this library to output its Glog statements to the same file as the rest of the application? I've also combed the source for each linked library and found no differences in how Glog is included and used. In both, #include <glog/logging.h>
is called, and then Glog LOG(<severity>)
calls are immediately used.