MsgDebug() -> Logfile ?

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

MsgDebug() -> Logfile ?

Post by AUGE_OHR »

hi,

i often use MsgDebug() but that "stop" App
is there a harbour / HMG Way to get Message in a Logfile :idea:
have fun
Jimmy
User avatar
serge_girard
Posts: 3309
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: MsgDebug() -> Logfile ?

Post 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()
There's nothing you can do that can't be done...
edk
Posts: 998
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: MsgDebug() -> Logfile ?

Post 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 :idea:
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 ) )
User avatar
Anand
Posts: 596
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF

Re: MsgDebug() -> Logfile ?

Post by Anand »

You can also use HMG inbuilt function "_LogFile()"

example:
_LogFile(.t.,time(), CRLF+cDataTxt)

this will create "_MsgLog.txt" file.

Regards,

Anand
Regards,

Anand

Image
edk
Posts: 998
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: MsgDebug() -> Logfile ?

Post 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.
User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: MsgDebug() -> Logfile ?

Post 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 :idea:
have fun
Jimmy
User avatar
Anand
Posts: 596
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF

Re: MsgDebug() -> Logfile ?

Post 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
Regards,

Anand

Image
Post Reply