cancel
Showing results for 
Search instead for 
Did you mean: 

Application log messages are being duplicated

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Answers (0)