Changeset 368 for trunk/src/core


Ignore:
Timestamp:
05/22/15 10:28:08 (10 years ago)
Author:
epyon
Message:
  • massive restructuring
  • detail::data_base class for container/reference class base
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/logger.cc

    r365 r368  
    142142void log_console_sink::log( log_level level, const string_ref& message )
    143143{
     144        char stamp[16];
     145        size_t ssize = timestamp( stamp );
     146
    144147#if NV_PLATFORM == NV_WINDOWS
    145148        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 );
    148150        WriteConsole( m_handle, " [", 2, nullptr, nullptr );
    149151        if (m_color) SetConsoleTextAttribute( m_handle, log_color[( level ) / 10] );
     
    156158#else
    157159        if ( m_color ) fwrite( "\33[30;1m", 7, 1, stdout );
    158         fwrite( stamp.data(), stamp.size(), 1, stdout );
     160        fwrite( stamp, ssize, 1, stdout );
    159161        fwrite( " [", 2, 1, stdout );
    160162        if ( m_color )
     
    176178void log_handle_sink::log( log_level level, const string_ref& message )
    177179{
    178         string_ref stamp( timestamp() );
     180        char stamp[16];
     181        size_t ssize = timestamp( stamp );
    179182#if 0 // NV_PLATFORM == NV_WINDOWS
    180183        // Turns out WriteFile on Windows is unbuffered and quite slower than fwrite
     
    182185        // If we want to get rid of C runtime, this would need a buffered I/O layer.
    183186        DWORD unused = 0;
    184         WriteFile( m_handle, stamp.data(), stamp.size(), &unused, nullptr );
     187        WriteFile( m_handle, stamp, ssize, &unused, nullptr );
    185188        WriteFile( m_handle, " [", 2, &unused, nullptr );
    186189        WriteFile( m_handle, NV_LOG_LEVEL_NAME_PAD( level ), 8, &unused, nullptr );
     
    190193        //if ( m_flush ) FlushFileBuffers( m_handle );
    191194#else
    192         fwrite( stamp.data(), stamp.size(), 1, (FILE*)m_handle );
     195        fwrite( stamp, ssize, 1, (FILE*)m_handle );
    193196        fwrite( " [", 2, 1, (FILE*)m_handle );
    194197        fwrite( NV_LOG_LEVEL_NAME_PAD( level ), 8, 1, (FILE*)m_handle );
     
    237240}
    238241
    239 string_ref nv::log_sink::timestamp() const
     242size_t nv::log_sink::timestamp( char* buffer ) const
    240243{
    241244        uint32 ms = get_system_ms();
     
    245248        unsigned int m    = (unsigned int)(secs / 60) % 60;
    246249        unsigned int s    = secs % 60;
    247         static char buffer[16];
    248250#if NV_PLATFORM == NV_WINDOWS
    249251        sprintf_s( buffer, 16, "%02d:%02d:%02d.%02d", h, m, s, mm );
     
    251253        snprintf( buffer, 16, "%02d:%02d:%02d.%02d", h, m, s, mm );
    252254#endif
    253         buffer[11] = '\0';
    254         return string_ref( buffer, 10 );
     255        return 11;
    255256}
    256257
Note: See TracChangeset for help on using the changeset viewer.