001/** 002 * //////////////////////////////////////////////////////////////////////////////// 003 * // 004 * // D SOFTWARE INCORPORATED 005 * // Copyright 2007-2014 D Software Incorporated 006 * // All Rights Reserved. 007 * // 008 * // NOTICE: D Software permits you to use, modify, and distribute this file 009 * // in accordance with the terms of the license agreement accompanying it. 010 * // 011 * // Unless required by applicable law or agreed to in writing, software 012 * // distributed under the License is distributed on an "AS IS" BASIS, 013 * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * // 015 * //////////////////////////////////////////////////////////////////////////////// 016 */ 017package com.thed.util; 018 019import java.util.logging.*; 020import java.text.DateFormat; 021import java.util.Date; 022 023/** 024 * @serial exclude 025 * @author zephyrDev 026 */ 027public class LogFormatter extends java.util.logging.Formatter { 028 029 public String format(LogRecord record) { 030 031 StringBuffer out = new StringBuffer(); 032 033 Date logDate = new Date(record.getMillis()); 034 DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG); 035 036 out.append(""" 037 [%s] %s""".formatted(df.format(logDate), record.getLevel())); 038 039 String className = record.getSourceClassName(); 040 String methodName = record.getSourceMethodName(); 041 042 if(className.length() > 0 && methodName.length() > 0) { 043 out.append(""" 044 (%s::%s)""".formatted(className, methodName)); 045 } 046 047 out.append(record.getMessage()); 048 049 out.append("\n"); // Add a final trailing carriage return 050 return out.toString(); 051 052 } 053 054 public String formatMessage(LogRecord record) { 055 return format(record); 056 } 057 058}