3

i am tryng to implement the GLOG lib in my project, but i am only getting console outputs, and i cannot allow to create the file log with the severity asociated, here is my code: i am developing for linux (ubuntu)

#include <glog/logging.h>
int main(int argc, char *argv[])
{

    google::SetLogDestination(0,"/home/ricardo/Desktop/CODIGO/info.log");
    google::SetLogDestination(google::WARNING,"");
    FLAGS_logtostderr = 1;
    google::InitGoogleLogging("log_test");
    LOG(INFO) << "Found " << 2332 << " cookies";

     return 0;

}

any help?? thx in advance!

Ricardo_arg
  • 520
  • 11
  • 28

2 Answers2

4

The line google::SetLogDestination(google::WARNING,""); looks pretty suspicious.

This line:

FLAGS_logtostderr = 1;

tells Glog to write to the console, instead of a file. For details, see the section entitled Setting Flags in Google Log's how-to document: http://google-glog.googlecode.com/svn/trunk/doc/glog.html

If you want to write to a file, delete the line containing FLAGS_logtostderr.

Also, why not use INFO instead of 0 in the first case? It would make it clearer.

NicholasM
  • 4,557
  • 1
  • 20
  • 47
4

Instead of FLAGS_logtostderr = 1; you want FLAGS_alsologtostderr=1;

This will log to both a log file and to stderr.

ferrouswheel
  • 3,658
  • 2
  • 24
  • 24