Hi ,

I have attached the patch which is having both functionalities (-v for
version info and timestamp in log)

Here timestamp is added only for linux platform because on windows pgagent
logs are viewed in event viewer which provides timestamp on its own.

Please do review it and let me know in case anything is missing.

Regards,
Sanket Mehta
Sr Software engineer
Enterprisedb

On Fri, Jul 10, 2015 at 8:01 PM, Sanket Mehta <sanket.me...@enterprisedb.com
> wrote:

> Sure Dave,
>
> I will look into it.
>
> Regards,
> Sanket Mehta
> Sr Software engineer
> Enterprisedb
>
> On Fri, Jul 10, 2015 at 7:40 PM, Dave Page <dp...@pgadmin.org> wrote:
>
>> Sanket - can you look at this please? As with Josh's request for
>> --version, it looks like we added this functionality to the PEM agent,
>> not pgAgent. You may copy the timestamp support for logging from the
>> PEM code to save effort.
>>
>> On Sat, Jul 4, 2015 at 7:23 PM, Josh Berkus <j...@agliodbs.com> wrote:
>> > Request:
>> >
>> > pgagent's output log current does not include timestamps.  That makes it
>> > fairly hard to debug anything based on the log.  Can we add a timestamp
>> > to the beginning of each log line?
>> >
>> > --
>> > Josh Berkus
>> > PostgreSQL Experts Inc.
>> > http://pgexperts.com
>> >
>> >
>> > --
>> > Sent via pgadmin-support mailing list (pgadmin-support@postgresql.org)
>> > To make changes to your subscription:
>> > http://www.postgresql.org/mailpref/pgadmin-support
>>
>>
>>
>> --
>> Dave Page
>> Blog: http://pgsnake.blogspot.com
>> Twitter: @pgsnake
>>
>> EnterpriseDB UK: http://www.enterprisedb.com
>> The Enterprise PostgreSQL Company
>>
>
>
diff --git a/include/misc.h b/include/misc.h
index 14b4edc..6f1c7d3 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -18,6 +18,7 @@ void WaitAWhile(const bool waitLong = false);
 void setOptions(int argc, char **argv, const wxString &executable);
 wxString getArg(int &argc, char **&argv);
 wxString NumToStr(const long l);
+void printVersion();
 
 #endif // MISC_H
 
diff --git a/include/pgAgent.h b/include/pgAgent.h
index 6ef4944..3a09197 100644
--- a/include/pgAgent.h
+++ b/include/pgAgent.h
@@ -34,6 +34,9 @@ extern bool runInForeground;
 extern wxString logFile;
 #endif
 
+// Application Versions
+#define VERSION_STR     wxT("3.4.0")
+
 // Log levels
 enum
 {
diff --git a/misc.cpp b/misc.cpp
index dfd56a0..1978a72 100644
--- a/misc.cpp
+++ b/misc.cpp
@@ -42,6 +42,11 @@ wxString getArg(int &argc, char **&argv)
 	return s;
 }
 
+void printVersion()
+{
+	wxPrintf(_("PostgreSQL Scheduling Agent\n"));
+	wxPrintf(_("Version: %s\n"), VERSION_STR);
+}
 
 void setOptions(int argc, char **argv, const wxString &executable)
 {
@@ -72,6 +77,11 @@ void setOptions(int argc, char **argv, const wxString &executable)
 						minLogLevel = val;
 					break;
 				}
+				case 'v':
+				{
+					printVersion();
+					exit (0);
+				}
 #ifndef __WXMSW__
 				case 'f':
 				{
diff --git a/unix.cpp b/unix.cpp
index 34ad0f6..3228b98 100644
--- a/unix.cpp
+++ b/unix.cpp
@@ -17,14 +17,17 @@
 #include <wx/filename.h>
 #include <wx/ffile.h>
 #include <fcntl.h>
+void printVersion();
 
 void usage(const wxString &executable)
 {
 	wxFileName *fn = new wxFileName(executable);
+	printVersion();
 
 	wxPrintf(_("Usage:\n"));
 	wxPrintf(fn->GetName() + _(" [options] <connect-string>\n"));
 	wxPrintf(_("options:\n"));
+	wxPrintf(_("-v (shows version then exit)\n"));
 	wxPrintf(_("-f run in the foreground (do not detach from the terminal)\n"));
 	wxPrintf(_("-t <poll time interval in seconds (default 10)>\n"));
 	wxPrintf(_("-r <retry period after connection abort in seconds (>=10, default 30)>\n"));
@@ -50,22 +53,25 @@ void LogMessage(wxString msg, int level)
 		return;
 	}
 
+	wxDateTime logTime = wxDateTime::Now();
+	wxString logTimeString = logTime.Format() + wxT(" : ");
+
 	switch (level)
 	{
 		case LOG_DEBUG:
 			if (minLogLevel >= LOG_DEBUG)
-				file.Write(_("DEBUG: ") + msg + wxT("\n"));
+				file.Write(logTimeString + _("DEBUG: ") + msg + wxT("\n"));
 			break;
 		case LOG_WARNING:
 			if (minLogLevel >= LOG_WARNING)
-				file.Write(_("WARNING: ") + msg + wxT("\n"));
+				file.Write(logTimeString + _("WARNING: ") + msg + wxT("\n"));
 			break;
 		case LOG_ERROR:
-			file.Write(_("ERROR: ") + msg + wxT("\n"));
+			file.Write(logTimeString + _("ERROR: ") + msg + wxT("\n"));
 			exit(1);
 			break;
 		case LOG_STARTUP:
-			file.Write(_("WARNING: ") + msg + wxT("\n"));
+			file.Write(logTimeString + _("WARNING: ") + msg + wxT("\n"));
 			break;
 	}
 
diff --git a/win32.cpp b/win32.cpp
index aa5d5d7..56a9398 100644
--- a/win32.cpp
+++ b/win32.cpp
@@ -36,6 +36,7 @@ static HANDLE serviceSync;
 static HANDLE eventHandle;
 
 bool stopService();
+void printVersion();
 
 // This will be called from MainLoop, if pgagent is initialized properly
 void Initialized()
@@ -435,12 +436,14 @@ bool removeService(const wxString &serviceName)
 void usage(const wxString &executable)
 {
 	wxFileName *fn = new wxFileName(executable);
+	printVersion();
 
 	wxPrintf(_("Usage:\n"));
 	wxPrintf(fn->GetName() + _(" REMOVE <serviceName>\n"));
 	wxPrintf(fn->GetName() + _(" INSTALL <serviceName> [options] <connect-string>\n"));
 	wxPrintf(fn->GetName() + _(" DEBUG [options] <connect-string>\n"));
 	wxPrintf(_("options:\n"));
+	wxPrintf(_("-v (shows version then exit)\n"));
 	wxPrintf(_("-u <user or DOMAIN\\user>\n"));
 	wxPrintf(_("-p <password>\n"));
 	wxPrintf(_("-d <displayname>\n"));
-- 
Sent via pgadmin-support mailing list (pgadmin-support@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-support

Reply via email to