From 53f9c39941b413e040fa72b05b58e5c1bbe8fcf7 Mon Sep 17 00:00:00 2001 From: Nestal Wan Date: Sun, 3 Jun 2012 17:31:16 +0800 Subject: [PATCH] disable debug log during authenication --- libgrive/src/drive/Drive.cc | 4 ++-- libgrive/src/protocol/OAuth2.cc | 3 +++ libgrive/src/util/DefaultLog.cc | 4 +++- libgrive/src/util/DefaultLog.hh | 2 +- libgrive/src/util/Log.cc | 14 +++++++++++++- libgrive/src/util/Log.hh | 13 ++++++++++++- 6 files changed, 34 insertions(+), 6 deletions(-) diff --git a/libgrive/src/drive/Drive.cc b/libgrive/src/drive/Drive.cc index a025d5f..456cc1b 100644 --- a/libgrive/src/drive/Drive.cc +++ b/libgrive/src/drive/Drive.cc @@ -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() ; diff --git a/libgrive/src/protocol/OAuth2.cc b/libgrive/src/protocol/OAuth2.cc index a2e3b78..17afd7f 100644 --- a/libgrive/src/protocol/OAuth2.cc +++ b/libgrive/src/protocol/OAuth2.cc @@ -23,6 +23,7 @@ #include "Json.hh" #include "http/Agent.hh" +#include "util/Log.hh" // for debugging #include @@ -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() ; diff --git a/libgrive/src/util/DefaultLog.cc b/libgrive/src/util/DefaultLog.cc index dbecb90..f279a31 100644 --- a/libgrive/src/util/DefaultLog.cc +++ b/libgrive/src/util/DefaultLog.cc @@ -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 diff --git a/libgrive/src/util/DefaultLog.hh b/libgrive/src/util/DefaultLog.hh index f0eafa5..64625e6 100644 --- a/libgrive/src/util/DefaultLog.hh +++ b/libgrive/src/util/DefaultLog.hh @@ -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 ; diff --git a/libgrive/src/util/Log.cc b/libgrive/src/util/Log.cc index 7cdce11..cf89290 100644 --- a/libgrive/src/util/Log.cc +++ b/libgrive/src/util/Log.cc @@ -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 diff --git a/libgrive/src/util/Log.hh b/libgrive/src/util/Log.hh index 35512c8..043d7b0 100644 --- a/libgrive/src/util/Log.hh +++ b/libgrive/src/util/Log.hh @@ -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