Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.clipper.visual-objects > #5431 > unrolled thread

Add text to logfile

Started byRob van Erk <erk.v@hotmail.com>
First post2013-07-01 12:44 -0700
Last post2013-07-02 21:12 +0200
Articles 8 — 6 participants

Back to article view | Back to comp.lang.clipper.visual-objects


Contents

  Add text to logfile Rob van Erk <erk.v@hotmail.com> - 2013-07-01 12:44 -0700
    Re: Add text to logfile JohnMartens <martens@tennishulp.info> - 2013-07-01 22:15 +0200
      Re: Add text to logfile Rob van Erk <erk.v@hotmail.com> - 2013-07-01 21:04 -0700
    Re: Add text to logfile Mathias <mathias.hakansson@consultec.se> - 2013-07-01 22:25 -0700
      Re: Add text to logfile Malcolm G <malcolm-news2012delete@delete.jobstream.com> - 2013-07-02 10:07 +0100
    Re: Add text to logfile "Valery N." <mustangsoftcom@gmail.com> - 2013-07-01 23:29 -0700
    Re: Add text to logfile Rob van Erk <erk.v@hotmail.com> - 2013-07-02 10:44 -0700
      Re: Add text to logfile D.J.W. van Kooten <public@ic2remove.this.com> - 2013-07-02 21:12 +0200

#5431 — Add text to logfile

FromRob van Erk <erk.v@hotmail.com>
Date2013-07-01 12:44 -0700
SubjectAdd text to logfile
Message-ID<1d052544-284b-4137-9b29-e4d68829b576@googlegroups.com>
Is there an easy way to add text to a log(txt) file? I want to use a logfile in my program but every time I use Writeline (or other) it looks like the text is written at start of existing logfile. I simply want to add text to a logfile, not replace text. Seems to me I have to open the file (Fopen2) and point cursor to last row before writing but sure how to do this.

Thanks,
Rob

[toc] | [next] | [standalone]


#5432

FromJohnMartens <martens@tennishulp.info>
Date2013-07-01 22:15 +0200
Message-ID<kqsnn1$opp$1@dont-email.me>
In reply to#5431
cMemo := MemoRead(cLogFileNm)
cMemo += cAddition
MemoWrit(cLogFileNm,cMemo)



Op 1-7-2013 21:44, Rob van Erk schreef:
> Is there an easy way to add text to a log(txt) file? I want to use a logfile in my program but every time I use Writeline (or other) it looks like the text is written at start of existing logfile. I simply want to add text to a logfile, not replace text. Seems to me I have to open the file (Fopen2) and point cursor to last row before writing but sure how to do this.
>
> Thanks,
> Rob
>

[toc] | [prev] | [next] | [standalone]


#5433

FromRob van Erk <erk.v@hotmail.com>
Date2013-07-01 21:04 -0700
Message-ID<99006c01-664d-4938-a1d8-c993f0d964a5@googlegroups.com>
In reply to#5432
Great ! Thanks.

[toc] | [prev] | [next] | [standalone]


#5434

FromMathias <mathias.hakansson@consultec.se>
Date2013-07-01 22:25 -0700
Message-ID<cff71901-9a4c-44ea-a30c-219e56a91483@googlegroups.com>
In reply to#5431
Hi Rob,

If you want it to be fast even when the log-file has grown to several Mb you should do like this instead:

---------------------------------------
procedure LogWrite(newLogRow as string)
local fh as ptr
local fp as dword

if File(filename)
	fh := FOpen(filename,FO_READWRITE)	// Open
else
	fh := FCreate(filename)			// Create
endif

if fh == F_ERROR
	InfoBox{,"Error","Could not open " + filename + "!"}:Show()
	return
endif

fp := SetFilePointer(fh,0,null_ptr,FILE_END)

FWriteLine(fh,newLogRow)

CloseHandle(fh)
-------------------------------

/Mathias

