Page 1 of 1
MsgDebug() -> Logfile ?
Posted: Thu Feb 18, 2021 5:49 pm
by AUGE_OHR
hi,
i often use MsgDebug() but that "stop" App
is there a harbour / HMG Way to get Message in a Logfile

Re: MsgDebug() -> Logfile ?
Posted: Thu Feb 18, 2021 6:00 pm
by serge_girard
I have default in my programs a logging. Simple and yet very effective.
Start of your program:
Code: Select all
SET PRINTER TO debug.txt
SET PRINTER ON
SET CONSOLE OFF
? 'logging', date(), time()
More sophisticated:
Code: Select all
FUNCTION Open_Trace()
/*******************/
LOCAL cTRACE := ''
LOCAL cDATE := DTOC(DATE())
LOCAL cFOLDER := GetStartUpFolder()
LOCAL lUPD
SET DATE FRENCH
SET CENT ON
cDATE := DTOC(DATE())
cDATE := STRTRAN(cDATE,'-','')
cDATE := STRTRAN(cDATE,'/','')
cTRACE := cFOLDER + "\TRACE" + cDATE + '.TXT'
IF .NOT. FILE(cTRACE)
hTRACE := FCREATE(cTRACE)
ELSE
hTRACE := FOPEN(cTRACE,2)
FSEEK(hTRACE,0,2) //End Of File
ENDIF
RETURN (hTRACE)
FUNCTION Close_Trace()
/*********************/
Write_Trace('Close_Trace')
FCLOSE( hTRACE )
RETURN
FUNCTION Write_Trace()
/*************************/
LOCAL i, cParam
cParam := ''
FOR i = 1 TO pcount()
cParam := cParam + ' ' + STRVALUE(HB_PValue(i)) + ' '
NEXT
FWRITE(hTRACE, TIME() + ' ' + ALLTRIM(cParam) + CRLF )
RETURN
Open_Trace()
Write_Trace('something', 1, date(), '123')
...
Close_Trace()
Re: MsgDebug() -> Logfile ?
Posted: Fri Feb 19, 2021 9:26 am
by edk
AUGE_OHR wrote: ↑Thu Feb 18, 2021 5:49 pm
hi,
i often use MsgDebug() but that "stop" App
is there a harbour / HMG Way to get Message in a Logfile
Here is the solution that I personally use - just use LogDebug() instead of MsgDebug()
The log file will be created incrementally in the same folder and name as the executable file with
__ log__ extension.
Code: Select all
#include <hmg.ch>
Function Main()
Local i
SET DATE TO ANSI
SET CENTURY ON
Msginfo( 'Begining ... Be patient, it will take about 4 seconds.')
FOR i := 1 TO 20
LogDebug (i, time(), 'Some string #' + Str(i) )
hb_idleSleep( 0.2 )
NEXT i
IF MsgYesNo ( 'Finished. Do you want to view the log file ?')
MsgInfo ( hb_MemoRead ( LogDebug() ) )
ENDIF
RETURN
*****************************************************************************
FUNCTION LogDebug
Local i, cMsgLog, nMax := PCount(), cLogFile, cPath, cAppFileName, cTimeStamp := hb_TtoC ( hb_DateTime() ) + ' '
hb_FNameSplit( hb_ProgName(), @cPath, @cAppFileName )
cLogFile := hb_FNameMerge( cPath, cAppFileName, '__log__' )
IF nMax >0
cMsgLog := cTimeStamp + 'Called from: ' + ProcName(1) + '(' + AllTrim( Str( ProcLine(1) ) ) + ') --> ' + ProcFile (1) + hb_eol() + Space ( Len (cTimeStamp ) )
FOR i := 1 TO nMax
cMsgLog += hb_ValToExp ( PValue (i) ) + IF(i < nMax , ', ' , '')
NEXT i
StrFile( cMsgLog + hb_eol() , cLogFile , .T. )
ENDIF
RETURN cLogFile
Note: if you want to clear the log file, just delete it beforehand, for example: DeleteFile ( LogDebug () )
If you want to have both messages (on screen and into log file) just call LogDebug (MsgDebug ( some params ) )
Re: MsgDebug() -> Logfile ?
Posted: Sat Feb 20, 2021 5:27 pm
by Anand
You can also use HMG inbuilt function "_LogFile()"
example:
_LogFile(.t.,time(), CRLF+cDataTxt)
this will create "_MsgLog.txt" file.
Regards,
Anand
Re: MsgDebug() -> Logfile ?
Posted: Sat Feb 20, 2021 9:49 pm
by edk
Anand wrote: ↑Sat Feb 20, 2021 5:27 pm
You can also use HMG inbuilt function "_LogFile()"
example:
_LogFile(.t.,time(), CRLF+cDataTxt)
this will create "_MsgLog.txt" file.
Regards,
Anand
I have an error trying to use the _LogFile () function
hbmk2: Error: Referenced, missing, but unknown function(s): _LOGFILE()
There is, however, the hb_logfile class.
Re: MsgDebug() -> Logfile ?
Posted: Sat Feb 20, 2021 10:24 pm
by AUGE_OHR
edk wrote: ↑Sat Feb 20, 2021 9:49 pm
There is, however, the hb_logfile class.
i found something in c:\
MiniGUI\SAMPLES\BASIC\LogRdd\demo.Prg
// Request for LOGRDD rdd driver
REQUEST LOGRDD
where can i found more about LOGRDD

Re: MsgDebug() -> Logfile ?
Posted: Sun Feb 21, 2021 9:54 am
by Anand
edk wrote: ↑Sat Feb 20, 2021 9:49 pm
I have an error trying to use the _LogFile () function
It is in MiniGUI Extended.
I checked again in simple Hello World.
Code: Select all
/*
* Harbour MiniGUI Hello World Demo
* (c) 2002-2009 Roberto Lopez
*/
#include "minigui.ch"
PROCEDURE Main
_LogFile(.t.,time(), 'Hello World!')
DEFINE WINDOW Win_1 ;
CLIENTAREA 400, 400 ;
TITLE 'Hello World!' ;
WINDOWTYPE MAIN
END WINDOW
Win_1.Center
Win_1.Activate
RETURN
It works.
Regards,
Anand