Esha Goel

Greenhorn
+ Follow
since Jan 24, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Esha Goel

Trying conversion pattern like below is not working, as HTML layout donot extend pattern layout.

log4j.appender.MY_FILE=org.apache.log4j.RollingFileAppender
log4j.appender.MY_FILE_FILE.File=logs/myfile/MyLog.html
log4j.appender.MY_FILE_FILE.MaxFileSize=2500KB
log4j.appender.MY_FILE_FILE.MaxBackupIndex=5
log4j.appender.MY_FILE_FILE.Append=true
log4j.appender.MY_FILE_FILE.layout=org.apache.log4j.HTMLLayout
#log4j.appender.MY_FILE_FILE.layout.ConversionPattern=[%d{MMM dd HH:mm:ss}] %-5p (%F:%L) - %m%n
Hi All,

I am using HTMLLayout for logging using log4j.

I want to change the default timestamp that comes with HTMLLayout.
something like this 2008-01-28 17:13:02,057 .

Please let me know how can we do that.

Thanks in advance
Hi All,

I want to search a particular text ina file and replace it with a different string (much more in length).

I am tryinh it with regular expression and new io.

here is my code snippet

.....................................
RandomAccessFile raf=new RandomAccessFile(f,"rw");
FileChannel fc = raf.getChannel();
int len=(int)fc.size();
MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_WRITE, 0, len);

Charset charset = Charset.forName("US-ASCII");
CharsetDecoder decoder = charset.newDecoder();
CharBuffer cb = decoder.decode(bb);

Pattern p = Pattern.compile("texttomatch");
Matcher m = p.matcher(cb); // get a matcher object
StringBuffer sb = new StringBuffer();
byte[] src=null;

while (m.find()) {
m.appendReplacement(sb, "texttoreplace with");
///src=new String(cb.array()).getBytes();
///writeBuffer.put(src);

//bb.put(sb.toString().getBytes());

}

m.appendTail(sb);

bb.force();
//raf.close();
fc.close();
.....................................


When i see the string buffer the text is correctly replace but i am not able to put it in mapped buffer.

If anybody has some solution or some better way ,then please let me know
16 years ago