/*
 * Copyright 2013 Andrew Everitt, Andrew Heckford, Daniele Masato
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package uk.org.raje.maven.plugin.msbuild.streamconsumers;

import org.apache.maven.plugin.logging.Log;
import org.codehaus.plexus.util.cli.StreamConsumer;

/**
 * StreamConsumer that writes lines from the stream to the supplied Log at 'info' level.
 */
public class StdoutStreamToLog implements StreamConsumer
{
    /**
     * Construct instance to log to specified Log
     * @param logger the Log to write to
     */
    public StdoutStreamToLog( Log logger ) 
    {
        this.logger = logger;
    }
    
    @Override
    public void consumeLine( String line )
    {
        if ( line.toLowerCase().contains( "warning:" ) )
        {
            logger.warn( line );
        }
        else
        {
            logger.info( line );
        }
    }
    
    private Log logger;
}

@@ -859,18 +859,138 @@
  Log
- at 'info'
+.%0A * The default is to log at 'info' level, we also try to identify error%0A * and warning messages and log these at the appropriate
  lev
@@ -1329,56 +1329,509 @@
     
-if ( line.toLowerCase().contains( %22warning:
+// Regex's devised using http://www.regexplanet.com/advanced/java/index.html%0A%0A        // Look for errors with Regex: .*((?:error%5C:)%7C(?:%5C: error (?:%5BA-Z%5D+%5B0-9%5D+)?%5C:)).*%0A        if ( line.matches( %22.*((?:error%5C%5C:)%7C(?:%5C%5C: error (?:%5BA-Z%5D+%5B0-9%5D+)?%5C%5C:)).*%22 ) )%0A        %7B%0A            logger.error( line );%0A        %7D%0A        // Look for warnings with Regex: .*((?:warning%5C:)%7C(?:%5C: warning (?:%5BA-Z%5D+%5B0-9%5D+)?%5C:)).*%0A        else if ( line.matches( %22.*((?:warning%5C%5C:)%7C(?:%5C%5C: warning (?:%5BA-Z%5D+%5B0-9%5D+)?%5C%5C:)).*
 %22 ) )
+ 
 %0A   

Enhance logging of output captured from tools (MSBuild, CppCheck etc) to identify warning and error messages and log at the appropriate level.