Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

Petr Turek

Greenhorn
+ Follow
since Jan 04, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Petr Turek

In my log4j properties, I've defined a rootLogger to log everything starting with WARN to a file, so I don't have to put logger.error(...) in every catch statement (the rootLogger catches the errors itself when they are thrown). But the problem is, that errors get logged multiple times. For example, when I throw an IOException, i get these two lines:

1:
ERROR (ApplicationDispatcher.java:687) - Servlet.service() for servlet action threw exception
java.io.IOException: dddd
(...stack trace)

2:
ERROR (StandardWrapperValve.java:253) - Servlet.service() for servlet jsp threw exception
javax.servlet.jsp.JspException: Exception forwarding for name index: java.io.IOException: dddd
(...stack trace)

And when I use a wrong key for bean:message tag (I use struts) the error is logged even 6 times. In short it looks like this:

ApplicationDispatcher.java:704) - Servlet.service() for servlet jsp threw exception
(InsertTag.java:922) - ServletException in '/tiles/body_search.jsp': Missing message for key "search..title"
(InsertTag.java:922) - ServletException in '/tiles/body_search.jsp': Missing message for key "search..title"
(ApplicationDispatcher.java:704) - Servlet.service() for servlet jsp threw exception
(ApplicationDispatcher.java:704) - Servlet.service() for servlet action threw exception
(StandardWrapperValve.java:253) - Servlet.service() for servlet jsp threw exception

The question is how can I assure that each error (incl. JspExceptions) will get logged only one time (with full trace)? Thanks for advice.
You can use a Jakarta POI HSSF.
Here's a tutorial: http://jakarta.apache.org/poi/hssf/quick-guide.html.
Is it possible to configure the properties that an appender will log only messages at one level, i.e. INFO? If I use (...).Threshold=INFO it also logs warns, errors and fatals, so is there a way to log only the info messages?

Thanks for help.
Hi All, I would like to have some questions about configuring FileAppenders wich I didn't find answers for anywhere.

1. Can I somehow access init parameters (defined in web.xml) from within the properties? Something like (...).File=${init[logFile]}. The goal is I would have all the settings in web.xml and if something changes, I wouldn't have to change it in these properties.

2. Can I define some settings (except the File) for a FileAppender in properties and the rest (the File) in the servlet? I would like to have logs for each document in a separate file (by ID), So I need to set the filename in the servlet. When I call logger.getAllAppenders, I get a null Enumeration.

3. If creating an appender within the servlet, can I somehow avoid the olbigation to close() the appender on the end of the servlet (I would have to add try-finally block to each servlet which I would like to avoid)? Because when I don't close the appender, it doesn't function properly. I tried to set the immediate flushing on true, but nothing changed.

Thank you very much everyone who could help,

Petr
Thanks very much, it works. I would have one more question on the topic of getting the locale. In jsp I have session, so I can access it to read the Locale, but what about in some servlet method with no request or session to use (assuming I don't want to pass them or locale itself to the method)? If I would call a method doSomething() from the action servlet and the method would look like:

public void doSomething() {
lang = /** get the language somehow */;
if (lang.equals("en")) {
//do something else
}
}

I can't get the locale from session or reqest, so is there some global value or anything else I could use?

Thank you again.
16 years ago
Hi.
Is there a way to get the selected locale-language in a struts bean? I would like to do something like:

<logic:equal name="lang" value="en">
English selected
</logic:equal>

<logic:notEqual name="lang" value="en">
Different language selected
</logic:equal>

Please note, that this is really simplyfied, I of course use MessageResources, but I wanted to make the example simple as much as I can. So is there a way to get some block executed only if some language is selected? Or if not, what's the simplest way to set the 'lang' property right, so the code above will be functional.

Thank you.
16 years ago