Author | Topic: write to log window | |
---|---|---|
Jeremy Suiter | write to log window on Tue, 17 Jun 2008 10:44:51 +0100 Hi, Does anyone know if it's possible to write to the log window from a custom function? TIA Jeremy | |
Thomas Braun | Re: write to log window on Thu, 19 Jun 2008 16:27:40 +0200 Jeremy Suiter wrote: > Hi, > > Does anyone know if it's possible to write to the log window from a custom > function? Yes This is how I do it: Step 1: Create a init procedure in one of the packages, declare some locals you need later on: INIT Procedure MyPersonalInit() LOCAL oDlg, oList LOCAL oStat Step 2: Get the windows you need: oDlg := AppDesktop():Childlist()[1] oDlg:Hide() oStat := oDlg:drawingarea:childlist()[2] oList := oStat:ChildList()[2] oList:Clear() oList:SetFontCompoundName("8.Courier New") Step 3: Initialize the loggin function with the List control: Init Logging Function WriteToLogScreen( oList ) Step 4: Create the logging function: FUNCTION WriteToLogScreen( cText ) STATIC oLogList #pragma info(NOINIT) suppress warning about not initialised static IF oLogList = NIL #pragma info(INIT) reset warning status oLogList := cText cText := "" ENDIF IF ! EMPTY(cText) .AND. VALTYPE(oLogList) = "O" oLogList:AddItem( "worker #" + LTRIM(STR(ThreadID())) + " " + TRIM(cText) ) oLogList:SetTopItem( oLogList:NumItems()) ENDIF RETURN NIL I think that's it! What you unfortunately can't do is to write in the "official" log file, so you would have to maintain a log file of your own. regards Thomas | |
Jeremy Suiter | Re: write to log window on Thu, 19 Jun 2008 16:31:34 +0100 Thomas Thanks for this. I shall give it a try. Regards Jeremy "Thomas Braun" <spam@software-braun.de> wrote in message news:1y1ebunz9g0yq.4yxhx7eu8h8n$.dlg@40tude.net... > Jeremy Suiter wrote: > >> Hi, >> >> Does anyone know if it's possible to write to the log window from a >> custom >> function? > > Yes > > This is how I do it: > > Step 1: > > Create a init procedure in one of the packages, declare some locals you > need later on: > > INIT Procedure MyPersonalInit() > LOCAL oDlg, oList > LOCAL oStat > > > Step 2: Get the windows you need: > > oDlg := AppDesktop():Childlist()[1] > oDlg:Hide() > > oStat := oDlg:drawingarea:childlist()[2] > oList := oStat:ChildList()[2] > oList:Clear() > oList:SetFontCompoundName("8.Courier New") > > Step 3: Initialize the loggin function with the List control: > > Init Logging Function > WriteToLogScreen( oList ) > > > Step 4: Create the logging function: > > FUNCTION WriteToLogScreen( cText ) > STATIC oLogList > > #pragma info(NOINIT) suppress warning about not initialised static > IF oLogList = NIL > #pragma info(INIT) reset warning status > oLogList := cText > cText := "" > ENDIF > > IF ! EMPTY(cText) .AND. VALTYPE(oLogList) = "O" > oLogList:AddItem( "worker #" + LTRIM(STR(ThreadID())) + " " + > TRIM(cText) ) > oLogList:SetTopItem( oLogList:NumItems()) > ENDIF > > RETURN NIL > > I think that's it! > > What you unfortunately can't do is to write in the "official" log file, so > you would have to maintain a log file of your own. > > regards > Thomas | |
Thomas Braun | Re: write to log window on Tue, 24 Feb 2009 17:36:20 +0100 Jeremy Suiter wrote: > Thomas > > Thanks for this. I shall give it a try. > > Regards Following up on this somewhat aged thread from June 2008 , I have now found the solution how to add messages not only to the logging window, but also the actual log file - here is the new function: FUNCTION WriteToLog( xVal ) STATIC oLog #pragma info(NOINIT) suppress warning about not initialised static IF oLog = NIL Initialise oLog := ClassObject("logsync") xVal := "" ENDIF #pragma info(INIT) IF VALTYPE(xVal) = "C" .AND. ! EMPTY(xVal) .AND. VALTYPE(oLog) = "O" oLog:AddLogMsg("[#" + LTRIM(STR(ThreadID())) + ": " + TRIM(xVal) + "]") ENDIF RETURN NIL This took only a hex editor and a little bit of "detective work"... regards thomas >> Jeremy Suiter wrote: >> >>> Hi, >>> >>> Does anyone know if it's possible to write to the log window from a >>> custom >>> function? >> >> Yes >> >> This is how I do it: >> >> Step 1: >> >> Create a init procedure in one of the packages, declare some locals you >> need later on: >> >> INIT Procedure MyPersonalInit() >> LOCAL oDlg, oList >> LOCAL oStat >> >> >> Step 2: Get the windows you need: >> >> oDlg := AppDesktop():Childlist()[1] >> oDlg:Hide() >> >> oStat := oDlg:drawingarea:childlist()[2] >> oList := oStat:ChildList()[2] >> oList:Clear() >> oList:SetFontCompoundName("8.Courier New") >> >> Step 3: Initialize the loggin function with the List control: >> >> Init Logging Function >> WriteToLogScreen( oList ) >> >> >> Step 4: Create the logging function: >> >> FUNCTION WriteToLogScreen( cText ) >> STATIC oLogList >> >> #pragma info(NOINIT) suppress warning about not initialised static >> IF oLogList = NIL >> #pragma info(INIT) reset warning status >> oLogList := cText >> cText := "" >> ENDIF >> >> IF ! EMPTY(cText) .AND. VALTYPE(oLogList) = "O" >> oLogList:AddItem( "worker #" + LTRIM(STR(ThreadID())) + " " + >> TRIM(cText) ) >> oLogList:SetTopItem( oLogList:NumItems()) >> ENDIF >> >> RETURN NIL >> >> I think that's it! >> >> What you unfortunately can't do is to write in the "official" log file, so >> you would have to maintain a log file of your own. >> >> regards >> Thomas |