com.softicar.platform.common.core.logging.LogBuffer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.
package com.softicar.platform.common.core.logging;
/**
* In-memory implementation of {@link ILogOutput}.
*
* Stores all log output internally in a {@link StringBuilder}. The logged text
* can be returned using {@link #toString()}.
*
* @author Oliver Richers
*/
public class LogBuffer implements ILogOutput {
private final StringBuilder builder;
public LogBuffer() {
this.builder = new StringBuilder();
}
@Override
public synchronized void logLine(String line) {
builder.append(line).append("\n");
}
/**
* Returns all logged text.
*/
@Override
public synchronized String toString() {
return builder.toString();
}
/**
* Clears this buffer by discarding all previously logged text.
*/
public synchronized void clear() {
builder.setLength(0);
}
}