improved logging for HTTP responses

pull/40/head
Nestal Wan 2012-07-16 23:23:08 +08:00
parent 394982da4e
commit 593c335a5e
5 changed files with 37 additions and 11 deletions

View File

@ -140,7 +140,7 @@ void Drive::DetectChanges()
Log( "Reading remote server file list", log::info ) ;
Feed feed ;
// feed.EnableLog( "/tmp/file", ".xml" ) ;
feed.EnableLog( "/tmp/file", ".xml" ) ;
feed.Start( &http, m_http_hdr, feed_base + "?showfolders=true&showroot=true" ) ;
m_resume_link = feed.Root()["link"].
@ -159,7 +159,7 @@ void Drive::DetectChanges()
{
Log( "Detecting changes from last sync", log::info ) ;
Feed changes ;
// feed.EnableLog( "/tmp/changes", ".xml" ) ;
feed.EnableLog( "/tmp/changes", ".xml" ) ;
feed.Start( &http, m_http_hdr, ChangesFeed(prev_stamp+1) ) ;
std::for_each(

View File

@ -69,8 +69,9 @@ void Feed::Start( http::Agent *http, const http::Header& auth, const std::string
if ( m_log.get() != 0 )
log.Reset(
(boost::format( "%1%-%2%." ) % m_log->prefix % m_log->sequence++).str(),
m_log->suffix, &xrsp ) ;
m_log->prefix,
(boost::format( "-#%1%%2%" ) % m_log->sequence++ % m_log->suffix ).str(),
&xrsp ) ;
http->Get( url, &log, auth ) ;

View File

@ -260,8 +260,8 @@ void Resource::FromLocal( const DateTime& last_sync )
// in FromRemote()
else
{
// Trace( "file %1% mtime %2%, last_sync %3%", path, m_mtime, last_sync ) ;
m_state = ( m_mtime > last_sync ? local_new : remote_deleted ) ;
// Trace( "file %1% mtime %2%, last_sync %3%, state (%4%)", path, m_mtime, last_sync, m_state ) ;
}
m_name = Path2Str( path.filename() ) ;
@ -567,7 +567,12 @@ bool Resource::Create( http::Agent* http, const http::Header& auth, DateTime& sy
}
}
bool Resource::Upload( http::Agent* http, const std::string& link, const http::Header& auth, bool post, DateTime& sync_time )
bool Resource::Upload(
http::Agent* http,
const std::string& link,
const http::Header& auth,
bool post,
DateTime& sync_time )
{
assert( http != 0 ) ;

View File

@ -19,6 +19,7 @@
#include "ResponseLog.hh"
#include "util/log/Log.hh"
#include "util/DateTime.hh"
#include <cassert>
@ -30,10 +31,9 @@ ResponseLog::ResponseLog(
const std::string& suffix,
Receivable *next ) :
m_enabled ( true ),
m_log ( Filename(prefix, suffix).c_str() ),
m_next ( next )
{
assert( m_next != 0 ) ;
Reset( prefix, suffix, next ) ;
}
ResponseLog::ResponseLog( Receivable *next ) :
@ -62,7 +62,7 @@ void ResponseLog::Clear()
std::string ResponseLog::Filename( const std::string& prefix, const std::string& suffix )
{
return prefix + DateTime::Now().Format( "%H%M%S" ) + suffix ;
return prefix + DateTime::Now().Format( "%F.%H%M%S" ) + suffix ;
}
void ResponseLog::Enable( bool enable )
@ -77,9 +77,23 @@ void ResponseLog::Reset( const std::string& prefix, const std::string& suffix, R
if ( m_log.is_open() )
m_log.close() ;
m_log.open( Filename(prefix, suffix).c_str() ) ;
const std::string fname = Filename(prefix, suffix) ;
// reset previous stream state. don't care if file can be opened
// successfully previously
m_log.clear() ;
// re-open the file
m_log.open( fname.c_str() ) ;
if ( m_log )
{
Trace( "logging HTTP response: %1%", fname ) ;
m_enabled = true ;
}
else
Trace( "cannot open log file %1%", fname ) ;
m_next = next ;
m_enabled = true ;
}
}} // end of namespace

View File

@ -135,4 +135,10 @@ void Trace( const std::string& fmt, const P1& p1, const P2& p2, const P3& p3 )
LogBase::Inst()->Log( log::Fmt(fmt) % p1 % p2 % p3, log::debug ) ;
}
template <typename P1, typename P2, typename P3, typename P4>
void Trace( const std::string& fmt, const P1& p1, const P2& p2, const P3& p3, const P4& p4 )
{
LogBase::Inst()->Log( log::Fmt(fmt) % p1 % p2 % p3 % p4, log::debug ) ;
}
} // end of namespace