Changeset 368 for trunk/src/core/logger.cc
- Timestamp:
- 05/22/15 10:28:08 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/logger.cc
r365 r368 142 142 void log_console_sink::log( log_level level, const string_ref& message ) 143 143 { 144 char stamp[16]; 145 size_t ssize = timestamp( stamp ); 146 144 147 #if NV_PLATFORM == NV_WINDOWS 145 148 if ( m_color ) SetConsoleTextAttribute( m_handle, FOREGROUND_INTENSITY ); 146 string_ref stamp( timestamp() ); 147 WriteConsole( m_handle, stamp.data(), stamp.size(), nullptr, nullptr ); 149 WriteConsole( m_handle, stamp, ssize, nullptr, nullptr ); 148 150 WriteConsole( m_handle, " [", 2, nullptr, nullptr ); 149 151 if (m_color) SetConsoleTextAttribute( m_handle, log_color[( level ) / 10] ); … … 156 158 #else 157 159 if ( m_color ) fwrite( "\33[30;1m", 7, 1, stdout ); 158 fwrite( stamp .data(), stamp.size(), 1, stdout );160 fwrite( stamp, ssize, 1, stdout ); 159 161 fwrite( " [", 2, 1, stdout ); 160 162 if ( m_color ) … … 176 178 void log_handle_sink::log( log_level level, const string_ref& message ) 177 179 { 178 string_ref stamp( timestamp() ); 180 char stamp[16]; 181 size_t ssize = timestamp( stamp ); 179 182 #if 0 // NV_PLATFORM == NV_WINDOWS 180 183 // Turns out WriteFile on Windows is unbuffered and quite slower than fwrite … … 182 185 // If we want to get rid of C runtime, this would need a buffered I/O layer. 183 186 DWORD unused = 0; 184 WriteFile( m_handle, stamp .data(), stamp.size(), &unused, nullptr );187 WriteFile( m_handle, stamp, ssize, &unused, nullptr ); 185 188 WriteFile( m_handle, " [", 2, &unused, nullptr ); 186 189 WriteFile( m_handle, NV_LOG_LEVEL_NAME_PAD( level ), 8, &unused, nullptr ); … … 190 193 //if ( m_flush ) FlushFileBuffers( m_handle ); 191 194 #else 192 fwrite( stamp .data(), stamp.size(), 1, (FILE*)m_handle );195 fwrite( stamp, ssize, 1, (FILE*)m_handle ); 193 196 fwrite( " [", 2, 1, (FILE*)m_handle ); 194 197 fwrite( NV_LOG_LEVEL_NAME_PAD( level ), 8, 1, (FILE*)m_handle ); … … 237 240 } 238 241 239 s tring_ref nv::log_sink::timestamp() const242 size_t nv::log_sink::timestamp( char* buffer ) const 240 243 { 241 244 uint32 ms = get_system_ms(); … … 245 248 unsigned int m = (unsigned int)(secs / 60) % 60; 246 249 unsigned int s = secs % 60; 247 static char buffer[16];248 250 #if NV_PLATFORM == NV_WINDOWS 249 251 sprintf_s( buffer, 16, "%02d:%02d:%02d.%02d", h, m, s, mm ); … … 251 253 snprintf( buffer, 16, "%02d:%02d:%02d.%02d", h, m, s, mm ); 252 254 #endif 253 buffer[11] = '\0'; 254 return string_ref( buffer, 10 ); 255 return 11; 255 256 } 256 257
Note: See TracChangeset
for help on using the changeset viewer.