tracym111 / google-glog

Automatically exported from code.google.com/p/google-glog
Other
0 stars 0 forks source link

Add log messages to the same file #41

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Would be a nice feature to add all log messages in the same file 
(Optionally). This way we could easily track things in time, in the same file

Original issue reported on code.google.com by leonardoaraujo.santos on 3 Mar 2010 at 2:52

GoogleCodeExporter commented 8 years ago
I agree with that, probably one file per day

In log4j this feature is Rolling file log

Original comment by kevin....@gmail.com on 15 Mar 2010 at 4:31

GoogleCodeExporter commented 8 years ago
I think I answered the original issue (add log message into the same file) in 
Issue 
26:

INFO log file should have all log levels. Isn't it sufficient?

http://google-glog.googlecode.com/svn/trunk/doc/glog.html#severity

Note that messages of a given severity are logged not only in the logfile for 
that 
severity, but also in all logfiles of lower severity. E.g., a message of 
severity 
FATAL will be logged to the logfiles of severity FATAL, ERROR, WARNING, and 
INFO.

Original comment by shinichi...@gmail.com on 27 May 2010 at 10:26

GoogleCodeExporter commented 8 years ago
It would be nice to not be forced to have the WARNING and ERROR log files 
created for you. Some kind of env variable / command line option to enable / 
disable this feature would be good.

Having the extra WARNING and ERROR log files just creates clutter for us.

Also, it would be good to buffer INFO messages and flush them out to the one 
file periodically or as soon as a WARNING or ERROR message is processed for the 
same file. i.e. the buffering is on a per message basis and not applied to the 
whole of the INFO logger.

Original comment by rimck...@gmail.com on 28 Jun 2010 at 2:11

GoogleCodeExporter commented 8 years ago
While I agree that this would be preferable, you can arrange this under the 
current system using the public API's by calling

for (google::LogSeverity s = WARNING; s < google::NUM_SEVERITIES; s++)
   google::SetLogDestination(s, "");
google::SetLogDestination(INFO, "/path/to/file");

Then all messages will be logged to only to the file for INFO.

This is a workaround only. but if you are wrapping glog in another layer (like 
I am in my project) then it is probably sufficient.

Rotation should probably be handled externally. To make sure you reopen the 
file you will need to periodically re-call SetLogDestination(INFO, 
"/path/to/file") again so that glog will reopen the file if it has been 
displaced.

Original comment by donald.b.guy on 29 Jun 2010 at 5:41

GoogleCodeExporter commented 8 years ago
FYI, there is another way to suppress log files.

#include <glog/logging.h>

using namespace google;
using namespace std;

struct NullLogger : public base::Logger {
  virtual void Write(bool should_flush,
                     time_t timestamp,
                     const char* message,
                     int length) {
  }

  virtual void Flush() { }

  virtual uint32 LogSize() { return 0; }
};

void SetMyLogger(int severity, base::Logger* logger) {
  base::Logger* old_logger = base::GetLogger(severity);
  base::SetLogger(severity, logger);
  FlushLogFiles(severity);
}

int main(int argc, char* argv[]) {
  InitGoogleLogging(argv[0]);

  NullLogger null_logger;
  SetMyLogger(WARNING, &null_logger);
  SetMyLogger(ERROR, &null_logger);
  SetMyLogger(FATAL, &null_logger);

  LOG(INFO) << "info";
  LOG(WARNING) << "warn";
  LOG(ERROR) << "error";
  LOG(FATAL) << "fatal";
}

Original comment by shinichi...@gmail.com on 1 Jul 2010 at 6:56