1,355 バイト追加
、 2020年2月15日 (土) 07:33
==Java java.util.logging==
[Java]
=====簡易にロギングしたいときのサンプル=====
*http://www.atmarkit.co.jp/ait/articles/0801/08/news128.html
package info.typea.sample;
import java.io.ByteArrayInputStream;
import java.util.logging.LogManager;
import java.util.logging.Logger;
public class LoggingSample {
protected static final String LOGGING_PROPERTIES_DATA
= "handlers=java.util.logging.ConsoleHandler, java.util.logging.FileHandler\n"
+ ".level=INFO\n"
+ "java.util.logging.ConsoleHandler.level=INFO\n"
+ "java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter\n"
+ "java.util.logging.FileHandler.pattern=/home/piroto/work/log/LoggingSample%u.log\n"
+ "java.util.logging.FileHandler.append=true\n"
+ "java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter\n"
;
private static Logger logger = null;
static {
try {
LogManager.getLogManager().readConfiguration(
new ByteArrayInputStream(LOGGING_PROPERTIES_DATA.getBytes("UTF-8")));
logger = Logger.getLogger(LoggingSample.class.getName());
} catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) {
LoggingSample me = new LoggingSample();
me.test();
}
public void test() {
logger.info("TEST");
}
}