[brailleblaster] Re: Debugging

See my comments below:
On 28/02/11 11:21, John J. Boyer wrote:
The information on logging will be useful. I agree that it is easier to
put it in when writing the code than later. That is just like
localization. However, I wonder if logging will deal with what I have in
mind. For some reason people have had dificulty porting liblouis and
liblouisutdml for BrailleBlaster, though it has been done several times
in other contexts. So if the liblouisutdml library is absent I want the
word processor to advise that the braille facility is missing and to
give the user the option of continuing. If she choses to do so, the word
processor will operate normally, except that the only braille
translation available will be computer braille. This will be very
valuable for testing and for porting to new platforms.
<MW>This seems to have little to do with logging and I don't really see how it fits with your original question of a debug system property. Surely all this is business logic and UI stuff?</MW>


However, I have
encountered a situation in which liblouisutdml was present but couldn't
find one of its dependencies. In this case I want to see the message
from the UnsatisfiedLinkError exception. Can logging handle this
situation?
<MW>Logging can output any string. Particularly considering exceptions the following method of the Logger class may be worth looking at:
void log(Level level, String msg, Throwable thrown)
</MW>


If the library is completely absent I want the user to be
able to see what the word processor will do, but if it can't find a
dependency I want it to throw the exception.
<MW>Is it really wise to just throw an exception and let it bubble all the way up and bring the application down? A more useful thing to do would be to catch the exception at an appropriate level where you have a pretty good idea why it was thrown, give the user a friendly error message telling them what possibley is the issue in language they understand and then may be exit gracefully, letting the user sort it out/contact for further support if they cannot fix it. Even doing this you still can have the exception information output by appropriate logging.</MW>


It seemed to me that
-Ddebug-yes on the command line would enable me to do this.
<MW>I really don't see what it is doing, how it helps, etc. May be I haven't understood what your trying to do.</MW>


Of course,
I'll also check into including logging.

John

On Mon, Feb 28, 2011 at 10:36:24AM +0000, Michael Whapples wrote:
Might you really be wanting logging?

The java logging API in the JDK will probably be sufficient although
there are alternatives like log4j, etc.

Logging has much finer control over what error messages get output and
where they go (eg. levels like finest, finer, fine, config, info,
warning and severe). I think extra custom levels can be defined although
the documentation seems to advise against that unless really needed.

Also logging allows you to have multiple loggers which can be set to log
at different levels (eg. the documentation suggests a logger per class).

Also it is worth noting the following usage:

if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "Message to be logged");
}

While the log method of the Logger class will test if the level allows
logging out, the additional if statement may improve performance as it
saves any preparation to construct the message (eg. concatenation of
strings).

Configuration of the logging API can be done using system properties or
a properties file.

Also logging was mentioned before to you. Generally logging is easiest
to implement at the time of writing the code rather than to add it in later.

Michael Whapples
On 28/02/11 08:09, John J. Boyer wrote:
First, in response to Michael's last message, BrailleBlaster will
present the user with a dialog box asking if she wants to continue,
change settings read a startup tutorial, see a quick-start guide, etc.
Finallyt it will have a checkbox with the message "Do not show me this
message again."

On to debugging. Can I call BrailleBlaster with the command:

java -Ddebug=yes -jar brailleblaster.jar

and later have the code

String debug System.getProperty ("debug")

The immediate reason for this is that I catch the UnsatisfiedLinkError
exception if the liblouisutdml library is not found and set a boolean
for the rest of the program. However this error could also be caused if
one of its dependencies is not found. In this case I want to see the
message. There will certainly be other reasons for wanting a debug flag.

Thanks,
John



Other related posts: