• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using logging API

 
Mary John
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I was referring to Andrews book on Logging. I saw that the code has the following:
private Logger log = Logger.getLogger("sampleproject.db"); // Log output
and then in each method like read, update....etc
log.entering
log.exiting

But this does not produce anything on the console,
I understand that the default log levels above INFO are only displayed

My question is what might be the purpose of having entering and exiting in the code without having either a FileHandler to write out the messages or else the level not being set to ALL anywhere in the Class(so that all messages could be displayed on console) where these methods like read etc are defined.


Did you choose to log all the messages to a file? or displayed on console

Did you have many files where you log messages?




Thanks
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, Mary.

Well, I know that this isn't really what you're looking for, but... do you want a tip? Don't use any logging functionality. It was not required. And maybe, implementing this will result in a lower score. Maybe they can say "oh, she used log.info(), but should have used log.debug(): -1 here!", or something like that... there may be problems that you are not expecting... in a nutshell: if it was not required, we better not do it.
Just a small tip.
[ April 14, 2008: Message edited by: Roberto Perillo ]
 
Mary John
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.

But then I have another question.

How did you test your application without logging? Did you have print
statements inside your methods? If so, did you still keep them as such
when you submitted the assigment? or did you delete all print statements?
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, ok. You're testing your application. Honestly, I just finished my application, and now I'll have to test it, and document it as well. I'll define my testing strategy on the next couple of days, but logging sounds good too. But, if I go for logging for my testing strategy, I'll take it off completely before submitting my project, for sure.
 
Mary John
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Roberto

BTW, I havent completed the application yet, well actually not anywhere near completion, and have a long way to go. I am testing each method before I go on to the other method.

Your idea seems good, from the SCJD point of view. I am still searching the forum to see what lots of others have done.
 
John Donoghue
Ranch Hand
Posts: 45
IntelliJ IDE Mac OS X Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mary,

I have submitted, but not yet received a decision, so take this with an appropriate grain of salt.

After a long-bit of thrash (including a post to the forum that Andrew responded to), using loggin and leaving it in. I finally settled on just using "entering" messages; I felt that entering and exiting was just too much. My methods are generally short enough that knowing where it entered before blogin up allowed me the info I needed for debugging (by changing the level of the base logger). There is also a method setUseParentHandlers() that allowed me to either opt a particular class' logger in or out of loggin to the screen.

I also made sure that all exceptions were logged.

Much like unit testing, I found the real strength of logging to be not when I first wrote the code, but when I changed it. Then a broken test or some logging info suddenly showing up in the console let me I had a problem, quickly enough that it was very easy to track down the problem.

Hope that is of some help.

-John
 
Gilles Marceau
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Mary,

my assignment development phase is nearly over, and i use the J2SE Logging
feature. This is very usefull for the server part, when you are running some
JUnit test to check that you locking strategy works. I don't agree with the
argument that leaving log code could cost you points : if you use the
right level at the right place (and there is only 7 levels), there is no
way it could cost you points.
And i used the class full name as logger name :
private static Logger logger = Logger.getLogger(class.getCanonicalName());

Hope it helps,

Gilles
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this is a big discussion, where there is no right or wrong, and is clearly a desing choice. Whatever is yours, document it and justify your choice. But just for the records, I never said that using logging is right or wrong; it's just that I don't feel comfortable adding something that was not required, that's all.
[ April 15, 2008: Message edited by: Roberto Perillo ]
 
Mary John
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all, I feel more inclined to using logging. At present I am new to logging and now seeing many posts I am thinking of taking some extra effort to include it and see it if really helps.

if I dont find it that useful, I will just take it away from the code before submitting
 
Herman Schelti
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Mary,

I added logging in my assignment and it helped me find some errors.

Especially in the locking/unlocking section, when I started logging the name of the running thread.

Herman
[ April 15, 2008: Message edited by: Herman Scheltinga ]
 
Mary John
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again.

I have a question. Do you think this is a good way to log exceptions?

try{
throw new RecordNotFoundException();

}
catch(RecordNotFoundException e){

logger.log(Level.SEVERE, " Record Not Found :Read Record Method", e);
}

any opinions?

Thanks
[ April 15, 2008: Message edited by: Mary John ]
 
Herman Schelti
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Mary,

-I don't understand why you want to throw and catch an Exception in 1 method
-you are not logging you search criteria (probably recordnumber)

Herman
 
Mary John
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,

within the try block, I was actually just trying to show that some statements/methods might be called that throws RecordNotFoundException.

it should have been like

try
{
db.readRecord(900);
}
catch(RecordNotFoundException rnf)
{
log.severe("Record" + recNo + " does not exist, RecordNotFoundException occured");
}


I hope this might be an appropriate way to log exceptions??

thanks
 
Robert James Liguori
Author
Ranch Hand
Posts: 553
5
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the real world, you will be using the logging feature. So even though it's not required for the assignment and in theory could cost you points if you botch up it's implementation... mastering (and including) this API can only benefit you.

...just my thoughts.
 
rinke hoekstra
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Roberto Perillo:
Howdy, Mary.

Don't use any logging functionality. It was not required. And maybe, implementing this will result in a lower score. Maybe they can say "oh, she used log.info(), but should have used log.debug(): -1 here!", or something like that... there may be problems that you are not expecting... in a nutshell: if it was not required, we better not do it.
Just a small tip.



I'd have to disagree on this one. I used logging a lot. It helps yourself for debugging and finding errors, and in every serious program you will use logging. Sure it's not a must, but logging is very simple, and I can't imagine it will cost you points.
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rinke hoekstra:


I'd have to disagree on this one. I used logging a lot. It helps yourself for debugging and finding errors, and in every serious program you will use logging. Sure it's not a must, but logging is very simple, and I can't imagine it will cost you points.


This is your choice, and it was not required at all. Some developers choose to use it, and that's ok. There's no right or wrong here, it's just a choice. If you feel comfortable using it, go ahead, otherwise, just don't use it and it will be equally ok.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic