allenhoum / google-glog

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

recreate log file failed when the size of log reach max size. #138

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
1. src below,

#include <iostream>
#include <string>
#include <stdio.h>

#include "glog/logging.h"

int main(int argc, char * argv[])
{
    int nRet = 0;
    nRet = google::ParseCommandLineFlags(&argc, &argv, true);

    google::InitGoogleLogging("test");
    google::SetLogDestination(google::INFO, "./info_");
    google::SetLogSymlink(google::INFO, "");

    for(int i = 0; i < 100000; i++)
    {
        LOG(INFO) << "It is test, 12345678790";
    }

    google::ShutdownGoogleLogging();

    return 0;
}

2.set env var, when the size of log reach 1M, recreate new log file.
# export GLOG_max_log_size=1

3.run app
glog recreate new log file when the size of log file reach max size, but
create the new log file failed.

i check the code below,

void LogFileObject::Write(bool force_flush,
                          time_t timestamp,
                          const char* message,
                          int message_len)
{
...
...
      if (!CreateLogfile(time_pid_string)) {
        perror("Could not create log file");
        fprintf(stderr, "COULD NOT CREATE LOGFILE '%s'!\n", time_pid_string);
        return;
      }
}

The logfile's filename will have the date/time & pid in it. But  date/time may 
be coarsness.

Original issue reported on code.google.com by 89617...@qq.com on 26 Nov 2012 at 7:31