001 /* 002 * $RCSfile: LogFormatter.java,v $ 003 * 004 * Created on August 9, 2002, 10:33 AM 005 * 006 * This file is part of the STAR Scheduler. 007 * Copyright (c) 2002-2006 STAR Collaboration - Brookhaven National Laboratory 008 * 009 * STAR Scheduler is free software; you can redistribute it and/or modify 010 * it under the terms of the GNU General Public License as published by 011 * the Free Software Foundation; either version 2 of the License, or 012 * (at your option) any later version. 013 * 014 * STAR Scheduler is distributed in the hope that it will be useful, 015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 017 * GNU General Public License for more details. 018 * 019 * You should have received a copy of the GNU General Public License 020 * along with STAR Scheduler; if not, write to the Free Software 021 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 022 */ 023 package gov.bnl.star.offline.scheduler; 024 025 import java.io.PrintWriter; 026 import java.io.StringWriter; 027 028 import java.util.logging.LogRecord; 029 import java.util.logging.SimpleFormatter; 030 031 032 /** Defines the log output format of the log of the scheduler. 033 * 034 * @author Gabriele Carcassi 035 * @version $Revision: 1.10 $ $Date: 2006/11/21 00:41:32 $ 036 */ 037 public class LogFormatter extends SimpleFormatter { 038 /** Creates a new instance of LogFormatter */ 039 public LogFormatter() { 040 } 041 042 public String format(LogRecord log) { 043 String exceptionReport = "\n"; 044 045 if (log.getThrown() != null) { 046 StringWriter buff = new StringWriter(); 047 log.getThrown().printStackTrace(new PrintWriter(buff)); 048 exceptionReport += (" -> Exception: " + buff.toString()); 049 } 050 051 int lastDot = log.getLoggerName().lastIndexOf('.'); 052 String name = log.getLoggerName().substring(lastDot + 1); 053 054 return "" + log.getSequenceNumber() + "|" + log.getLevel() + "|" + 055 name + "." + log.getSourceMethodName() + ": " + log.getMessage() + 056 exceptionReport; 057 } 058 }