Java by API/java.util.logging/LogRecord
Версия от 17:43, 31 мая 2010; (обсуждение)
Содержание
LogRecord: getLevel()
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
public class Main {
private static Logger logger = Logger.getLogger("CustomHandler");
private static List<String> strHolder = new ArrayList<String>();
public static void main(String[] args) {
logger.addHandler(new Handler() {
public void publish(LogRecord logRecord) {
strHolder.add(logRecord.getLevel() + ":");
strHolder.add(logRecord.getSourceClassName() + ":");
strHolder.add(logRecord.getSourceMethodName() + ":");
strHolder.add("<" + logRecord.getMessage() + ">");
strHolder.add("\n");
}
public void flush() {
}
public void close() {
}
});
logger.warning("Logging Warning");
logger.info("Logging Info");
System.out.print(strHolder);
}
}
LogRecord: getMessage()
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
public class Main {
private static Logger logger = Logger.getLogger("CustomHandler");
private static List<String> strHolder = new ArrayList<String>();
public static void main(String[] args) {
logger.addHandler(new Handler() {
public void publish(LogRecord logRecord) {
strHolder.add(logRecord.getLevel() + ":");
strHolder.add(logRecord.getSourceClassName() + ":");
strHolder.add(logRecord.getSourceMethodName() + ":");
strHolder.add("<" + logRecord.getMessage() + ">");
strHolder.add("\n");
}
public void flush() {
}
public void close() {
}
});
logger.warning("Logging Warning");
logger.info("Logging Info");
System.out.print(strHolder);
}
}
LogRecord: getSourceClassName()
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
public class Main {
private static Logger logger = Logger.getLogger("CustomHandler");
private static List<String> strHolder = new ArrayList<String>();
public static void main(String[] args) {
logger.addHandler(new Handler() {
public void publish(LogRecord logRecord) {
strHolder.add(logRecord.getLevel() + ":");
strHolder.add(logRecord.getSourceClassName() + ":");
strHolder.add(logRecord.getSourceMethodName() + ":");
strHolder.add("<" + logRecord.getMessage() + ">");
strHolder.add("\n");
}
public void flush() {
}
public void close() {
}
});
logger.warning("Logging Warning");
logger.info("Logging Info");
System.out.print(strHolder);
}
}
LogRecord: getSourceMethodName()
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
public class Main {
private static Logger logger = Logger.getLogger("CustomHandler");
private static List<String> strHolder = new ArrayList<String>();
public static void main(String[] args) {
logger.addHandler(new Handler() {
public void publish(LogRecord logRecord) {
strHolder.add(logRecord.getLevel() + ":");
strHolder.add(logRecord.getSourceClassName() + ":");
strHolder.add(logRecord.getSourceMethodName() + ":");
strHolder.add("<" + logRecord.getMessage() + ">");
strHolder.add("\n");
}
public void flush() {
}
public void close() {
}
});
logger.warning("Logging Warning");
logger.info("Logging Info");
System.out.print(strHolder);
}
}
new LogRecord(Level level, String msg)
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import java.util.logging.MemoryHandler;
public class Main {
public static void main(String args[]) throws Exception {
Logger logger = Logger.getLogger("your.logging");
ConsoleHandler handler = new ConsoleHandler();
MemoryHandler mHandler = new MemoryHandler(handler, 10, Level.ALL);
logger.addHandler(mHandler);
logger.setUseParentHandlers(false);
LogRecord record1 = new LogRecord(Level.SEVERE, "This is SEVERE level message");
LogRecord record2 = new LogRecord(Level.WARNING, "This is WARNING level message");
logger.log(record1);
logger.log(record2);
}
}