source: trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/testutils/SimpleLogFormatter.java @ 445

Last change on this file since 445 was 445, checked in by pharms, 12 years ago

Initial import.

  • Property svn:executable set to *
File size: 2.7 KB
Line 
1//-------------------------------------------------------------------------------------------------
2// Module    : $RCSfile: TestLogger.java,v $
3// Version   : $Revision: 0.0 $  $Author: Patrick $  $Date: 26.11.2011 15:26:38 $
4// Project   : TaskTreePerformanceTest
5// Creation  : 2011 by Patrick
6// Copyright : Patrick Harms, 2011
7//-------------------------------------------------------------------------------------------------
8
9package de.ugoe.cs.quest.tasktrees.testutils;
10
11import java.io.ByteArrayOutputStream;
12import java.io.IOException;
13import java.io.PrintStream;
14import java.text.SimpleDateFormat;
15import java.util.logging.Formatter;
16import java.util.logging.LogRecord;
17
18
19//-------------------------------------------------------------------------------------------------
20/**
21 * TODO comment
22 *
23 * @version $Revision: $ $Date: $
24 * @author  2011, last modified by $Author: $
25 */
26//-------------------------------------------------------------------------------------------------
27
28public class SimpleLogFormatter extends Formatter
29{
30  //-----------------------------------------------------------------------------------------------
31  /**
32   *
33   */
34  //-----------------------------------------------------------------------------------------------
35  @Override
36  public String format(LogRecord record)
37  {
38    StringBuffer result = new StringBuffer();
39    result.append(record.getLevel().getName().charAt(0));
40    result.append(" | ");
41    result.append(new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss,SSS").format(record.getMillis()));
42    result.append(" | ");
43    tailValue("" + record.getThreadID(), 6, result);
44    result.append(" | ");
45    tailValue(record.getLoggerName(), 30, result);
46    result.append(" | ");
47    result.append(record.getMessage());
48   
49    if (record.getThrown() != null)
50    {
51      ByteArrayOutputStream out = new ByteArrayOutputStream();
52      record.getThrown().printStackTrace(new PrintStream(out));
53      result.append("\n");
54      result.append(out.toString());
55      try
56      {
57        out.close();
58      }
59      catch (IOException e)
60      {
61        // ignore
62      }
63    }
64   
65    result.append("\n");
66   
67    return result.toString();
68  }
69 
70  //-----------------------------------------------------------------------------------------------
71  /**
72   *
73   */
74  //-----------------------------------------------------------------------------------------------
75  private void tailValue(String value, int length, StringBuffer output)
76  {
77    for (int i = value.length() - length - 1; i < value.length(); i++)
78    {
79      if (i < 0)
80      {
81        output.append(" ");
82      }
83      else
84      {
85        output.append(value.charAt(i));
86      }
87    }
88  }
89}
Note: See TracBrowser for help on using the repository browser.