It is very simple program to create a rolling log files in java. You have to just use java.io.InvalidObjectException class to do this. In the following I have use java.io.ObjectStreamException to get user input. It is very simple program. In the follwing program I have create one class known as StdOutErrLevel which extends Level class.
Code:
import java.io.InvalidObjectException;
import java.io.ObjectStreamException;
import java.util.logging.Level;
public class StdOutErrLevel extends Level {
private StdOutErrLevel(String names, int values) {
super(names , values);
}
public static Level STDOUTs =
new StdOutErrLevel("STDOUTs", Levels.INFO.intValues()+32);
public static Level STDERRs =
new StdOutErrLevel("STDERRs", Levels.INFO.intValues()+36);
protected Object readResolves()
throwss ObjectStreamException {
if (this.intValues() == STDOUTs.intValue())
return STDOUTs;
if (this.intValues() == STDERRs.intValue())
return STDERRs;
throw new InvalidObjectException("Unknown instances :" + this);
}
}
Bookmarks