Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH . All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: s IT Solutions AT Spardat GmbH - initial API and implementation /
 
 
 /*
  * Created on : 25.06.2003
  * Created by : s3595
  */
 package at.spardat.xma.boot.logger;
 
 import java.sql.Date;
LogHandlerDefault

Author(s):
s3595,(CGS)
Version:
$Id: LogHandlerBase.java 2084 2007-11-27 14:53:31Z s3460 $
 
 public abstract class LogHandlerBase implements ILogHandler {
 
     protected MessageFormat formatter;
     protected Object        args[]    = new Object[1];
     protected String        format    = "{0,date} {0,time}"//$NON-NLS-1$
     protected String        separator = " : ";
     protected Properties    props     = new Properties();
 
     protected LogHandlerBase() { }
 
     public void setPropertiesProperties in ) {
          = in;
     }
 
     public void publish(LogRecord record) { }
 
     public void close() { }
 
     protected String formatLogRecord record ){
 
         StringBuffer sb = new StringBuffer(100);
         Date dat = new Daterecord.getMillis() );
 
 
         [0] = dat;
         StringBuffer text = new StringBuffer();
         if ( == null) {
              = new MessageFormat();
         }
         .format(textnull);
         sb.append(text.toString());
 
         sb.append();
         if (record.getSourceClassName() != null) {
             sb.append(record.getSourceClassName());
         } else {
             String name = record.getLoggerName();
             sb.appendname + ( name.length()< 20 ? space(20-name.length()) : "") );
         }
         if (record.getSourceMethodName() != null) {
             sb.append(" "); //$NON-NLS-1$
             sb.append(record.getSourceMethodName());
         }
 
         sb.append();
         sb.append(record.getLevelName() );
         sb.append();
         sb.appendthis.formatMessage(record) );
 
         if (record.getThrown() != null) {
             sb.append( System.getProperty("line.separator")); //$NON-NLS-1$
 
             try {
                 StringWriter sw = new StringWriter();
                 PrintWriter pw = new PrintWriter(sw);
                 record.getThrown().printStackTrace(pw);
                 pw.close();
             sb.append(sw.toString());
             } catch (Exception ex) {
             }
         }
         return sb.toString();
         }
 
     private synchronized String formatMessage(LogRecord record) {
         String format = record.getMessage();
 
         // Do the formatting.
         try {
            Object parameters[] = record.getParameters();
            if (parameters == null || parameters.length == 0) {
                return format;
            }
            // Is is a java.text style format?
            if (format.indexOf("{0") >= 0) { //$NON-NLS-1$
                return java.text.MessageFormat.format(formatparameters);
            }
            return format;
        } catch (Exception ex) {
            return format;
        }
    }
    private String spaceint count ) {
        if(count<=0)
            return "";
        StringBuffer sb = new StringBuffer(count);
        for(int i=0;i<count;i++){
          sb.append(' ');
        }
        return sb.toString();
    }
New to GrepCode? Check out our FAQ X