Changeset 2001

Show
Ignore:
Timestamp:
15/12/2007 20:03:50 (13 months ago)
Author:
chris
Message:

Allow logging with microsecond timestamps.

Location:
box/trunk/lib/common
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • box/trunk/lib/common/Logging.cpp

    r1789 r2001  
    2121#include <iomanip> 
    2222 
     23#include "BoxTime.h" 
     24 
    2325bool Logging::sLogToSyslog  = false; 
    2426bool Logging::sLogToConsole = false; 
     
    179181 
    180182bool Console::sShowTime = false; 
    181 bool Console::sShowTag  = false; 
     183bool Console::sShowTimeMicros = false; 
     184bool Console::sShowTag = false; 
    182185std::string Console::sTag; 
    183186 
     
    193196} 
    194197 
     198void Console::SetShowTimeMicros(bool enabled) 
     199{ 
     200        sShowTimeMicros = enabled; 
     201} 
     202 
    195203bool Console::Log(Log::Level level, const std::string& rFile,  
    196204        int line, std::string& rMessage) 
     
    212220        if (sShowTime) 
    213221        { 
    214                 struct tm time_now, *tm_ptr = &time_now; 
    215                 time_t time_t_now = time(NULL); 
    216  
    217                 if (time_t_now == ((time_t)-1)) 
    218                 { 
    219                         msg += strerror(errno); 
    220                         msg += " "; 
    221                 } 
     222                box_time_t time_now = GetCurrentBoxTime(); 
     223                time_t seconds = BoxTimeToSeconds(time_now); 
     224                int micros = BoxTimeToMicroSeconds(time_now) % MICRO_SEC_IN_SEC; 
     225 
     226                struct tm tm_now, *tm_ptr = &tm_now; 
     227 
    222228                #ifdef WIN32 
    223                         else if ((tm_ptr = localtime(&time_t_now)) != NULL) 
     229                        if ((tm_ptr = localtime(&seconds)) != NULL) 
    224230                #else 
    225                         else if (localtime_r(&time_t_now, &time_now) != NULL) 
     231                        if (localtime_r(&seconds, &tm_now) != NULL) 
    226232                #endif 
    227233                { 
    228234                        std::ostringstream buf; 
     235 
    229236                        buf << std::setfill('0') << 
    230237                                std::setw(2) << tm_ptr->tm_hour << ":" <<  
    231238                                std::setw(2) << tm_ptr->tm_min  << ":" << 
    232                                 std::setw(2) << tm_ptr->tm_sec  << " "; 
     239                                std::setw(2) << tm_ptr->tm_sec; 
     240 
     241                        if (sShowTimeMicros) 
     242                        { 
     243                                buf << "." << std::setw(6) << micros; 
     244                        } 
     245 
     246                        buf << " "; 
    233247                        msg += buf.str(); 
    234248                } 
  • box/trunk/lib/common/Logging.h

    r1938 r2001  
    119119        private: 
    120120        static bool sShowTime; 
     121        static bool sShowTimeMicros; 
    121122        static bool sShowTag; 
    122123        static std::string sTag; 
     
    130131        static void SetTag(const std::string& rTag); 
    131132        static void SetShowTime(bool enabled); 
     133        static void SetShowTimeMicros(bool enabled); 
    132134}; 
    133135