package be.ibridge.kettle.core.logging;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.*;
import org.apache.log4j.spi.LoggingEvent;

public class Log4jKettleLayout extends Layout
{
    private boolean timeAdded;
    
    public Log4jKettleLayout(boolean addTime)
    {
        this.timeAdded = addTime;
    }

    public String format(LoggingEvent event)
    {
        String line="";
        if (timeAdded)
        {
            SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
            line+=df.format(new Date(event.timeStamp))+" - ";
        }

        Object object = event.getMessage();
        if (object instanceof Log4jMessage)
        {
            Log4jMessage message = (Log4jMessage)object;
            
            if (message.getSubject()!=null)
            {
                line+=message.getSubject()+" - ";
            }

            if (message.isError())  
            {
                line+="ERROR : ";
            }
            
            line+=message.getMessage();
        }
        else
        {
            line+=object.toString();
        }
        
        return line;
    }

    public boolean ignoresThrowable()
    {
        return false;
    }

    public void activateOptions()
    {
    }

    public boolean isTimeAdded()
    {
        return timeAdded;
    }

    public void setTimeAdded(boolean addTime)
    {
        this.timeAdded = addTime;
    }

}

@@ -171,16 +171,56 @@
 ent;%0D%0A%0D%0A
+import be.ibridge.kettle.core.Const;%0D%0A%0D%0A
 public c
@@ -462,20 +462,231 @@
     
-String line=
+// OK, perhaps the logging information has multiple lines of data.%0D%0A        // We need to split this up into different lines and all format these lines...%0D%0A        String line=%22%22;%0D%0A        %0D%0A        String dateTimeString = 
 %22%22;%0D
@@ -813,22 +813,33 @@
         
-line+=
+dateTimeString = 
 df.forma
@@ -1047,16 +1047,18 @@
 bject;%0D%0A
+%0D%0A
         
@@ -1053,34 +1053,344 @@
 %0D%0A%0D%0A            
-%0D%0A
+String parts%5B%5D = message.getMessage().split(Const.CR);%0D%0A            for (int i=0;i%3Cparts.length;i++)%0D%0A            %7B%0D%0A                // Start every line of the output with a dateTimeString%0D%0A                line+=dateTimeString;%0D%0A                %0D%0A                // Include the subject too on every line...%0D%0A    
             if (
@@ -1422,35 +1422,43 @@
 l)%0D%0A            
+ 
-%7B%0D%0A
+   %7B%0D%0A    
                 
@@ -1496,37 +1496,60 @@
 %22;%0D%0A            
-%7D%0D%0A%0D%0A
+    %7D%0D%0A                %0D%0A   
             if (
@@ -1536,32 +1536,33 @@
 %0A               
+ 
 if (message.isEr
@@ -1575,32 +1575,36 @@
   %0D%0A            
+    
 %7B%0D%0A             
@@ -1602,24 +1602,28 @@
             
+  
+  
 line+=%22ERROR
@@ -1633,32 +1633,36 @@
 %22;%0D%0A            
+    
 %7D%0D%0A            %0D
@@ -1652,34 +1652,42 @@
  %7D%0D%0A            
+ 
-%0D%0A
+   %0D%0A    
             line
@@ -1692,29 +1692,118 @@
 ne+=
-message.getMessage();
+parts%5Bi%5D;%0D%0A                if (i%3Cparts.length-1) line+=Const.CR; // put the CR's back in there!%0D%0A            %7D
 %0D%0A  
@@ -1854,16 +1854,31 @@
   line+=
+dateTimeString+
 object.t

Fix for: Tracker: Bug - [# 1843] Logging not filtered correctly Add timestamp and subject on every line.