#1139·glog

Log line format string in the log header displays threadid even if it wasn't selected to display in custom formatter

Author: alexkushnirCreated Nov 7, 2024Updated Nov 7, 2024

Use the following snippet:

void custom_formatter(std::ostream& s, const google::LogMessage& m, void* data)
{
    s << google::GetLogSeverityName(m.severity())[0]
        << "["
        << std::setw(2) << m.time().hour() << ':'
        << std::setw(2) << m.time().min()  << ':'
        << std::setw(2) << m.time().sec() << "."
        << ' '
        << std::setfill(' ') << std::setw(5)
        << ' '
        << m.basename() << ':' << m.line() << "]";
}
int main(int argc, char** argv)
{
    google::InitGoogleLogging(argv[0]); 
    google::InstallPrefixFormatter(&custom_formatter);
    auto num_cookies = 15;
    LOG(INFO) << "Found " << num_cookies << " cookies"; 
    return 0;
}

Gives the following output:

Log file created at: 2024/11/07 16:12:06
Running on machine: AAAAAAAAAAA
Running duration (h:mm:ss): 0:00:00
Log line format: [IWEF]yyyymmdd hh:mm:ss.uuuuuu threadid file:line] msg
I[16:12:06.      glog_functions.cpp:72] Found 15 cookies

I would expect the threadid would not appear in the log line format