Menu

#8 Remove use of printf/cout/cerr

open
3
2007-04-22
2007-04-22
No

In most cases the use of printf, fprintf, cout and cerr is wrong and one of the abstractions, Alert, LOG, DEGBUG, should be used instead. We should make an effort to remove printf, fprintf, cout and cerr wherever it is not supposed to be used to increase portability. Also we should avoid using them in the future. I've committed a script in src/checkoutput.sh that can be used to find offending constructs.

Discussion

  • Erik Ytterberg

    Erik Ytterberg - 2007-05-08

    Logged In: YES
    user_id=861147
    Originator: NO

    What are the side effects of Alert, LOG, DEGBUG besides printing the message? I can think of a FATAL construct that prints a message and quits, or is this where Alert should be used? What are the conventions for using any of these? Which requires log4cxx? While I am at it, which version of log4cxx is required? What are the conventions for log levels? How do I specify log group? How do I turn on specific log groups?

     
  • Daniel Aarno

    Daniel Aarno - 2007-05-11

    Logged In: YES
    user_id=330479
    Originator: YES

    Alert are used for messages that are directed to the user. For example to notify the user that a resource could not be found and the application must quit. There are three different alert levels, MESSAGE, WARNING and ERROR. A message is an informative message, a warning is to notify the user that something is not as it should be but the application will continue to the best it can, an error message should be followed by application termination. The rational behind the Alert class is that it can be easily modified to provide alerts in the users natural environment, (i.e. for mac and win users that does not run the program from a terminal application) by popping up dialog boxes etc. Alert does not depend on log4cxx. The debug and log functions requires log4cxx if they are to output anything. DEBUG is actually just a log message that is disabled if NDEBUG is set when compiling. Log4cxx works with hierarchical loggers, the most common way in MW is to use unit loggers, i.e. a log group per source file, but any courser or finer grained logging is possible as well. Using unit loggers a couple of macros are available to make logging a bit smoother. For example to set a unit logger do: SET_UNIT_LOGGER(net.sourceforge.metalwarriors.UNIT_NAME) in global scope within a file UNIT_NAME.cc, you can then use the LOG and DEBUG macros. For more info on levels etc see the DebugFunctions.h file. The log4cxx version to use is the current CVS version. Logging is configured through a configuration file that can be specified on the command line, see log4cxx docs for more info.

     

Log in to post a comment.

MongoDB Logo MongoDB