Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOXIA-534] Migrate logging to Sl4j #5

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions doxia-core/pom.xml
Original file line number Diff line number Diff line change
@@ -39,8 +39,13 @@ under the License.
<artifactId>doxia-sink-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-logging-api</artifactId>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@
* under the License.
*/

import org.apache.maven.doxia.logging.PlexusLoggerWrapper;
import org.apache.maven.doxia.parser.ParseException;
import org.apache.maven.doxia.parser.Parser;
import org.apache.maven.doxia.parser.manager.ParserManager;
@@ -28,7 +27,6 @@

import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.AbstractLogEnabled;

import java.io.Reader;

@@ -42,7 +40,6 @@
*/
@Component( role = Doxia.class )
public class DefaultDoxia
extends AbstractLogEnabled
implements Doxia
{
@Requirement
@@ -60,8 +57,6 @@ public void parse( Reader source, String parserId, Sink sink )
{
Parser parser = parserManager.getParser( parserId );

parser.enableLogging( new PlexusLoggerWrapper( getLogger() ) );

parser.parse( source, sink );
}

Original file line number Diff line number Diff line change
@@ -21,11 +21,11 @@

import java.util.Map;

import org.apache.maven.doxia.logging.Log;
import org.apache.maven.doxia.logging.SystemStreamLog;
import org.apache.maven.doxia.sink.SinkEventAttributes;
import org.apache.maven.doxia.sink.impl.SinkEventAttributeSet;
import org.codehaus.plexus.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Abstract base class to execute <code>Macro</code>.
@@ -38,13 +38,7 @@ public abstract class AbstractMacro
implements Macro
{
/** Log instance. */
private Log logger;

/** {@inheritDoc} */
public void enableLogging( Log log )
{
this.logger = log;
}
private Logger logger;

/**
* Returns a logger for this macro.
@@ -53,11 +47,11 @@ public void enableLogging( Log log )
* @return Log
* @since 1.1
*/
protected Log getLog()
protected Logger getLog()
{
if ( logger == null )
{
logger = new SystemStreamLog();
logger = LoggerFactory.getLogger( this.getClass() );
}

return logger;
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@
* under the License.
*/

import org.apache.maven.doxia.logging.LogEnabled;
import org.apache.maven.doxia.sink.Sink;

/**
@@ -30,7 +29,6 @@
* @since 1.0
*/
public interface Macro
extends LogEnabled
{
/** The Plexus lookup role. */
String ROLE = Macro.class.getName();
Original file line number Diff line number Diff line change
@@ -27,15 +27,15 @@

import java.util.Properties;

import org.apache.maven.doxia.logging.Log;
import org.apache.maven.doxia.logging.SystemStreamLog;
import org.apache.maven.doxia.macro.Macro;
import org.apache.maven.doxia.macro.MacroExecutionException;
import org.apache.maven.doxia.macro.MacroRequest;
import org.apache.maven.doxia.macro.manager.MacroManager;
import org.apache.maven.doxia.macro.manager.MacroNotFoundException;
import org.apache.maven.doxia.sink.Sink;
import org.codehaus.plexus.component.annotations.Requirement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* An abstract base class that defines some convenience methods for parsers.
@@ -55,7 +55,7 @@ public abstract class AbstractParser
private MacroManager macroManager;

/** Log instance. */
private Log logger;
private Logger logger;

/**
* Emit Doxia comment events when parsing comments?
@@ -131,8 +131,6 @@ public void executeMacro( String macroId, MacroRequest request, Sink sink )
{
Macro macro = getMacroManager().getMacro( macroId );

macro.enableLogging( getLog() );

macro.execute( sink, request );
}

@@ -200,24 +198,18 @@ protected boolean isSecondParsing()
return secondParsing;
}

/** {@inheritDoc} */
public void enableLogging( Log log )
{
this.logger = log;
}

/**
* Returns the current logger for this parser.
* If no logger has been configured yet, a new SystemStreamLog is returned.
*
* @return Log
* @since 1.1
*/
protected Log getLog()
protected Logger getLog()
{
if ( logger == null )
{
logger = new SystemStreamLog();
logger = LoggerFactory.getLogger( this.getClass() );
}

return logger;
Original file line number Diff line number Diff line change
@@ -124,7 +124,7 @@ public void parse( Reader source, Sink sink )
throw new ParseException( "Error reading the model: " + e.getMessage(), e );
}

new XmlValidator( getLog() ).validate( content );
new XmlValidator( ).validate( content );

src = new StringReader( content );
}
@@ -140,8 +140,6 @@ public void parse( Reader source, Sink sink )
// Note: do it after input is set, otherwise values are reset
initXmlParser( parser );

sink.enableLogging( getLog() );

parseXml( parser, sink );
}
catch ( XmlPullParserException ex )
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@
* under the License.
*/

import org.apache.maven.doxia.logging.LogEnabled;
import org.apache.maven.doxia.sink.Sink;

import java.io.Reader;
@@ -34,7 +33,6 @@
* @since 1.0
*/
public interface Parser
extends LogEnabled
{
/** The Plexus lookup role. */
String ROLE = Parser.class.getName();
Original file line number Diff line number Diff line change
@@ -19,10 +19,10 @@
* under the License.
*/

import org.apache.maven.doxia.logging.Log;
import org.apache.maven.doxia.logging.SystemStreamLog;
import org.apache.maven.doxia.markup.Markup;
import org.apache.maven.doxia.sink.Sink;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* An abstract base class that defines some convenience methods for sinks.
@@ -35,25 +35,19 @@
public abstract class AbstractSink
implements Sink, Markup
{
private Log logger;

/** {@inheritDoc} */
public void enableLogging( Log log )
{
this.logger = log;
}
private Logger logger;

/**
* Returns a logger for this sink.
* If no logger has been configured, a new SystemStreamLog is returned.
*
* @return Log
*/
protected Log getLog()
protected Logger getLog()
{
if ( logger == null )
{
logger = new SystemStreamLog();
logger = LoggerFactory.getLogger( this.getClass() );
}

return logger;
Original file line number Diff line number Diff line change
@@ -27,7 +27,6 @@
import java.util.ArrayList;
import java.util.List;

import org.apache.maven.doxia.logging.Log;
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.doxia.sink.SinkEventAttributes;
import org.apache.maven.doxia.sink.SinkFactory;
@@ -920,10 +919,4 @@ public void verbatim_()
{
currentSink.verbatim_();
}

@Override
public void enableLogging( Log log )
{
currentSink.enableLogging( log );
}
}
Original file line number Diff line number Diff line change
@@ -27,11 +27,12 @@

import javax.xml.XMLConstants;

import org.apache.maven.doxia.logging.Log;
import org.apache.maven.doxia.markup.XmlMarkup;
import org.apache.maven.doxia.parser.AbstractXmlParser.CachedFileEntityResolver;
import org.apache.maven.doxia.parser.ParseException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
@@ -59,16 +60,15 @@ public class XmlValidator
/** lazy xmlReader to validate xml content*/
private XMLReader xmlReader;

private Log logger;
private Logger logger = LoggerFactory.getLogger( XmlValidator.class );

/**
* Constructor.
*
* @param log a logger, not null.
*/
public XmlValidator( Log log )
public XmlValidator( )
{
this.logger = log;

}

/**
@@ -127,7 +127,7 @@ private XMLReader getXmlReader( boolean hasDtdAndXsd )
{
if ( xmlReader == null )
{
MessagesErrorHandler errorHandler = new MessagesErrorHandler( getLog() );
MessagesErrorHandler errorHandler = new MessagesErrorHandler( );

xmlReader = XMLReaderFactory.createXMLReader();
xmlReader.setFeature( "http://xml.org/sax/features/validation", true );
@@ -141,7 +141,7 @@ private XMLReader getXmlReader( boolean hasDtdAndXsd )
return xmlReader;
}

private Log getLog()
private Logger getLog()
{
return logger;
}
@@ -166,13 +166,12 @@ private static class MessagesErrorHandler
private static final Pattern ELEMENT_TYPE_PATTERN =
Pattern.compile( "Element type \".*\" must be declared.", Pattern.DOTALL );

private final Log log;
private final Logger log = LoggerFactory.getLogger( MessagesErrorHandler.class );

private boolean hasDtdAndXsd;

private MessagesErrorHandler( Log log )
private MessagesErrorHandler( )
{
this.log = log;
}

/**
Original file line number Diff line number Diff line change
@@ -74,7 +74,6 @@ public void testExecute()
public void testLog()
{
EchoMacro macro = new EchoMacro();
macro.enableLogging( null );
assertNotNull ( macro.getLog() );
assertNotNull ( macro.getLog() );
}
Original file line number Diff line number Diff line change
@@ -26,7 +26,6 @@

import org.apache.maven.doxia.AbstractModuleTest;

import org.apache.maven.doxia.logging.PlexusLoggerWrapper;
import org.apache.maven.doxia.parser.ParseException;
import org.apache.maven.doxia.parser.Parser;

@@ -108,7 +107,6 @@ public void testIdentity()
writer = new StringWriter();
sink = new TextSink( writer );
Parser parser = createParser();
parser.enableLogging( new PlexusLoggerWrapper( ( ( DefaultPlexusContainer )getContainer() ).getLogger() ) );
parser.parse( reader, sink );
String actual = writer.toString();

Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@

import java.util.Iterator;

import org.apache.maven.doxia.logging.Log;
import org.apache.maven.doxia.sink.impl.SinkEventAttributeSet;
import org.apache.maven.doxia.sink.impl.SinkEventElement;
import org.apache.maven.doxia.sink.impl.SinkEventTestingSink;
@@ -44,7 +43,6 @@ public class XhtmlBaseParserTest
protected Parser createParser()
{
parser = new XhtmlBaseParser();
parser.getLog().setLogLevel( Log.LEVEL_ERROR );
return parser;
}

@@ -60,7 +58,6 @@ protected void setUp() throws Exception
super.setUp();

parser = new XhtmlBaseParser();
parser.getLog().setLogLevel( Log.LEVEL_ERROR );
sink.reset();
}

Loading