DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Debug log

  1. #1
    Join Date
    May 2006

    Question Debug log

    As a general rule when I start a new application in Borlands C++ Builder I create a macro like this:

    #define L(X)    cLog->Items->Add("["+TimeToStr(Time())+"] "+Sender->ClassName()+"::"+AnsiString(X))
    And I've added a TListBox to the active form I can make invisible or just delete and redifine my macro to a dummy, If I dont want the log in the final program.

    I'ts helped me tons of times, but I've heard that it's bad practise to use macros, so what would you suggest to do?

  2. #2
    Join Date
    Nov 2003
    First of all, you realize that your code isn't portable, right? So thi stechnique is restricted to VCL exclusively.
    A more portable (and macro free) approach would define a debug class that overloads the function call operator with several overloaded versions. This will enable you to pass seemingly random types of values to this object and have them displayed on the screen or stored in a file. You can also use the RAII idiom to embed a debug object in every function, loop or block and make sure that its destructor prints all the necessary information, unless the debug infor is disabled (say by using environment variables, the DEBUG constant etc.)
    Danny Kalev

  3. #3
    Join Date
    Dec 2003
    I just made a function that i call jprintf() that is defined to do nothing in release code via #defines (much like assert) -- it is basically printf but it also echos it to a file for a log. Most compilers seem to have a defination for debug and release modes anyway, so you don't need an extra #define if you tap the existing one.

  4. #4
    Join Date
    May 2006
    Yeah offcouse it isnt portable (maybe CLX) and that is a major drawback.

    Designing a class for debug and logging has crossed my mind once or twice, but I never really get myself around to do so, but I guess including a "smart" template design or simply overloading functions for diffrent data types would be as sufficient, eg. would allow me to type lesser code to debug in the feature.

    jonnin yea I used to have a function like that but I got tired of having to parse too much info to that function that it really could find on it's own, and using macros was what I'm trying to get away from in the first place.

    I'll see if I can write a class like what Danny is proposing to include in all of my projects that way I can hold him responsable when my lousy code blows up in my face :D no sry bad danish humor. Well if it's not too big I'll post it here so we can discus it (yes yes, I know flame it).

Similar Threads

  1. Java Mail Error
    By ddsuresh in forum Java
    Replies: 1
    Last Post: 12-29-2005, 10:58 AM
  2. restoring transaction log files
    By amy in forum Database
    Replies: 0
    Last Post: 07-22-2002, 03:38 PM
  3. Transaction log - full ?
    By James McGrath in forum Database
    Replies: 0
    Last Post: 09-06-2001, 10:13 AM
  4. Truncate Log ?
    By Ruaidhri in forum Database
    Replies: 2
    Last Post: 12-20-2000, 11:56 AM
  5. Viewing Transaction Logs
    By Kristin Piskulic in forum Database
    Replies: 2
    Last Post: 05-02-2000, 03:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center