February 13, 2007 Continuous Integration

Shh, Keep it Quiet

Sometimes you just wish there was a way to make it secret.  It was really simple.

<target name="test" >
  <exec program="ping" commandline="localhost" output="c:\temp\ping.log" />
  <echo message="before"/>
  <loglevel level="None">
    <do>
      <exec program="ping" commandline="localhost" output="c:\temp\ping.log"/>
    </do>
  </loglevel>
  <echo message="after"/>
</target>

test:

     [exec] Starting ‘ping (localhost)’ in ‘C:\Projects\CI Factory\Current\Product\nAnt Scratch’
     [exec]
     [exec]
     [exec] Pinging jflowersxp5.CHCSII.COM [::1] with 32 bytes of data:
     [exec]
     [exec]
     [exec]
     [exec] Reply from ::1: time<1ms
     [exec]
     [exec] Reply from ::1: time<1ms
     [exec]
     [exec] Reply from ::1: time<1ms
     [exec]
     [exec] Reply from ::1: time<1ms
     [exec]
     [exec]
     [exec]
     [exec] Ping statistics for ::1:
     [exec]
     [exec]     Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
     [exec]
     [exec] Approximate round trip times in milli-seconds:
     [exec]
     [exec]     Minimum = 0ms, Maximum = 0ms, Average = 0ms
     [exec]
     [echo] before
     [echo] after

BUILD SUCCEEDED

Total time: 7.1 seconds.

[TaskName("loglevel")]
public class LogLevelTask : Task
{
    private Level _LogLevel;
    private TaskContainer _Tasks;

    [BuildElement("do", Required = true)]
    public TaskContainer Tasks
    {
        get
        {
            return _Tasks;
        }
        set
        {
            _Tasks = value;
        }
    }

    [TaskAttribute("level", Required = true)]
    public Level LogLevel
    {
        get
        {
            return _LogLevel;
        }
        set
        {
            _LogLevel = value;
        }
    }

    protected override void ExecuteTask()
    {
        Level OldLevel = this.Project.Threshold;
        this.Project.Threshold = this.LogLevel;
        this.Tasks.Execute();
        this.Project.Threshold = OldLevel;

    }
}

18,840 Total Views

9 to “Shh, Keep it Quiet”

  1. JohnF says...

    I have no idea what you’re trying to say here.

  2. jflowers says...

    I am saying this task lets you change the current log level. An application is to set the log level to None. So anything executed in the do block of the example is not logged. That is why in the example output you see the before and after echos adjacent. You don’t see the ping output logged in between the before and after echos.

  3. Will Buttitta says...

    I had problems silencing the exec task using the custom loglevel task where I was exec’ing a subversion list command. Instead setting the threshold directly on the nested tasks did the trick. I used the following modification of the original idea:

    using System;
    using NAnt.Core;
    using NAnt.Core.Types;
    using NAnt.Core.Attributes;

    namespace NAnt.Tasks
    {
    ///
    /// An NAnt task to set the logging of all tasks nested
    /// within this container.
    ///
    ///
    /// All tasks have a property which is not currently exposed
    /// to the build script author. In theory the threshold can be set at the project
    /// level but for some tasks this does not work properly.
    ///
    [TaskName("loglevel")]
    public class LogLevelTask : TaskContainer
    {
    private Level _logLevel;

    ///
    /// The logging at which all nested tasks should be configured.
    ///
    [TaskAttribute("level", Required = true)]
    public Level LogLevel
    {
    get
    {
    return _logLevel;
    }

    set
    {
    _logLevel = value;
    }
    }

    ///
    /// Sets the for a nested task.
    ///
    protected override Task CreateChildTask(System.Xml.XmlNode node)
    {
    Task t = base.CreateChildTask(node);
    t.Threshold = _logLevel;
    return t;
    }
    }
    }

  4. jflowers says...

    This has the potential to be wicked. As you have encountered it may be necessary to set the Threshold property of nested tasks. This could get out of hand. A deeper look for a simple solution is needed.

  5. Rob says...

    Nice bit of code. Unfortunately I tried it but it didn’t work. I still get the output.

    I’m using an “exec” that calls a .bat file which does a load of copy commands.

    I tried Will Buttitta’s solution. That stopped the output, but also meant the task didn’t actually run!

    Back to the drawing board. Am trying to make my NAnt logs as clean as possible, and when running our build via command line (we have a go.bat) in colour (but I need to recompile NAnt).

  6. lethaldisease6363.soup.io says...

    Très plaisant, mon petit doigt me dit que cet article
    devrait intéresser un mec

  7. éjaculation sur la tronche says...

    Je vais te dire que ce n’est guère erroné !!

  8. Endurableobject64.deviantart.com says...

    Je vois tout de suite que vous connaissez bien le sujet

  9. خرید vpn says...

    very nice

Leave a comment

*

here