Skip to content
This repository has been archived by the owner on Sep 15, 2022. It is now read-only.

Commit

Permalink
Fix the logging system to ensure that errors from the
Browse files Browse the repository at this point in the history
query tool get logged, and notices are only output once.
Cleanup some other minor misbehaviours at the same time.
Per report from Erwin.

git-svn-id: svn://svn.pgadmin.org/branches/REL-1_8_0_PATCHES@7215 a7884b65-44f6-0310-8a51-81a127f17b15
  • Loading branch information
dpage committed Apr 4, 2008
1 parent b4ae755 commit 4cb86a8
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 26 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG
Expand Up @@ -36,7 +36,11 @@ Changes

Date Dev Ver Change details
---------- --- ----- --------------
2008-03-27 DP 1.8.3 Ignore the type modifier for domains in function
2008-04-04 DP 1.8.3 Fix the logging system to ensure that errors from the
query tool get logged, and notices are only output once.
Cleanup some other minor misbehaviours at the same time.
Per report from Erwin.
2008-03-27 DP 1.8.3 Ignore the type modifier for domains in function
signatures.
2008-03-22 DP 1.8.3 If stopping the server service fails after stopping
dependent services, wait 5 seconds and try again up to 10
Expand Down
30 changes: 14 additions & 16 deletions pgadmin/db/pgConn.cpp
Expand Up @@ -480,11 +480,13 @@ void pgConn::RegisterNoticeProcessor(PQnoticeProcessor proc, void *arg)

void pgConn::Notice(const char *msg)
{
wxString str(msg, *conv);
wxLogNotice(wxT("%s"), str.c_str());

if (noticeArg && noticeProc)
(*noticeProc)(noticeArg, msg);
else
{
wxString str(msg, *conv);
wxLogNotice(wxT("%s"), str.Trim().c_str());
}
}


Expand Down Expand Up @@ -530,8 +532,7 @@ bool pgConn::ExecuteVoid(const wxString& sql, bool reportError)
if (lastResultStatus != PGRES_TUPLES_OK &&
lastResultStatus != PGRES_COMMAND_OK)
{
if (reportError)
LogError();
LogError(!reportError);
return false;
}

Expand Down Expand Up @@ -640,22 +641,19 @@ wxString pgConn::GetLastError() const



void pgConn::LogError()
void pgConn::LogError(const bool quiet)
{
if (conn)
{
wxLogError(wxT("%s"), GetLastError().c_str());

IsAlive();
#if 0
ConnStatusType status = PQstatus(conn);
if (status == CONNECTION_BAD)
if (quiet)
{
PQfinish(conn);
conn=0;
connStatus = PGCONN_BROKEN;
wxLogQuietError(wxT("%s"), GetLastError().c_str());
}
else
{
wxLogError(wxT("%s"), GetLastError().c_str());
IsAlive();
}
#endif
}
}

Expand Down
8 changes: 4 additions & 4 deletions pgadmin/db/pgQueryThread.cpp
Expand Up @@ -27,7 +27,7 @@ static void pgNoticeProcessor(void *arg, const char *message)
{
wxString str(message, wxConvUTF8);

wxLogNotice(wxT("%s"), str.c_str());
wxLogNotice(wxT("%s"), str.Trim().c_str());
((pgQueryThread*)arg)->appendMessage(str);
}

