Index: include/pgAgent.h =================================================================== --- include/pgAgent.h (revision 5225) +++ include/pgAgent.h (working copy) @@ -26,8 +26,9 @@ extern wxString serviceDBname; extern wxString backendPid; -#ifndef _WIN32_ +#ifndef __WXMSW__ extern bool runInForeground; +extern wxString logFile; #endif // Log levels Index: win32.cpp =================================================================== --- win32.cpp (revision 5225) +++ win32.cpp (working copy) @@ -413,7 +413,7 @@ wxPrintf(_("-d \n")); wxPrintf(_("-t \n")); wxPrintf(_("-r =10, default 30)>\n")); - wxPrintf(_("-l \n")); + wxPrintf(_("-s \n")); } Index: unix.cpp =================================================================== --- unix.cpp (revision 5225) +++ unix.cpp (working copy) @@ -11,11 +11,12 @@ #include "pgAgent.h" -#ifdef WIN32 +#ifdef __WXMSW__ #error this file is for unix only! #endif #include +#include #include void usage(const wxString &executable) @@ -28,27 +29,52 @@ wxPrintf(_("-f run in the foreground (do not detach from the terminal)\n")); wxPrintf(_("-t \n")); wxPrintf(_("-r =10, default 30)>\n")); - wxPrintf(_("-l \n")); + wxPrintf(_("-l \n")); + wxPrintf(_("-s \n")); } -void LogMessage(wxString msg, int level) -{ - switch (level) - { - case LOG_DEBUG: - if (minLogLevel >= LOG_DEBUG) - wxPrintf(_("DEBUG: %s\n"), msg.c_str()); - break; - case LOG_WARNING: - if (minLogLevel >= LOG_WARNING) - wxPrintf(_("WARNING: %s\n"), msg.c_str()); - break; - case LOG_ERROR: - wxPrintf(_("ERROR: %s\n"), msg.c_str()); - exit(1); - break; - } - +void LogMessage(wxString msg, int level) +{ + wxFFile file; + if (logFile.IsEmpty()) + { + file.Attach(stdout); + } + else + { + file.Open(logFile.c_str(), wxT("a")); + } + + if (!file.IsOpened()) + { + wxFprintf(stderr, wxT("Can not open the logfile!")); + return; + } + + switch (level) + { + case LOG_DEBUG: + if (minLogLevel >= LOG_DEBUG) + file.Write(wxT("DEBUG: ") + msg + wxT("\n")); + break; + case LOG_WARNING: + if (minLogLevel >= LOG_WARNING) + file.Write(wxT("WARNING: ") + msg + wxT("\n")); + break; + case LOG_ERROR: + file.Write(wxT("ERROR: ") + msg + wxT("\n")); + exit(1); + break; + } + + if (logFile.IsEmpty()) + { + file.Detach(); + } + else + { + file.Close(); + } } // Shamelessly lifted from pg_autovacuum... Index: pgAgent.cpp =================================================================== --- pgAgent.cpp (revision 5225) +++ pgAgent.cpp (working copy) @@ -11,7 +11,7 @@ #include "pgAgent.h" -#ifndef WIN32 +#ifndef __WXMSW__ #include #endif @@ -22,8 +22,9 @@ long shortWait=10; long minLogLevel=LOG_ERROR; -#ifndef WIN32 +#ifndef __WXMSW__ bool runInForeground = false; +wxString logFile = wxEmptyString; #endif int MainRestartLoop(DBconn *serviceConn) Index: misc.cpp =================================================================== --- misc.cpp (revision 5225) +++ misc.cpp (working copy) @@ -11,7 +11,7 @@ #include "pgAgent.h" -#ifndef WIN32 +#ifndef __WXMSW__ #include #endif @@ -64,19 +64,24 @@ longWait = val; break; } - case 'l': + case 's': { int val = atoi(getArg(argc, argv).mb_str(wxConvUTF8)); if (val >= 0 && val <= 2) minLogLevel = val; break; } -#ifndef WIN32 +#ifndef __WXMSW__ case 'f': { runInForeground = true; break; } + case 'l': + { + logFile = getArg(argc, argv); + break; + } #endif default: {