• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Logging

 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
sunglasses are a type of coolness prosthetic. Check out the sunglasses on this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic