• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Logging

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ranchers,

I'd like to share my logging approach with you and see if it is any good.

I decided to use java logging utility not only as a handy debugging tool, but also as a part of my final application. So, once the app is ready, all errors and warnings should be logged into a "suncertify.log" file in a simple text format.

To support this I created a class in my db package with a static method getLogger(). This method takes a name of a logger as a parameter, and then dynamically changes the default settings (formatting, log file name, level etc) and returns the resulting logger. If an IO exception occurs, it returns a default logger as per logging.properties.

My initial thought was to go with a property file to be able change logger settings without having to recompile the code. But:
1. we are allowed only one property file
2. we can't ask examinator to change any files manually
3. our own logging.properties file can be only provided at run time, which would contradict requirements of starting the application

In my class I created a couple of constants - level, log file name, etc. which may be changed when the app is deployed. This way these properties may be relatively easily changed, but the code would still require to be recompiled.

What do you think about this direction for logging? I'd love to hear your thoughts!
[ February 13, 2006: Message edited by: Svitlana Dukhovna ]
 
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,

i successfully passed last year, so maybe it helps if i describe what i did:

i used java.util.logging, of course, what else. i used a strict logging policy for each log-comment i wrote in the code. so i took care that .info() is really only used for importat informative messages, while .severe() would only indicate real serious situtations and so on.

even though i used a .properties file during development, i was not allowed to submit one to sun, more or less the same as you describe. but i decided (and documented) to leave all logging in the code, which means that nothing below .info() gets logged (to standard-out).

should a motivated tester want to change this, he can put a properties file in the class path at any time...

i think i wrote a line about it this in my general considerations and got no deduction (say: full points) in this fields.

hope it help,
jan
 
Svitlana Dukhovna
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jan,

Thanks for your response. I am on a similar path as you in terms of leaving log statements in the code after deployment, and a strict policy for using log levels.

I don't like the default settings of the log file though. I know I can modify them as I like while developing, but once I submit, the examinator will see log statements on the console and the log file will be XML named java0. I want the application to output no statements on the console, but create a text log file in a current directory. I think it will give it a more professional flavor. To make this standard, I came up with what I described in my first post.

There aree 4 things "hardcoded" in my code for logging: Log level, file name, setting file handler to simple text and turning off/on of the console handler. What are the odds that someone might want to change these things when the application is deployed? If they suddenly want a log file in XML format, would not it mean some changes in the application as well? If standard info worning and error log messages are not enough, does not it mean there are bigger problems with the code and it needs to be changed, recompiled and redeployed as well?

What do you think about it? Thanks again for your help!
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Svitlana,

even though i understand your motivation i'd say that you are working beyond the scope of the assignment. and this brings you into trouble, because you still have to meet the requirements - no config files, no vm-arguments...

...which in some sort of chain-reaction leeds you to ugly design - hard-coded config settings.

from my judgement of the situation, i'd rather skip anything hardcoded. lets put it like this: if you have no way to set configuration variables, the cost of professionalizing your logging overweight the benefits.

that's my opinion, but hey, you asked :-)

many greetings from berlin,
jan
 
Svitlana Dukhovna
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jan!

After thinking over your approach, I decided to skip "hardcoding". You are right - it is not worth it, no matter how much I dislike the default settings.

Best wishes to you from Detroit!
 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Svitlana Dukhovna:
I know I can modify them as I like while developing, but once I submit, the examinator will see log statements on the console and the log file will be XML named java0.



I just had a look at my default logging.properties file, it says

By default we only configure a ConsoleHandler, which will only
show messages at the INFO and above levels.


I know there is an XMLFormatter mentioned in the default logging.properties file but it is not used ... by default
Or am I missing something

Regards,
Ronald Wouters
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes. the default log configuration we are refering to is not set through any (default) logging.properties files, but through some hard wired logic in the logging factory...

:-)
 
Svitlana Dukhovna
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep. Sorry about confusion guys.
 
reply
    Bookmark Topic Watch Topic
  • New Topic