Expand All @@ -45,7 +45,7 @@ pgQueryThread::pgQueryThread(pgConn *_conn, const wxString &qry, int _resultToRe
eventId=_eventId;
data=_data;

wxLogSql(wxT("Thread Query %s"), qry.c_str());
wxLogSql(wxT("Thread query (%s:%d): %s"), conn->GetHost().c_str(), conn->GetPort(), qry.c_str());

conn->RegisterNoticeProcessor(pgNoticeProcessor, this);
if (conn->conn)
Expand Down Expand Up @@ -178,8 +178,8 @@ int pgQueryThread::raiseEvent(int retval)
{
if (caller)
{
wxCommandEvent resultEvent(wxEVT_COMMAND_MENU_SELECTED, eventId);
resultEvent.SetClientData(data);
wxCommandEvent resultEvent(wxEVT_COMMAND_MENU_SELECTED, eventId);
resultEvent.SetClientData(data);
caller->AddPendingEvent(resultEvent);
}
return retval;
Expand Down
1 change: 1 addition & 0 deletions pgadmin/frm/frmQuery.cpp
Expand Up @@ -1736,6 +1736,7 @@ void frmQuery::OnQueryComplete(wxCommandEvent &ev)
{
pgError err = sqlResult->GetResultError();
wxString errMsg = err.formatted_msg;
wxLogQuietError(conn->GetLastError().Trim().c_str());

long errPos;
err.statement_pos.ToLong(&errPos);
Expand Down
2 changes: 1 addition & 1 deletion pgadmin/include/db/pgConn.h
Expand Up @@ -125,7 +125,7 @@ class pgConn
void RegisterNoticeProcessor(PQnoticeProcessor proc, void *arg);
wxMBConv *GetConv() { return conv; };

void LogError();
void LogError(const bool quiet=false);

bool IsSSLconnected();
PGconn *connection() { return conn; }
Expand Down
3 changes: 2 additions & 1 deletion pgadmin/include/utils/sysLogger.h
Expand Up @@ -41,9 +41,10 @@ class sysLogger : public wxLog

#define wxLOG_Notice (wxLOG_User+1)
#define wxLOG_Sql (wxLOG_User+2)
#define wxLOG_QuietError (wxLOG_User+3)

DECLARE_LOG_FUNCTION(Notice);
DECLARE_LOG_FUNCTION(Sql);

DECLARE_LOG_FUNCTION(QuietError);

#endif
34 changes: 31 additions & 3 deletions pgadmin/utils/sysLogger.cpp
Expand Up @@ -25,6 +25,27 @@ wxLogLevel sysLogger::logLevel=LOG_ERRORS;
wxString sysLogger::logFile=wxT("debug.log");

// IMPLEMENT_LOG_FUNCTION(Sql) from wx../common/log.c
void wxVLogQuietError(const wxChar *szFormat, va_list argptr)
{
static wxChar s_szBuf[1024];

if (sysLogger::logLevel >= LOG_ERRORS)
{
wxVsnprintf(s_szBuf, WXSIZEOF(s_szBuf), szFormat, argptr);
wxLog::OnLog(wxLOG_QuietError, s_szBuf, time(NULL));

}
}

void wxLogQuietError(const wxChar *szFormat, ...)
{
va_list argptr;
va_start(argptr, szFormat);
wxVLogQuietError(szFormat, argptr);
va_end(argptr);
}


void wxVLogSql(const wxChar *szFormat, va_list argptr)
{
static wxChar s_szBuf[1024];
Expand Down Expand Up @@ -54,8 +75,7 @@ void wxVLogNotice(const wxChar *szFormat, va_list argptr)
if (sysLogger::logLevel >= LOG_NOTICE)
{
wxVsnprintf(s_szBuf, WXSIZEOF(s_szBuf), szFormat, argptr);
wxLog::OnLog(wxLOG_Sql, s_szBuf, time(NULL));

wxLog::OnLog(wxLOG_Notice, s_szBuf, time(NULL));
}
}

Expand Down Expand Up @@ -85,6 +105,10 @@ void sysLogger::DoLog(wxLogLevel level, const wxChar *msg, time_t timestamp)
icon = wxICON_ERROR;
break;

case wxLOG_QuietError:
msgtype = wxT("ERROR ");
break;

case wxLOG_Warning:
msgtype = wxT("WARNING");
preamble = _("Warning:\n\n");
Expand Down Expand Up @@ -146,20 +170,23 @@ void sysLogger::DoLog(wxLogLevel level, const wxChar *msg, time_t timestamp)

case LOG_ERRORS:
if (level == wxLOG_FatalError ||
level == wxLOG_Error)
level == wxLOG_Error ||
level == wxLOG_QuietError)
WriteLog(fullmsg);
break;

case LOG_NOTICE:
if (level == wxLOG_FatalError ||
level == wxLOG_Error ||
level == wxLOG_QuietError ||
level == wxLOG_Notice)
WriteLog(fullmsg);
break;

case LOG_SQL:
if (level == wxLOG_FatalError ||
level == wxLOG_Error ||
level == wxLOG_QuietError ||
level == wxLOG_Message ||
level == wxLOG_Status ||
level == wxLOG_Notice ||
Expand Down Expand Up @@ -213,3 +240,4 @@ bool sysLogger::SilenceMessage(const wxString &msg)
return false;
}


0 comments on commit 4cb86a8

Please sign in to comment.