/*
 * Copyright (c) 2007 Stephan D. Cote' - All rights reserved.
 * 
 * This program and the accompanying materials are made available under the 
 * terms of the MIT License which accompanies this distribution, and is 
 * available at http://creativecommons.org/licenses/MIT/
 *
 * Contributors:
 *   Stephan D. Cote 
 *      - Initial concept and initial implementation
 */
package coyote.loader.log;

import coyote.commons.StringUtil;


/**
 * An event formatter which is suitable for console logging.
 * 
 * <p>This is a minimalistic formatter to keep the console clean.</p>
 */
public class ConsoleFormatter implements Formatter {

  /**
   *
   */
  public ConsoleFormatter() {
  }




  /**
   * Format the event into a string to be placed in the log.
   *
   * @param event the thing to be logged
   * @param category the type of log entry it is
   * @param cause The exception that caused the log entry. Can be null.
   *
   * @return a string representing the line to place in the log
   */
  public String format( final Object event, final String category, final Throwable cause ) {

    final StringBuffer buffer = new StringBuffer();

    buffer.append( category );
    buffer.append( " | " );

    if ( event != null )
      buffer.append( event.toString() );

    buffer.append( StringUtil.LINE_FEED );

    return buffer.toString();
  }




  /**
   * Create any header data.
   *
   * @return header data to be written out before any log entries.
   */
  public byte[] initialize() {
    return null;
  }




  /**
   * Create any footer data.
   *
   * @return footer data to be written after any events before the output is closed.
   */
  public byte[] terminate() {
    return null;
  }
}
@@ -675,21 +675,18 @@
 tter() %7B
-%0A  
 %7D%0A
+
 %0A%0A%0A%0A  /*
@@ -1221,16 +1221,18 @@
 = null )
+ %7B
 %0A      b
@@ -1264,16 +1264,899 @@
 ing() );
+%0A    %7D%0A%0A    if ( cause != null ) %7B%0A      if ( event != null ) %7B%0A        buffer.append( ' ' );%0A      %7D%0A%0A      buffer.append( %22EXCEPTION: %22 );%0A      buffer.append( cause.getClass().getName() );%0A      if ( cause.getMessage() != null ) %7B%0A        buffer.append( %22 MSG: %22 );%0A        buffer.append( cause.getMessage() );%0A      %7D%0A      buffer.append( %22 at %22 );%0A%0A      final StackTraceElement%5B%5D stack = ( cause ).getStackTrace();%0A      StackTraceElement elem = stack%5B0%5D;%0A%0A      buffer.append( elem.getClassName() );%0A      buffer.append( %22.%22 );%0A      buffer.append( elem.getMethodName() );%0A      buffer.append( %22(%22 );%0A%0A      if ( elem.getLineNumber() %3C 0 ) %7B%0A        buffer.append( %22Native Method%22 );%0A      %7D else %7B%0A        buffer.append( elem.getFileName() );%0A        buffer.append( %22:%22 );%0A        buffer.append( elem.getLineNumber() );%0A      %7D%0A%0A      buffer.append( %22)%22 );%0A      // --%0A%0A    %7D
 %0A%0A    bu

Support the formatting of exceptions