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.io.File;
 import java.util.Date;
 
LogHandlerDefault

Author(s):
s3595,(CGS)
Version:
$Id: LogHandlerFile.java 2084 2007-11-27 14:53:31Z s3460 $
 
 public class LogHandlerFile extends LogHandlerBase implements ILogHandler {
 
     private String lineSeparator;
 
     private File logfile;
 
     protected LogHandlerFile() {
          = System.getProperty"line.separator");
     }
 
     public void setPropertiesProperties in ) {
         super.setProperties(in);
 
         String strLogDir = (String).get. );
         if(strLogDir==null)
             return;
 
         File logParrent = new FilestrLogDir );
         if(!logParrent.exists()){
             logParrent.mkdirs();
         }
 
         File logdir = new FilelogParrent"/logs");
         if(!logdir.exists()){
             logdir.mkdirs();
         }
 
         SimpleDateFormat sdf = new SimpleDateFormat"ddMMMyyyy", Locale.getDefault() ); //$NON-NLS-1$
         String strDate = sdf.formatnew Date( System.currentTimeMillis()) );
 
          = new File ( logdirstrDate + ".log");
         synchronized() {
             if(!.exists()) {
                 try {
                     if.createNewFile() ) { }
                 } catch (IOException e) {
                     ..println("error creating logfile: " + .toString() );
                      = null;
                     return;
                 }
             }
             if(.exists()) {
                 SimpleDateFormat sdf_file = new SimpleDateFormat"EEE, dd MMM yyyy hh:mm:ss zzz", Locale.getDefault() );            //$NON-NLS-1$
                 String strDateFile = sdf_file.formatnew Date(System.currentTimeMillis()) );
                 writeToDisk + "LogHandler: New File-Logger opened: "strDateFile +  );
             }
         }
 
     }
 
     public synchronized void publish(LogRecord record) {
 
        ifrecord!=null && !=null && .exists() ){
            writeToDisk(format(record)+  );
        }//if
     }
 
     public void writeToDisk(String strMessage) {
         FileOutputStream fos = null;
         try {
 
             fos = new FileOutputStream(.toString(), true);
             fos.writestrMessage.getBytes());
 
        } catch (FileNotFoundException e) {
            ..println("error open logfile: " + e.getMessage());
        } catch (IOException ex) {
            ..println("error writing logfile: " + ex.getMessage());
        } finally {
             if(fos!=null)
                 try {
                     fos.close();
                 } catch (IOException e1) {
                     ..println("error closing logfile: " + .toString());
                 }
        }
    }
    public void close() {
        ..println("log handler close");
    }

    
Get the full qualified name of the used log file.

Since:
1.6.0
    public String getLogFileName() {
        return !=null?.getAbsolutePath():null;
    }
New to GrepCode? Check out our FAQ X