Error log location

Error log location

Postby rhlawek » Thu Jun 24, 2021 5:48 pm

I have an app, call it appname.exe, which has a font release error in it that results in a file named appname.log being written to the same folder as the executable, with contents such as this:

2021/06/24 13:37:37: EXCESS RELEASE OF FONT ARIAL[ hFont : 0] ( nCount : -1 )
<-TFONT:END(0) <-TBUTTON:DESTROY(0) <-TWINDOW:HANDLEEVENT(0) <-TBUTTON:HANDLEEVENT(0) <-_FWH(0) <-SENDMESSAGE(0) <-(b)TWINDOW(0) <-TMDICLIENT:SENDMSG(0) <-TMDICLIENT:CHILDCLOSE(0)

Fixing the error is simple, that's not my question, what I want to know is how do I redirect appname.log so that it writes to a folder of my choosing, and not in the default location alongside the executable itself?

Robb
User avatar
rhlawek
 
Posts: 193
Joined: Sun Jul 22, 2012 7:01 pm

Re: Error log location

Postby Antonio Linares » Thu Jun 24, 2021 7:40 pm

Rob,

Please implement this function in your main PRG and set the desired path:

Code: Select all  Expand view
function LogFile( cFileName, aInfo, lDate )

   local cMyPath := ".\"
   local hFile, cLine := "
", n
   DEFAULT lDate   := .T.
   if lDate
      cLine := DToC( Date() ) + "
" + Time() + ": "
   endif

   if ValType( aInfo ) != "
A"
      aInfo = { aInfo }
   endif

   for n = 1 to Len( aInfo )
      cLine += cValToChar( aInfo[ n ] ) + Chr( 9 )
   next
   cLine += CRLF

   if ! File( cMyPath + cFileName )
      FClose( FCreate( cMyPath + cFileName ) )
   endif

   if( ( hFile := FOpen( cMyPath + cFileName, FO_WRITE ) ) != -1 )
      FSeek( hFile, 0, FS_END )
      FWrite( hFile, cLine, Len( cLine ) )
      FClose( hFile )
   endif

return nil

regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Error log location

Postby rhlawek » Thu Jun 24, 2021 11:25 pm

Thank you Antonio, overriding the library function will work.

I already use these functions in my code to override other default logs locations for FWH apps:

SetErrorPath( cLogDir )
SetErrorFileName( "error.log" )

What I will do in my local copy of LogFile, instead of modifying the path this way:

local cMyPath := ".\"

I will instead modify it this way:

local cMyPath := SetErrorPath()

This way it will pick up the static path already being set with the call SetErrorPath( cLogDir )

This might be a change to consider making in the fivewin code.

Thanks again.

Robb
User avatar
rhlawek
 
Posts: 193
Joined: Sun Jul 22, 2012 7:01 pm

Re: Error log location

Postby rhlawek » Fri Jun 25, 2021 3:21 pm

Antonio,

How can I avoid the issue of the linker complaining that LogFile() already exists in a fivewin library? I'm used to having local code just supercede the library functions when there is a name conflict, but I haven't figured out how to get the linker to ignore this particular conflict.
User avatar
rhlawek
 
Posts: 193
Joined: Sun Jul 22, 2012 7:01 pm

Re: Error log location

Postby Antonio Linares » Fri Jun 25, 2021 4:53 pm

Dear Robb,

From FWH\samples\buildh64.bat

link @msvc.tmp /nologo /subsystem:windows /force:multiple

Yes, I agree with you, we are going to implement those functions as you have suggested :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 63 guests