Append to Log File
Moderator: Rathinagiri
-
melliott42
- Posts: 119
- Joined: Wed Feb 18, 2009 2:14 pm
Append to Log File
Hello,
What is the easiest way in xHarbour\HMG to append to a line to a log file?
Thanks,
Michael
What is the easiest way in xHarbour\HMG to append to a line to a log file?
Thanks,
Michael
Re: Append to Log File
I'm writing to log files with my InfoMssg function:
Code: Select all
------------------------------
procedure InfoMssg
parameters info, NrLog
private plik_id, ObRob, k, p1:="", p2:=""
default NrLog to 1
eol := chr(13)+chr(10)
LogFile := cPathToLogFiles
if NrLog = 1
LogFile += "diary.msg"
elseif NrLog = 2
LogFile += "tango.msg"
elseif NrLog = 3
LogFile += "viking.msg"
endif
if !file(LogFile)
plik_id = fcreate(LogFile,0)
else
plik_id = fopen(LogFile,2)
endif
fseek(plik_id,0,2)
fwrite(plik_id,"---"+eol)
fwrite(plik_id, dtoc(date())+" "+time()+;
" Op."+str(opnr,1)+" "+alltrim(OpNaz))
fwrite(plik_id,eol+" "+INFO+eol)
fclose(plik_id)
return
-
melliott42
- Posts: 119
- Joined: Wed Feb 18, 2009 2:14 pm
Re: Append to Log File
Marek,
Very nicely done. Thanks for posting.
Michael
Very nicely done. Thanks for posting.
Michael
- esgici
- Posts: 4543
- Joined: Wed Jul 30, 2008 9:17 pm
- DBs Used: DBF
- Location: iskenderun / Turkiye
- Contact:
Re: Append to Log File
Code: Select all
HB_MemoWrit( <cLogFileName>, MemoRead( <cLogFileName> ) + <cStringToAppend> ) Viva INTERNATIONAL HMG 
-
melliott42
- Posts: 119
- Joined: Wed Feb 18, 2009 2:14 pm
Re: Append to Log File
esgici,
>> HB_MemoWrit( ... )
I love you man!
>> HB_MemoWrit( ... )
I love you man!
- esgici
- Posts: 4543
- Joined: Wed Jul 30, 2008 9:17 pm
- DBs Used: DBF
- Location: iskenderun / Turkiye
- Contact:
Re: Append to Log File
MemoWrit() add EOF (end of file marker = CHR( 26 ) ) at end of file, HB_MemoWrit() not.
Viva INTERNATIONAL HMG 
Re: Append to Log File
I think, the problem may occurs whe the log file is too big. The way presented by Esgici causes all log file is read to memory and after that saved on disk.
Maybe my mind is determined by older DOS and Windows delimiters???
Best regards, Marek
Maybe my mind is determined by older DOS and Windows delimiters???
Best regards, Marek
- danielmaximiliano
- Posts: 2647
- Joined: Fri Apr 09, 2010 4:53 pm
- Location: Argentina
- Contact:
Re: Append to Log File
Hola melliott:
una posible solución sobre los archivos LOG es crear una aplicacion que lea la estructura del mismo, ese mismo archivo log tiene que tener una estructura pensada para poder manejar dicha informacion, como ser fecha, tipo de LOG y el LOG de datos.
al estar fechado tendrias un manejo eficiente de la informacion que guardarias en el archivo LOG busqueda por fecha, entre fechas, por tipo de LOG o datos.
ahi no tendrias problema con el tamaño del archivo LOG
Transalte Google
Hello melliott:
a possible solution on the log files is to create an application that read the same structure, same log file must have a structure designed to handle such information, such as date, type of LOG and LOG data.
the date would be effective management of the information you stored on the LOG file search by date, including dates, type of log or data.
there would have no problem with the size of log file
DaNiElMaXiMiLiAnO
una posible solución sobre los archivos LOG es crear una aplicacion que lea la estructura del mismo, ese mismo archivo log tiene que tener una estructura pensada para poder manejar dicha informacion, como ser fecha, tipo de LOG y el LOG de datos.
al estar fechado tendrias un manejo eficiente de la informacion que guardarias en el archivo LOG busqueda por fecha, entre fechas, por tipo de LOG o datos.
ahi no tendrias problema con el tamaño del archivo LOG
Transalte Google
Hello melliott:
a possible solution on the log files is to create an application that read the same structure, same log file must have a structure designed to handle such information, such as date, type of LOG and LOG data.
the date would be effective management of the information you stored on the LOG file search by date, including dates, type of log or data.
there would have no problem with the size of log file
DaNiElMaXiMiLiAnO
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*
Saludos / Regards
DaNiElMaXiMiLiAnO
Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*
Saludos / Regards
DaNiElMaXiMiLiAnO
Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
- esgici
- Posts: 4543
- Joined: Wed Jul 30, 2008 9:17 pm
- DBs Used: DBF
- Location: iskenderun / Turkiye
- Contact:
Re: Append to Log File
You are right.mol wrote:I think, the problem may occurs whe the log file is too big. The way presented by Esgici causes all log file is read to memory and after that saved on disk.
Maybe my mind is determined by older DOS and Windows delimiters???![]()
As far as I remember, in DOS, limit of MemoRead() and MemoWrit() was 64K, because this is max length of a string.
In windows (and Harbour of course) that barriers already broken; I had tested bigger than 64K and strings in many way and didn't noticed any problem.
Surely, anything can't be limitless, and all of these considerations must have their own limits. At least, virtual memory manipulation of Windows may will be extremely slow down, though it isn't crashed.
Anyway, the file is big or not, we haven't read (take into memory) whole file for adding a single line (or some lines) at end of it
In this case we have another possibility :
Code: Select all
FILEAPPEND( cSrc, cDest )So, we can do somethings like :
Code: Select all
cTempFileName := "MyTempFile.log" // or we may use hb_fsCreateTemp() or hb_fsCreateEx()
HB_MemoWrit( cTempFileName, <cStringToAppend> )
FILEAPPEND( cTempFileName, <cLogFileName> )
ERASE (cTempFileName)In other hand, I never used FILEAPPEND(). So please use carefully, test adequately and please inform me too about your experiences
Regards
--
Esgici
Viva INTERNATIONAL HMG 
- esgici
- Posts: 4543
- Joined: Wed Jul 30, 2008 9:17 pm
- DBs Used: DBF
- Location: iskenderun / Turkiye
- Contact:
Re: Append to Log File
And ...
The opinion of Daniel may be good choice.
If you haven't any compelling reason to use text file format for your log file, using table based log file may be more appropriate; at least without these append matters.
Regards
--
Esgici
The opinion of Daniel may be good choice.
If you haven't any compelling reason to use text file format for your log file, using table based log file may be more appropriate; at least without these append matters.
Regards
--
Esgici
Viva INTERNATIONAL HMG 