Log.cpp
//==============================================================================
// Generates a timestamp to prepend to a log message
//==============================================================================
Generates a timestamp to prepend to a log message
Generates a timestamp to prepend to a log message
void Log::generateTimestamp(std::string& timestamp) const
{
    timeval ts;
    if (gettimeofday(&ts, 0) == -1)
    {
        timestamp = "[???]";
        return;
    }
    tm ts_local;
    if (current_time_format == LOCAL)
    {
        localtime_r(&ts.tv_sec, &ts_local);
    }
    else
    {
        gmtime_r(&ts.tv_sec, &ts_local);
    }
    unsigned int max_ts_len = 30;
    char ts_local_temp[max_ts_len];
    strftime(ts_local_temp, max_ts_len, "%a %b %d %Y %X:", &ts_local);
    timestamp = "[";
    timestamp += ts_local_temp;
    std::ostringstream out_stream;
    out_stream.width(6);
    out_stream.fill('0');
    out_stream << ts.tv_usec;
    timestamp += out_stream.str();
    strftime(ts_local_temp, max_ts_len, " %Z", &ts_local);
    timestamp += ts_local_temp;
    timestamp += "]";
}
void Log :: generateTimestamp ( std :: string & timestamp ) const { timeval ts ; if ( gettimeofday ( & ts , 0 ) == -1 ) { timestamp = " " ; return ; } tm ts_local ; if ( current_time_format == LOCAL ) { localtime_r ( & ts . tv_sec , & ts_local ) ; } else { gmtime_r ( & ts . tv_sec , & ts_local ) ; } unsigned int max_ts_len = 30 ; char ts_local_temp [ max_ts_len ] ; strftime ( ts_local_temp , max_ts_len , " " , & ts_local ) ; timestamp = " " ; timestamp += ts_local_temp ; std :: ostringstream out_stream ; out_stream . width ( 6 ) ; out_stream . fill ( ' ' ) ; out_stream << ts . tv_usec ; timestamp += out_stream . str ( ) ; strftime ( ts_local_temp , max_ts_len , " " , & ts_local ) ; timestamp += ts_local_temp ; timestamp += " " ; }
Generates a timestamp to prepend to a log message
Generates a timestamp to prepend to a log message
// Get numeric timestamp // Could not generate timestamp // Convert ts into string timestamp // Format ts_local // Save into string timestamp // Add microseconds // Add timezone