Title: Easy logger
Question: very often we have Logs to keep track of processes and/or errors, some times we have the logs displaying on screen using TMemo or TRichEdit and you often have to watch for logfiles too large as they might consume your memory...
Answer:
I created a procedure just to make life easier when loggin the common stuff, instead of using code like:
MyLogMemo.Lines.Add('an event just happened!');
or
MyRichEdit.Lines.Append('Windows is crashing...')
etc...
I have this procedure, which I have on my "goodies.pas" unit (togheter with my setstatusbar procedure)
Procedure Log(S:String; LogTo:TStrings; Const MaxLogSize:Integer; Const AddTime:Boolean=True; Const OnlyTime:Boolean=True);
Var X:Integer;
Begin
  If (AddTime) Then
    If (OnlyTime) Then
      S:=FormatDateTime('hh:mm - ', Now)+S
    Else
      S:=FormatDateTime('mm/dd hh:mm - ', Now)+S;
  LogTo.Append(S);
  If (LogTo.CountMaxLogSize) Then
    For X:=0 To (LogTo.Count-(MaxLogSize Div 10)) Do
      LogTo.Delete(0)
End;
...there's 2 constants by default to TRUE
- addtime (go figure its use!)
- onlytime (take out the date)
so, when I need it, I just include my "goodies.pas"
uses goodies;
and call it like:
Log('AnyEvent', Memo.Lines, 1000)
or
Log('whatever', MyLogFile, 1000)
hope this is useful
by the way, the source code of the article was formatted using my PAS 2 HTML converter
keep up coding
salu2
EberSys