delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
499 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi



Loremo - the 1.5 liter car coming in 2009




Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (0)


Easy loggerFormat this article printer-friendly!Bookmark function is only available for registered users!
log easily to TRichEdit, TMemo, or any TStrings descendant...
Product:
Delphi all versions
Category:
VCL-General
Skill Level:
Scoring:
Last Update:
03/22/2002
Search Keys:
delphi delphi3000 article borland vcl code-snippet log logger logging tstrings
Times Scored:
1
Visits:
2636
Uploader: Eber Irigoyen
Company: BTXSys
Reference: N/A
 
Question/Problem/Abstract:
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.Count>MaxLogSize) 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





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment













 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
S. Kucherov
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)