On Tue, 26 Jun 2001 09:01, Mohit Dilawari wrote:
> I am trying to use LogKit and I am having a bit of
> trouble appending messages.
>
> I create a log file in a shell script and then I pass
> the location of the logfile to a java program.  I
> would like LogKit to append debug messages to this
> file.
>
> Unfortunately, LogKit seems to delete the log file
> before it writes to the logfile.
>
> How do I append trace messages to a file that is
> already created from LogKit?
>
> The following is my code snippet:
>
>       Logger logger =
> Hierarchy.getDefaultHierarchy().getLoggerFor("myCategory");
>
>       FileOutputLogTarget target = new
> FileOutputLogTarget("C:\\SOD\\code\\test\\output\\out1.txt");
>                       target.setFormat( "%7.7{priority} %5.5{time}
> [%8.8{category}] " +
>                   "(%{context}):
> %{message}\\n%{throwable}" );
>
>       logger.setLogTargets( new LogTarget[] { target } );
>
>
>       logger.setPriority( Priority.DEBUG );
>       logger.debug( "This is a debug message" );

Thats the desired behaviour ;) Probably the best thing you could do would be 
to add a new LogTarget such as

public class MyFileOutputLogTarget
    extends DefaultOutputLogTarget
{
    public void setFilename( final String filename )
        throws IOException
    {
        final File file = new File( filename );
        final File parent = file.getAbsoluteFile().getParentFile();
        if( !parent.exists() ) parent.mkdirs();
        
        //Next line is different and tells system to append
        m_output = new FileWriter( filename, true );
    }
}


Cheers,

Pete

*-----------------------------------------------------*
| "Faced with the choice between changing one's mind, |
| and proving that there is no need to do so - almost |
| everyone gets busy on the proof."                   |
|              - John Kenneth Galbraith               |
*-----------------------------------------------------*

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to