logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Maarten Bosteels" <mbosteels....@gmail.com>
Subject Re: dynamically adding to a log file name?
Date Thu, 09 Nov 2006 08:37:01 GMT
Why don't you just save the request and the response to a file ?
You do not need log4j for that, right ?

      DateFormat df = new SimpleDateFormat("yyyyMMdd-HHmmss-S");
      String filename = "/tmp/" + df.format(new Date()) + "-request.xml";
      FileWriter writer = new FileWriter(filename);

If you need to specify the charset use

    OutputStreamWriter writer = new OutputStreamWriter(new
FileOutputStream(filename), "UTF-8");


On 11/9/06, Chris Cheshire <cheshirator@gmail.com> wrote:
> Hi,
> I have a process that sends an xml request to an external server and
> receives an xml response back. For purposes of debugging, I need to
> capture the request and response in separate files but with similar
> names so that I can pair them up easily.
> Currently I am using James Stauffer's DateFormatFileAppender (very
> useful James!!) with the filename set to
> '${log4j.log.dir}/'yyyy/MM/dd/'qresponse.'yyyyMMdd-HHmmss-S'.xml' (and
> similar for the request) to log each request and response to a
> separate file each time. (I do understand that there is potential for
> 2 requests at the same millisecond, but this is really for debugging
> only and not production, so I can pretty much guarantee that won't
> happen).
> By using the milliseconds in the filename I can get unique requests or
> responses, but each request and subsequent response will have slightly
> different timestamps. I might get two requests processed before I get
> the response back for the first, which makes it slightly difficult to
> match them up.
> I don't want to log the request and response to the same file, because
> then it is no longer a well formed XML document that I can look at in
> an XML browser.
> Is there some way I can dynamically add something (like my internal
> requestid) to the file names at log time such that I can pair the log
> files up, without forcefully finding the appender and reconfiguring it
> each time (which would be rather slow)?
> If all else fails I can add an XML comment to the end of the file via
> the pattern layout, but I am looking for something that will help for
> scan value in matching the files up.
> Thanks
> Chris
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message