Newer
Older
restamp / src / main / java / osm / surveyor / util / YuuLogFormatter.java
@haya4 haya4 on 26 Jan 2020 1 KB Restamp
  1. package osm.surveyor.util;
  2.  
  3. import java.text.SimpleDateFormat;
  4. import java.util.Date;
  5. import java.util.logging.Formatter;
  6. import java.util.logging.Level;
  7. import java.util.logging.LogRecord;
  8.  
  9. /**
  10. * シンプルなサンプルログフォーマッタ
  11. */
  12. public class YuuLogFormatter extends Formatter {
  13. private final SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
  14.  
  15. @Override
  16. public String format(final LogRecord argLogRecord) {
  17. final StringBuffer buf = new StringBuffer();
  18.  
  19. buf.append(sdFormat.format(new Date(argLogRecord.getMillis()))).append(" ");
  20.  
  21. if (argLogRecord.getLevel() == Level.FINEST) {
  22. buf.append("[FINEST]");
  23. }
  24. else if (argLogRecord.getLevel() == Level.FINER) {
  25. buf.append("[FINER]");
  26. }
  27. else if (argLogRecord.getLevel() == Level.FINE) {
  28. buf.append("[FINE]");
  29. }
  30. else if (argLogRecord.getLevel() == Level.CONFIG) {
  31. buf.append("[CONFIG]");
  32. }
  33. else if (argLogRecord.getLevel() == Level.INFO) {
  34. buf.append("[INFO]");
  35. }
  36. else if (argLogRecord.getLevel() == Level.WARNING) {
  37. buf.append("[WARN]");
  38. }
  39. else if (argLogRecord.getLevel() == Level.SEVERE) {
  40. buf.append("[SEVERE]");
  41. }
  42. else {
  43. buf.append(Integer.toString(argLogRecord.getLevel().intValue())).append(" ");
  44. }
  45. buf.append(" ").append(argLogRecord.getMessage()).append("\n");
  46. return buf.toString();
  47. }
  48. }