Skip to content

Commit

Permalink
[DOXIA-534] Migrate logging to slf4j and deprecate doxia-logging-api
Browse files Browse the repository at this point in the history
Deprecate doxia-logging-api based on plexus and implement logging based on slf4j.
  • Loading branch information
slachiewicz committed Feb 11, 2018
1 parent 7edfd00 commit b2a21de
Show file tree
Hide file tree
Showing 30 changed files with 268 additions and 84 deletions.
10 changes: 10 additions & 0 deletions doxia-core/pom.xml
Expand Up @@ -42,6 +42,16 @@ under the License.
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-logging-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -60,8 +59,6 @@ public void parse( Reader source, String parserId, Sink sink )
{
Parser parser = parserManager.getParser( parserId );

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

parser.parse( source, sink );
}

Expand Down
Expand Up @@ -22,10 +22,12 @@
import java.util.Map;

import org.apache.maven.doxia.logging.Log;
import org.apache.maven.doxia.logging.SystemStreamLog;
import org.apache.maven.doxia.logging.Slf4jLoggerWrapper;
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>.
Expand All @@ -38,29 +40,31 @@ public abstract class AbstractMacro
implements Macro
{
/** Log instance. */
private Log logger;
private Log log;

/** {@inheritDoc} */
public void enableLogging( Log log )
{
this.logger = log;
this.log = log;
}
protected Logger logger = LoggerFactory.getLogger( getClass() );

/**
* Returns a logger for this macro.
* If no logger has been configured, a new SystemStreamLog is returned.
*
* @return Log
* @since 1.1
* @deprecated use slf4j Loggers
*/
protected Log getLog()
{
if ( logger == null )
if ( log == null )
{
logger = new SystemStreamLog();
log = new Slf4jLoggerWrapper( logger );
}

return logger;
return log;
}

/**
Expand Down
Expand Up @@ -209,7 +209,7 @@ private StringBuffer getSnippet( URL url, String encoding, String id )
{
if ( ignoreDownloadError )
{
getLog().debug( "IOException which reading " + url + ": " + e );
logger.debug( "IOException which reading " + url + ": " + e );
result =
new StringBuffer( "Error during retrieving content skip as ignoreDownloadError activated." );
}
Expand Down
Expand Up @@ -28,14 +28,16 @@
import java.util.Properties;

import org.apache.maven.doxia.logging.Log;
import org.apache.maven.doxia.logging.SystemStreamLog;
import org.apache.maven.doxia.logging.Slf4jLoggerWrapper;
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.
Expand All @@ -55,8 +57,9 @@ public abstract class AbstractParser
private MacroManager macroManager;

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

protected Logger logger = LoggerFactory.getLogger( getClass() );
/**
* Emit Doxia comment events when parsing comments?
*/
Expand Down Expand Up @@ -131,8 +134,6 @@ public void executeMacro( String macroId, MacroRequest request, Sink sink )
{
Macro macro = getMacroManager().getMacro( macroId );

macro.enableLogging( getLog() );

macro.execute( sink, request );
}

Expand Down Expand Up @@ -203,7 +204,7 @@ protected boolean isSecondParsing()
/** {@inheritDoc} */
public void enableLogging( Log log )
{
this.logger = log;
this.log = log;
}

/**
Expand All @@ -212,15 +213,16 @@ public void enableLogging( Log log )
*
* @return Log
* @since 1.1
* @deprecated use slf4j Loggers
*/
protected Log getLog()
{
if ( logger == null )
if ( log == null )
{
logger = new SystemStreamLog();
log = new Slf4jLoggerWrapper( logger );
}

return logger;
return log;
}

/**
Expand Down
Expand Up @@ -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 );
}
Expand All @@ -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 )
Expand Down
Expand Up @@ -739,13 +739,13 @@ protected void handleStartTag( XmlPullParser parser, Sink sink )
{
if ( !baseStartTag( parser, sink ) )
{
if ( getLog().isWarnEnabled() )
if ( logger.isWarnEnabled() )
{
String position = "[" + parser.getLineNumber() + ":"
+ parser.getColumnNumber() + "]";
String tag = "<" + parser.getName() + ">";

getLog().warn( "Unrecognized xml tag: " + tag + " at " + position );
logger.warn( "Unrecognized xml tag: " + tag + " at " + position );
}
}
}
Expand Down Expand Up @@ -1270,9 +1270,9 @@ else if ( "right".equals( align ) )
private void logMessage( String key, String msg )
{
final String log = "[XHTML Parser] " + msg;
if ( getLog().isDebugEnabled() )
if ( logger.isDebugEnabled() )
{
getLog().debug( log );
logger.debug( log );

return;
}
Expand All @@ -1296,13 +1296,13 @@ private void logMessage( String key, String msg )
*/
private void logWarnings()
{
if ( getLog().isWarnEnabled() && this.warnMessages != null && !isSecondParsing() )
if ( logger.isWarnEnabled() && this.warnMessages != null && !isSecondParsing() )
{
for ( Map.Entry<String, Set<String>> entry : this.warnMessages.entrySet() )
{
for ( String msg : entry.getValue() )
{
getLog().warn( msg );
logger.warn( msg );
}
}

Expand Down
Expand Up @@ -20,9 +20,11 @@
*/

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

/**
* An abstract base class that defines some convenience methods for sinks.
Expand All @@ -35,28 +37,31 @@
public abstract class AbstractSink
implements Sink, Markup
{
private Log logger;
private Log log;

protected Logger logger = LoggerFactory.getLogger( getClass() );

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

/**
* Returns a logger for this sink.
* If no logger has been configured, a new SystemStreamLog is returned.
*
* @return Log
* @deprecated use slf4j Loggers
*/
protected Log getLog()
{
if ( logger == null )
if ( log == null )
{
logger = new SystemStreamLog();
log = new Slf4jLoggerWrapper( logger );
}

return logger;
return log;
}

/**
Expand Down
Expand Up @@ -1227,10 +1227,7 @@ public void table_()

if ( this.tableContentWriterStack.isEmpty() )
{
if ( getLog().isWarnEnabled() )
{
getLog().warn( "No table content." );
}
logger.warn( "No table content." );
return;
}

Expand Down Expand Up @@ -1896,7 +1893,7 @@ public void comment( String comment )

if ( !originalComment.equals( comment ) )
{
getLog().warn( "[Xhtml Sink] Modified invalid comment '" + originalComment + "' to '" + comment + "'" );
logger.warn( "[Xhtml Sink] Modified invalid comment '" + originalComment + "' to '" + comment + "'" );
}

final StringBuilder buffer = new StringBuilder( comment.length() + 7 );
Expand Down Expand Up @@ -2033,13 +2030,13 @@ public void close()
{
writer.close();

if ( getLog().isWarnEnabled() && this.warnMessages != null )
if ( logger.isWarnEnabled() && this.warnMessages != null )
{
for ( Map.Entry<String, Set<String>> entry : this.warnMessages.entrySet() )
{
for ( String msg : entry.getValue() )
{
getLog().warn( msg );
logger.warn( msg );
}
}

Expand Down Expand Up @@ -2174,9 +2171,9 @@ protected void writeEndTag( Tag t )
private void logMessage( String key, String msg )
{
final String mesg = "[XHTML Sink] " + msg;
if ( getLog().isDebugEnabled() )
if ( logger.isDebugEnabled() )
{
getLog().debug( mesg );
logger.debug( mesg );

return;
}
Expand Down

0 comments on commit b2a21de

Please sign in to comment.