aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Logging Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Logging" Watch "Logging" New topic
Author

Logging

Simon Ingram
Ranch Hand

Joined: Nov 30, 2003
Posts: 173
Hi,
I am following the instructions for logging provided in Max's Book (page 54) but still can't get the logging going. My system (Windows XP) provides the default INFO messages only. To confirm, I copied the file logging.properties from its location at c:\j2sdk1.4.1_03\jre\lib to a temp library, changed the extension from .properties to .txt, edited the file as suggested by Max i.e. increased the logging level from INFO to ALL, then I changed the name back to logging.properties, returned it to c:\j2sdk1.4.1_03\jre\lib after renaming the original logging.properties file to some other name. I added logging statements to my code (that is FINER level messages) and should now be ready to go, but alas still only the INFO level messages!
This should be a very simple process to implement, BUT I'M STUCK! HELP!
regards, Simon
Bill Robertson
Ranch Hand

Joined: Mar 21, 2003
Posts: 234
First off I would read and get to understand Suns Logging Overview and API. It has much more valuable information that
Max's book.
Second what is it your trying to accomplish with the logging? If you want
to send you messages to a file and store them there, which is a great way
to store exceptions for the project, you are going to have to take a different approach. So was your aim to just see if you could get what Max
was doing working, or do you have something specific you want to do with
your logging?
Simon Ingram
Ranch Hand

Joined: Nov 30, 2003
Posts: 173
Hi Bill,
Thanks for your reply and the links. In answer to your question, a bit of both. I wanted to direct some low level logging messages to an external file. Max suggested tinkering with the config file. The API documents for the LogManager class also suggest you can edit the properties file, so my question is very simple. How do you edit logging.properties? How do you even open it? You suggest I should be taking a different approach. Sure, I can do it dynamically. The API suggests that the LogManager uses two optional system properties:
"java.util.logging.config.class"
"java.util.logging.config.file"
This confuses me even more! I printed all the standard System Properties and these are not among them. When I try:
String s = System.getProperty("java.util.logging.config.class");
I get null! Clearly there is a gap in my understanding and I have to admit that even after reading the Logging Overview, I am still puzzled over these two points.
Regards,
Simon
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
For implicity, if you read section 2.3 in the above article.
http://java.sun.com/j2se/1.4.2/docs/guide/util/logging/overview.html#2.3
You can see that, the global setting can be overrided inside the program.
In my implementation, I did not make use of the logging.properties file, and I did not change any setting of it.
I simply create my own FileHandler, and redirects all logging msg to that handler, and that handler creates log files in the current directories.
Hope this help.
Nick.


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Simon,
About the use of the system property "java.util.logging.config.file", this thread may help you.
Best,
Phil.
Bill Robertson
Ranch Hand

Joined: Mar 21, 2003
Posts: 234
I am with Nicholas. I wanted to capture exceptions and other important
messages and send them to appropriate log files. To do this I create a
logging directory. I then placed my log files in the directory, and then send messages to my log files rotating every three times they are used. I did not mess around with any properties in that I could get
what I wanted by simply using a FileHandler and SimpleFormatter to write all
of my exceptions, exception stack traces, messages,Levels...to the log files
in the format and order and wished.
Messing around to much with the properties still seems a little hairy. IMO
Simon Ingram
Ranch Hand

Joined: Nov 30, 2003
Posts: 173
Thanks for the link, Phillippe. That's one hell of a detailed discussion on logging! For the exam, I guess Nicholas and Bill have the right idea, but clearly you like to play with the technology! The question I have with your approach is that if you set up a series of config files and assign them using the System Property "java.util.logging.config.file" at the command line, then you have to do this separately for each class/program.
I would like to be able to set up various config files, then at the command line, assign one of the config files to all the classes in my package, then run a test. After this I could switch config files at the command line and run the test again with a different logging arrangement. The problem for me is that at the command line you can only assign a config file to ONE class, not the package. This seems a great shame and I have a feeling there must be a way to do it. Any ideas?
regards,
Simon
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Simon,
then you have to do this separately for each class/program.

*One* logging config file is used for all your classes and packages. In the thread I mentioned above, I give an example of such a file's content (post dated October 24, 2003 12:31 AM).
Best,
Phil.
Simon Ingram
Ranch Hand

Joined: Nov 30, 2003
Posts: 173
Thanks Phil,
I read the link and your entry for 24 Oct 2003 12:31. I guess I was thrown by the syntax. I assumed:
java suncertify.Run server
was the same as:
java suncertify.Run.server
where server is the class you are running and Run is a directory within directory suncertify! In other words you have to assign the config file each time you wish to run the class server. Judging by your last remark and looking at it again now, it is clear that the dot between Run and server makes a lot of difference! Does your syntax mean that Run is the class and server is an arguement? Forgive my ignorance, you can probably tell that I'm fairly new to this.
regards,
Simon

java -cp . -Djava.util.logging.config.file=c:\scjd\serverlog.properties suncertify.Run server
Simon Ingram
Ranch Hand

Joined: Nov 30, 2003
Posts: 173
Phil,
Forget my last comment. The syntax is clear. But you do have to assign the config file on each command line invocation of Run (or any other class in the suncertify package) but this is no problem.
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
Hi Simon,
just as a FYI, if you're developing in windows with jdk 1.4, there are actually two logging.properties files. One's where you think it should be, and the other is under C:\ program files\Java\j2re1.4XXX\lib. Chances are, you need to modify the second one.
However, for the SCJD, I would suggest that you not log to a file. Logging's not required (even as it's very nice), and doing file IO is just one more thing that might go wrong. Since you've paid a lot of money for the exam, and you won't get a chance to defend against unexpected or unreasonable errors, I wouldn't risk it.
All best,
M
[ December 18, 2003: Message edited by: Max Habibi ]

Java Regular Expressions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Logging