Return-Path: Delivered-To: apmail-logging-log4j-user-archive@www.apache.org Received: (qmail 68247 invoked from network); 9 Nov 2006 08:37:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 9 Nov 2006 08:37:28 -0000 Received: (qmail 17348 invoked by uid 500); 9 Nov 2006 08:37:38 -0000 Delivered-To: apmail-logging-log4j-user-archive@logging.apache.org Received: (qmail 16660 invoked by uid 500); 9 Nov 2006 08:37:37 -0000 Mailing-List: contact log4j-user-help@logging.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Log4J Users List" Reply-To: "Log4J Users List" Delivered-To: mailing list log4j-user@logging.apache.org Received: (qmail 16607 invoked by uid 99); 9 Nov 2006 08:37:37 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Nov 2006 00:37:37 -0800 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of mbosteels.dns@gmail.com designates 64.233.162.195 as permitted sender) Received: from [64.233.162.195] (HELO nz-out-0102.google.com) (64.233.162.195) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Nov 2006 00:37:23 -0800 Received: by nz-out-0102.google.com with SMTP id s1so84932nze for ; Thu, 09 Nov 2006 00:37:02 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=egQUgRuw6oBz8+y3P1CRRt9NIEhmMv+wDll4GIp0oAjyhxIjPy9pKP194+0yqJfJjpmvckcWmV9+RR0dy75zx7P/2uzhx4FEFt3+NajHMHMcdHDW3U21eWwyAyiAEH4MpNoFrtPINgg6zQxD7pdKMRu+9driyvRvG7oPx1Po86g= Received: by 10.65.147.1 with SMTP id z1mr804573qbn.1163061422305; Thu, 09 Nov 2006 00:37:02 -0800 (PST) Received: by 10.65.138.19 with HTTP; Thu, 9 Nov 2006 00:37:01 -0800 (PST) Message-ID: <5e87acee0611090037l533797edmec2e1e9ab6793427@mail.gmail.com> Date: Thu, 9 Nov 2006 09:37:01 +0100 From: "Maarten Bosteels" To: "Log4J Users List" Subject: Re: dynamically adding to a log file name? In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_34742_23185024.1163061421755" References: X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_34742_23185024.1163061421755 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline 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); writer.write(request); writer.close(); If you need to specify the charset use OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(filename), "UTF-8"); Maarten On 11/9/06, Chris Cheshire 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 > > ------=_Part_34742_23185024.1163061421755--