Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

queries about logging in swing

 
Raviteja Penki
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,

i have some queries in swings with logging.
i am using my own formatter and a simpleformatter for console and file handlers respectively.
the main idea is, on console i want to display just the message but not the method name, class name, date etc..
but in the file it should print as general message.

eg: let the message like this
"Sep 5, 2012 3:00:07 PM com.temenos.sizing.LoginPage jButton2ActionPerformed
INFO: Please enter Username and Password"

so on console it should print like "Please enter Username and Password"
where as in the file its like original message.

i modified those classes as per the requirement.

problem:
1. i tried to assign a properties file like this "System.setProperty("java.util.logging.config.file", f.getAbsolutePath());"
but it's not working.

the properties file content is .

handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler

com.temenos.sizing.level = FINE

#properties for ConsoleHandler
java.util.logging.ConsoleHandler.formatter = com.temenos.sizing.CustomFormatter
java.util.logging.ConsoleHandler.level = INFO

#properties for FileHandler
java.util.logging.FileHandler.formatter = com.temenos.sizing.SizingSimpleFormatter
java.util.logging.FileHandler.pattern =..//log//sizingLog%g.log
java.util.logging.FileHandler.limit = 5000000
java.util.logging.FileHandler.count = 10
java.util.logging.FileHandler.append = true
java.util.logging.FileHandler.level = FINE


2. so i tried to give implicitly like below


but the output is like

onconsole:
login page
Sep 5, 2012 4:51:15 PM com.temenos.sizing.LoginPage <init>
INFO: login page

infile: same as original message


if you do not understand, please go through once

so can you guys please tell me where did i do mistake?

awaiting for responses
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
First of all, it is Swing and not swings: SwingIsAProperNoun

Secondly, this question has nothing to do with swing. I am moving this to the "Other JSE/JEE APIs" forum where such issues are generally discussed.
In future, carefully choose the correct forum to get quick and correct responses.
 
Raviteja Penki
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry for those mistakes.

i did use the same mechanism in some other core java application. it is running fine.
that's y i thought this as a SWING issue.so posted here.
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raviteja Penki wrote:i did use the same mechanism in some other core java application. it is running fine.
that's y i thought this as a SWING issue.so posted here.

In that case, take out that logging code and create a simple app (called SSCCE) and run it. If that reproduces the problem, you can see that it is not related to swing. Plus, you can use that small app to actually fix the issue and then move back the fix to the original application.
 
Raviteja Penki
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as per your advice, i had created a simple app
here also i'm getting the same issue.
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There you go. So, it is not related to Swing. First problem solved.

Can you post that simple code? That will make it easier for people here trying to help you.
 
Raviteja Penki
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is the cpde

//this class is to just print a log message



//this class is to set logger properties


//user defined formatter
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "getLogger" method is going to be called more than once, isn't it? Potentially thousands of times, I would expect. So it shouldn't be doing any of that setup processing.
 
Raviteja Penki
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in this case it's only one time right?.

"private Logger classLogger = Helper.getInstance().getLogger(this.getClass().getName());"

this is the only point, where we calling.

right after the main method it's trying to initialize the logger variable.

by using that variable. i'm trying to display the message.
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code is working fine actually. You get that extra logging message because, by default the jvm properties installs a ConsoleHandler with its own format (this is for the global logger).
If you comment out the entire try/catch block in getLogger, you will see that a message is still printed in the console. That is the default one.
(you can also check the logging.properties in your jvm path to understand this).

If you don't want the default one to appear, add this:
classLogger.setUseParentHandlers(false);

And btw, why are you catching NPE? This is a very bad programming practice.
 
Raviteja Penki
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its working, thank you

why am i unable to set the propertyfile
[code/java]System.setProperty("java.util.logging.config.file", f.getAbsolutePath());[code]

f.getAbsolutePath() contains the properties file path.

if i'm trying to do this,its automatically setting to the defalut logging.properties under java.
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, you're welcome.

I would suggest you make a call to f.exists() before that line. That should give you some clue.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic