on 11-15-2006 5:55 AM
Within my J2EE java application running on SP14, I write out log
messages to a FileLog as follows:
static final Location loc = Location.getLocation(SettingsServlet.class);
String logDestination = "/usr/sap/application_logs/ESS" + logDate + ".%g.log";
loc.setEffectiveSeverity(Severity.ALL);
FileLog fileLog = new FileLog(logDestination, 800000, 10, new
TraceFormatter());
And then in specific locations in my code, I write to the log as follows
<b>loc.infoT("Hello there");</b>
When the server first creates the log file, each event ("Hello There")
is logged once, which is correct and expected behavior. However, as
the day goes on, each single event is written multiple times in the
log. The log lines appear immediately next to each other.
1 hour later, every single event is logged 3 times. I see 3 "Hello
There" messages with the exact same timestamp in the log next to each
other.
And 4 or 5 hours later, every event is logged with 8+ "Hello There"
messages in consecutive order.
It seems that as the days wears on, the messages are duplicated more
and more.
This needless additional logging harms our system. We need logs to
monitor our system, but with logging working like this, our system will
crash with production volume.
What causes log messages to be duplicated?
Thanks!
Kevin
Hi Kevin,
Unless I am missing something you need to call loc.addLog(fileLog) to make the logging appear in the file, and it is not present in your sample code.
Check out how many times you have called this method on your static variable loc since the start of the JVM. If you call it 5 times, you are likely to receive 5 duplicated trace statements
HTH
Peter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Peter,
Thank you for your response.
Here is the rest of my code. I overlooked sending it first time.
loc.setEffectiveSeverity(Severity.ALL);
FileLog fileLog = new FileLog(logDestination, 800000, 10, new TraceFormatter());
loc.addLog(fileLog);
The addLog method is called in the intialize method of one of my servlets. So each time my application restarts, it runs this method once. That would explain why I get progressively more duplicated log messages as the day progresses. I am publishing fixes to the code and the program restarts each time.
But now the question is how do I get around this? Before I addLog, do I need to detect if another log is already in progress? How can I do this?
Here is what I need: a simple log file consisting of one message written each time a loc.infoT("") is executed.
Any further suggestions?
Thanks again.
Kevin
Hi Kevin,
well, you could go in 3 ways :
1) look for some singleton design pattern
2) do not use the creation of locations directly by API, but declare this by XML file
3) (Minimum changes) - use some of the hundreds of methods from the logging API, for example instead of
loc.addLog(fileLog),
execute
loc.removeLogs();
loc.addLog(fileLog),
or maybe
if (loc.getAllLogs().size() == 0) {
loc.addLog(fileLog);
}
HTH
Peter
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.