Open GoogleCodeExporter opened 8 years ago
We don't support the feature. You may need to remove log files periodically.
Original comment by shinichi...@gmail.com
on 1 Jul 2010 at 2:18
For the record, glog does reopen the same log file in append mode. The problem
is that the date-time-pid string will be different for each execution of the
cgi process.
If you patch the portion of logging.cc that creates the file (I believe it is
in Write() ) to not add that portion... it may work. Though there may be some
race conditions if the cgi process gets started multiple times at once.
But I am no one important ... as shinichiro.hamaji (who is someone important)
says, it is not officially supported.
Original comment by donald.b.guy
on 1 Jul 2010 at 5:54
FYI, if you are happy to write file management works by your self, you may be
able to use SetLogger like following code.
#include <stdio.h>
#include <sys/file.h>
#include <string>
#include <glog/logging.h>
using namespace google;
using namespace std;
struct MyLogger : public base::Logger {
virtual void Write(bool should_flush,
time_t timestamp,
const char* message,
int length) {
FILE* fp = fopen("/tmp/out", "a");
flock(fileno(fp), LOCK_EX);
fprintf(fp, "%.*s", length, message);
fclose(fp);
}
virtual void Flush() { }
virtual uint32 LogSize() { return 0; }
};
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]);
MyLogger my_logger;
NullLogger null_logger;
SetMyLogger(INFO, &my_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:38
Original issue reported on code.google.com by
owandyw...@gmail.com
on 1 Jul 2010 at 8:26