Index: include/pgAgent.h =================================================================== --- include/pgAgent.h (revision 5227) +++ 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: unix.cpp =================================================================== --- unix.cpp (revision 5227) +++ 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(_("-s \n")); wxPrintf(_("-l \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, _("Can not open the logfile!")); + return; + } + + switch (level) + { + case LOG_DEBUG: + if (minLogLevel >= LOG_DEBUG) + file.Write(_("DEBUG: ") + msg + wxT("\n")); + break; + case LOG_WARNING: + if (minLogLevel >= LOG_WARNING) + file.Write(_("WARNING: ") + msg + wxT("\n")); + break; + case LOG_ERROR: + file.Write(_("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 5227) +++ 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 5227) +++ misc.cpp (working copy) @@ -11,7 +11,7 @@ #include "pgAgent.h" -#ifndef WIN32 +#ifndef __WXMSW__ #include #endif @@ -71,12 +71,17 @@ minLogLevel = val; break; } -#ifndef WIN32 +#ifndef __WXMSW__ case 'f': { runInForeground = true; break; } + case 's': + { + logFile = getArg(argc, argv); + break; + } #endif default: {