Skip to content

Date format is blank on Windows 11 #3

@roboticforest

Description

@roboticforest

The variable timeStr seems to be empty under Windows 11 builds, causing the output to be in nanoseconds only, which completely breaks sorting the log file output.

I'm told that %F and %T were Linux specific extensions. Reverting back to %Y-%m-%d %H:%M:%S (or upgrading to C++20 and using std::format) should provide a cross-platform solution.

logger/logger.cpp

Lines 94 to 107 in 981bcd0

// Format the time as human readable.
// "%F %T" --> "%Y-%m-%d %H:%M:%S" --> "TZONE 2019-08-23 13:42:58\0" (26 chars)
char timeStr[26] = {0};
std::time_t curTimeSecondPrecision = curTimeNanosecondPrecision/1000000000; // Deliberate integer rounding.
std::strftime(timeStr, sizeof(timeStr), "%Z %F %T", std::localtime(&curTimeSecondPrecision));
// Finally, print the time stamp.
_buffer << '['
<< timeStr
<< ':'
<< std::setw(9) << std::right << std::setfill('0')
<< (curTimeNanosecondPrecision - curTimeSecondPrecision*1000000000)
<< ']';
_buffer << ' ';

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions