Sorry for previous message. When I tried the SocketAppender with XMLLayout the same error occured. I fix this issue with such changes in socketoutputstream.cpp:
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <log4cxx/logstring.h> #include <log4cxx/helpers/socketoutputstream.h> #include <log4cxx/helpers/socket.h> #include <log4cxx/helpers/bytebuffer.h> using namespace log4cxx; using namespace log4cxx::helpers; IMPLEMENT_LOG4CXX_OBJECT(SocketOutputStream) SocketOutputStream::SocketOutputStream(const SocketPtr& socket1) : socket(socket1) { } SocketOutputStream::~SocketOutputStream() { } void SocketOutputStream::close(Pool& p) { flush(p); socket->close(); } void SocketOutputStream::flush(Pool& p) { *if (array.size() == 0) return;** *socket->write(&array[0], array.size()); array.resize(0); } void SocketOutputStream::write(ByteBuffer& buf, Pool& /* p */ ) { size_t sz = array.size(); *if (buf.remaining() == 0) return;** *array.resize(sz + buf.remaining()); memcpy(&array[sz], buf.current(), buf.remaining()); buf.position(buf.limit()); } I just never created diff patches before though I wrote just in plain text. This fixes crashes and Chainsaw output log messages correctly. The Chainsaw was configured in such way: 1)port:4448 2)listener: org.apache.log4j.xml.XMLDecoder log4cxx config file: log4j.rootLogger=debug,chainsaw2 log4j.appender.chainsaw2=org.apache.log4j.SocketAppender log4j.appender.chainsaw2.RemoteHost=127.0.0.1 log4j.appender.chainsaw2.Port=4448 log4j.appender.chainsaw2.layout=org.apache.log4j.XMLLayout And I'm using svn trunk checkout. I'm developing using MSVC8. On 12/12/07, Curt Arnold <[EMAIL PROTECTED]> wrote: > > > On Dec 12, 2007, at 7:17 AM, Mykhailo Parfeniuk wrote: > > > When I use XMLSocketAppender in my application it fails with > > assertion "invalid subscript". The reason is it tries to append zero > > length string to output . > > When I looked at code I saw strange implementation of function write: > > > > void OutputStreamWriter::write(const LogString& str, Pool& p) { > > if (str.length() > 0) { > > enum { BUFSIZE = 1024 }; > > char rawbuf[BUFSIZE]; > > ByteBuffer buf(rawbuf, (size_t) BUFSIZE); > > enc->reset(); > > LogString::const_iterator iter = str.begin(); > > while(iter != str.end()) { > > CharsetEncoder::encode(enc, str, iter, buf); > > buf.flip(); > > out->write(buf, p); > > buf.clear(); > > } > > CharsetEncoder::encode(enc, str, iter, buf); > > enc->flush(buf); > > buf.flip(); > > out->write(buf, p); > > } > > } > > > > It seems to me that there should be iterator changing. > > Am I right or not? > > If use another appenders - file, console, all works normally. > > Maybe I forgot initialize something? Or function is implemented > > incorrectly? > > > > > > > > OutputStreamWriter::write is also used by all FileAppenders, so any > flaw in its implementation would be seen there too. > CharsetEncoder::encode() will advance the iterator as it encodes the > string into the specified encoding. > > There was recent work to make SocketAppender functional with > Chainsaw. I did some sanity tests with it and the SocketAppender did > work. However, those changes resulted in some refactoring of > XMLSocketAppender and it is possible that I messed that up. I didn't > do any sanity tests with XMLSocketAppender, since I could not figure > out how to get Chainsaw to work with it. It would be helpful if you > could > > a) See if SocketAppender works with Chainsaw for you > b) Give me instructions on how to set up Chainsaw to work with the > socket appender > > > >
