writing to ant's logger from external type

View: New views
2 Messages — Rating Filter:   Alert me  

writing to ant's logger from external type

by ruel loehr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've written a task which uses a custom data type.   I'd like to be able to write log messages from within that type using ANT's logging mechanism.   If I use that type independently, I'd like to just write to System.out.

Does anyone know of a way to pass ants logger to an external type such that I could do something like this:


If (logger !=null)
            Logger.LogMessage("My message");
Else
            System.out.println("My message");


Thanks!
R Loehr

Re: writing to ant's logger from external type

by Stefan Bodewig :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 17 Jun 2008, Ruel Loehr <rloehr@...> wrote:

> Does anyone know of a way to pass ants logger to an external type

Not Ant's logger (since there could be more than one BuildListener
attached), but the Project instance that is running Ant.

If your type defines a method of signature

public void setProject(org.apache.tools.ant.Project)

Ant will inject the current project instance into your type when
creating it and you can use project.logMessage and friends.

> such that I could do something like this:
>
> If (logger !=null)
>             Logger.LogMessage("My message");
> Else
>             System.out.println("My message");

Or you can always log to System.out/err.  Everything that goes to
System.err will end up as WARN message in Ant's logging system,
System.out as INFO (the default level).

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@...
For additional commands, e-mail: user-help@...

LightInTheBox - Buy quality products at wholesale price