0

in a legacy project I find a strange solution for logging. All classes in the servicelayer does have method signature to getting a log. After digging through the code and numberous conversation I found the reason for that.

We are needing a distinct logfile for every business transaction that was processed. So if a new business transactions starts a new log is created and is put into every method that is called.

That looks really odd.

Before I start to override the Log.getLogger(..) method or something else. Does anyone knows a better way to log each business transaction in a distinct file?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
wizardofOz
  • 127
  • 11
  • 1
    I would have one log file and use a unique id for each transaction. Then you can grep for an individual transaction. You don't need a file for each one. esp as this risks using a lot of resources. – Peter Lawrey Apr 16 '14 at 16:48
  • Unfortunately I need a distinct logfile for every transaction. The Thanks for your comments. Fogfiles are send to the customer, who initiate the business transaction. With your way I had to build a parser for logfiles to extract these messages. Could be an option. But I prefer a way that this is done with the logger itself. – wizardofOz Apr 17 '14 at 06:52
  • What I would do is to write the output to a buffer which is sent to the origination. This would bypass the need for a logger, or a log file. e.g. a normal Socket connection, you write to the socket the results. – Peter Lawrey Apr 17 '14 at 08:16

1 Answers1

0

You can avoid overwriting the "Log.getLogger(...)" by implementing a custom appender using the log4j library. Since the legacy application is logging the transaction in a file, it should be using an appender (or maybe somebody has already written that custom appender and it is using in the application you are working on).

In this case, the File Appender is the type of appender that best fits into your needs, that could be an option, you can find the documentation of the "FileAppender" here:

http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/FileAppender.html

It is a matter of extending this class, something like:

MyCustomTransactionAppender extends FileAppender

Then you just need to overwrite the methods according to your needs.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Marcelo Tataje
  • 3,849
  • 1
  • 26
  • 51