Den måndagen den 1:e juli 2013 kl. 21:44:14 UTC+2 skrev Rob van Erk:
> Is there an easy way to add text to a log(txt) file? I want to use a logfile in my program but every time I use Writeline (or other) it looks like the text is written at start of existing logfile. I simply want to add text to a logfile, not replace text. Seems to me I have to open the file (Fopen2) and point cursor to last row before writing but sure how to do this.
> 
> 
> 
> Thanks,
> 
> Rob

[toc] | [prev] | [next] | [standalone]


#5436

FromMalcolm G <malcolm-news2012delete@delete.jobstream.com>
Date2013-07-02 10:07 +0100
Message-ID<pLwAt.13103$c52.8844@fx22.am4>
In reply to#5434
> fp := SetFilePointer(fh,0,null_ptr,FILE_END)

Interesting - I normally use
      FSeek3(hf, 0, FS_END)
which I suspect calls SetFilePointer

[toc] | [prev] | [next] | [standalone]


#5435

From"Valery N." <mustangsoftcom@gmail.com>
Date2013-07-01 23:29 -0700
Message-ID<74f26e5e-469b-4617-90dc-f6bc33ab4202@googlegroups.com>
In reply to#5431
In CA-Vo 2.8 use the class LogFile{}.
But, it is possible to make also and own class.

[toc] | [prev] | [next] | [standalone]


#5438

FromRob van Erk <erk.v@hotmail.com>
Date2013-07-02 10:44 -0700
Message-ID<cd7beab0-9d7b-4c0d-a0ad-087d919a795b@googlegroups.com>
In reply to#5431
Thanks to all :-) 

[toc] | [prev] | [next] | [standalone]


#5439

FromD.J.W. van Kooten <public@ic2remove.this.com>
Date2013-07-02 21:12 +0200
Message-ID<8f96t8pm2fq9i47ajuub78p7ivnr5ngqpv@4ax.com>
In reply to#5438
On Tue, 2 Jul 2013 10:44:26 -0700 (PDT), Rob van Erk
<erk.v@hotmail.com> wrote:

Hello Rob,

Here's a general function where lAppend determines new or overwritten
files:

FUNCTION WriteString2File(cFile AS STRING,cString AS STRING,lAppend AS
LOGIC) AS STRING
//#s General method to write cString in cFile
	

LOCAL pszBuff AS PSZ
LOCAL ptrHandle AS PTR
	
//Default(@lAppend,FALSE) //	Append to file added 12-4-2005

	IF IsNil(cFile) .OR. IsNil(cString) // Apparently possible
26-7-2007
		RETURN "ERROR"	
	ENDIF
		
	IF File(cFile)
		IF !lAppend
			IF .NOT. FErase(cFile) // Removed string2psz
14-12-2007
				RETURN  DosErrString(FError())
			ENDIF
		ENDIF
	ENDIF
	SetAnsi(TRUE) // Make sure we write aan ANSI string 24-2-2011
	pszBuff := String2Psz(cString) // psz converted data
	IF !File(cFile) // Create only if not already there = always
in overwrite mode, only when new in lAppend mode
		ptrHandle := FCreate2(cFile, FC_NORMAL)
	ELSE // Already there, append
		ptrHandle := FOpen(cFile, FO_READWRITE + FO_COMPAT)
		FSeek (ptrHandle, 0, FS_END)
	ENDIF	

	IF ptrHandle != F_ERROR
		FWriteText(ptrHandle, cString,SLen(cString)) //
Changed 27-6-2007
		// FWriteText(ptrHandle, pszBuff) // actively removes
the length information that could allow the functions to continue
after the  character zero.>NG 25-6-2007
	ELSE
		IF ReturnVar("LUSEADS") // Correct SetAnsi for ADS
			SetAnsi(FALSE)
		ENDIF				
		RETURN "ERROR"	
	ENDIF
	IF lAppend // On append: add new line 22-8-2005
		FWriteText(ptrHandle, String2Psz(crlf))
	ENDIF	

	IF ReturnVar("LUSEADS") // Correct SetAnsi for ADS
		SetAnsi(FALSE)
	ENDIF				
		
	IF !FClose(ptrHandle)
		RETURN DosErrString(FError())
	ENDIF
RETURN "" 	

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.clipper.visual-objects


csiph-web