Henry, You can programmatically change the layout. See my response below:
Very timely question & answer. What if one inherits from XmlSocketAppender class and implement a setLayout() method that frees (deletes) the XmlLayout that was created and replaces it with the layout in the setLayout() call? The 'layout' variable defined in AppenderSkeleton (and used by XmlSocketAppender) is protected, so the derived class has access to it (which is what XmlSocketAppender does). peter ----- Original Message ----- From: "Henry Chou" To: "Log4CXX User" Subject: Re: Programmatic Configuration of XMLSocketAppender Date: Mon, 1 Jun 2009 18:16:19 -0700 "Nothing I've seen in the log4cxx codebase suggests that XMLSocketAppender accepts a layout specification. " I have also been digging through the XMLSocketAppender source files in 0.10.0, but couldn't find it; asking you guru's was my last resort. Weird though... when using an xml config file with the appender, > <appender name="MyXmlAppenderFormated" > class="org.apache.log4j.net.XMLSocketAppender"> > <param name="Port" value="2222"/> > <param name="RemoteHost" value="192.168.1.101"/> > <param name="ReconnectionDelay" value="30000"/> > <param name="LocationInfo" value="true" /> > <layout class="org.apache.log4j.PatternLayout"> > <param name="ConversionPattern" value="%d [%p] - %m%n"/> > </layout> > </appender> I get exactly the desired outcome: a pattern-based log message sent through a socket. No "serialized LoggingEvent"'s, no XMLLayout logs; just the simple "%d [%p] - %m%n" layout received from the server. Only when I programmatically configure, that option is not obvious to configure (if configurable at all). Alrighty, thank you! I was hoping to eliminate the use of additional (unnecessary) files, but I guess I'll have to keep the xml config file. And thanks for the quick reply! Best regards, -hc. ----- Original Message ----- From: "Curt Arnold" To: "Log4CXX User" Subject: Re: Programmatic Configuration of XMLSocketAppender Date: Thu, 28 May 2009 23:00:08 -0500 Nothing I've seen in the log4cxx codebase suggests that XMLSocketAppender accepts a layout specification. The log4cxx 0.10.0 code uses an XMLLayout in its implementation, but it is private. My guess is that your attempt at specifying a layout is getting ignored. If you want to write your own SocketAppender that does not output XML, you can base it off of SocketAppenderSkeleton. On May 28, 2009, at 9:21 PM, Henry Chou wrote: > Hello, > > I currently am sending a log string using the an > XMLSocketAppender, and am doing so by using the following > configuration. > > config.xml: > <appender name="MyXmlAppenderFormated" > class="org.apache.log4j.net.XMLSocketAppender"> > <param name="Port" value="2222"/> > <param name="RemoteHost" value="192.168.1.101"/> > <param name="ReconnectionDelay" value="30000"/> > <param name="LocationInfo" value="true" /> > <layout class="org.apache.log4j.PatternLayout"> > <param name="ConversionPattern" value="%d [%p] - %m%n"/> > </layout> > </appender> > > > > > > > > > ============== > > I have done this: > pXMLSocketAppender_ = new > log4cxx::net::XMLSocketAppender("192.168.2.31", 2009); > > Is there a way to modify the pattern programmatically? I can set > most of these settings by using XMLSocketAppender- > >setOption("ReconnectionDelay","30000"), but the > ConversionPattern parameter just isn't done the same way. > > Thanks ahead of time, > > -hc. -- Be Yourself @ mail.com! Choose From 200+ Email Addresses Get a Free Account at www.mail.com! -- Be Yourself @ mail.com! Choose From 200+ Email Addresses Get a Free Account at www.mail.com