Pages

How to log at the correct level

TRACE This is the lowest logging level. This should be used for tracing activities such as method invocation and parameter logging, etc.
DEBUG This log level is commonly used for application debugging statements. This level should be used to log messages which are helpful in debugging, but which are too verbose to be written to the log under normal situations.
INFO This is the information log level. This should be used to log statements which are expected to be written to the log during the normal operations. For example, running a important business operation should be logged under this level.
WARN Warning Level. This should be used to log warnings, which are situations that are usually unexpected, but which does not significantly affect the business functionality.
ERROR Error level should be used to log all errors and exceptions which affect the business functionality of the application.
FATAL Fatal log level is used to write extreme situations where the entire application execution could be affected due to some cause.

Deep copy object

import java.io.*;

public class Clone {
/**
* Returns a deep of the object, or null if the object cannot
* be serialized.
*/
public static Object deep(final Object orig) {
Object obj = null;

try {

// Write the object out to a byte array
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
final ObjectOutputStream out = new ObjectOutputStream(bos);

out.writeObject(orig);
out.flush();
out.close();

// Make an input stream from the byte array and read
// a deep of the object back in.
final ObjectInputStream in = new ObjectInputStream(
new ByteArrayInputStream(bos.toByteArray()));

obj = in.readObject();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}

return obj;
}
}