disable debug log during authenication

pull/40/head
Nestal Wan 2012-06-03 17:31:16 +08:00
parent 54b65bb738
commit 53f9c39941
6 changed files with 34 additions and 6 deletions

View File

@ -127,8 +127,8 @@ void Drive::SyncFolders( http::Agent *http )
Log( "Synchronizing folders", log::info ) ;
http::XmlResponse xml ;
http::ResponseLog log( "dir-", ".xml", &xml ) ;
http->Get( feed_base + "/-/folder?max-results=50&showroot=true", &log, m_http_hdr ) ;
// http::ResponseLog log( "dir-", ".xml", &xml ) ;
http->Get( feed_base + "/-/folder?max-results=50&showroot=true", &xml, m_http_hdr ) ;
xml::Node resp = xml.Response() ;

View File

@ -23,6 +23,7 @@
#include "Json.hh"
#include "http/Agent.hh"
#include "util/Log.hh"
// for debugging
#include <iostream>
@ -62,6 +63,7 @@ void OAuth2::Auth( const std::string& auth_code )
http::JsonResponse resp ;
http::Agent http ;
DisableLog dlog( log::debug ) ;
http.Post( token_url, post, &resp ) ;
Json jresp = resp.Response() ;
@ -98,6 +100,7 @@ void OAuth2::Refresh( )
http::JsonResponse resp ;
http::Agent http ;
DisableLog dlog( log::debug ) ;
http.Post( token_url, post, &resp ) ;
m_access = resp.Response()["access_token"].Str() ;

View File

@ -66,10 +66,12 @@ void DefaultLog::Log( const log::Fmt& msg, log::Serverity s )
}
}
void DefaultLog::Enable( log::Serverity s, bool enable )
bool DefaultLog::Enable( log::Serverity s, bool enable )
{
assert( s >= log::debug && s <= log::critical ) ;
bool prev = m_enabled[s] ;
m_enabled[s] = enable ;
return prev ;
}
} // end of namespace

View File

@ -34,7 +34,7 @@ public :
explicit DefaultLog( const std::string& filename ) ;
void Log( const log::Fmt& msg, log::Serverity s ) ;
void Enable( log::Serverity s, bool enable ) ;
bool Enable( log::Serverity s, bool enable ) ;
private :
std::ofstream m_file ;

View File

@ -30,8 +30,9 @@ public :
{
}
void Enable( log::Serverity s, bool enable )
bool Enable( log::Serverity s, bool enable )
{
return enable ;
}
} ;
@ -66,4 +67,15 @@ void Trace( const std::string& str )
LogBase::Inst()->Log( log::Fmt(str), log::debug ) ;
}
DisableLog::DisableLog( log::Serverity s ) :
m_sev( s ),
m_prev( LogBase::Inst()->Enable( s, false ) )
{
}
DisableLog::~DisableLog()
{
LogBase::Inst()->Enable( m_sev, m_prev ) ;
}
} // end of namespace

View File

@ -57,7 +57,7 @@ class LogBase
{
public :
virtual void Log( const log::Fmt& msg, log::Serverity s = log::info ) = 0 ;
virtual void Enable( log::Serverity s, bool enable = true ) = 0 ;
virtual bool Enable( log::Serverity s, bool enable = true ) = 0 ;
static LogBase* Inst( LogBase *log = 0 ) ;
@ -66,6 +66,17 @@ protected :
~LogBase() ;
} ;
class DisableLog
{
public :
DisableLog( log::Serverity s ) ;
~DisableLog() ;
private :
log::Serverity m_sev ;
bool m_prev ;
} ;
void Log( const std::string& str, log::Serverity s = log::info ) ;
template <typename P1>