From doxia-commits-return-750-apmail-maven-doxia-commits-archive=maven.apache.org@maven.apache.org Fri Feb 15 13:15:04 2008 Return-Path: Delivered-To: apmail-maven-doxia-commits-archive@www.apache.org Received: (qmail 83576 invoked from network); 15 Feb 2008 13:15:03 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 15 Feb 2008 13:15:03 -0000 Received: (qmail 98796 invoked by uid 500); 15 Feb 2008 13:14:58 -0000 Delivered-To: apmail-maven-doxia-commits-archive@maven.apache.org Received: (qmail 98755 invoked by uid 500); 15 Feb 2008 13:14:58 -0000 Mailing-List: contact doxia-commits-help@maven.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: doxia-dev@maven.apache.org Delivered-To: mailing list doxia-commits@maven.apache.org Received: (qmail 98744 invoked by uid 99); 15 Feb 2008 13:14:57 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Feb 2008 05:14:57 -0800 X-ASF-Spam-Status: No, hits=-1998.0 required=10.0 tests=ALL_TRUSTED,URIBL_BLACK X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Feb 2008 13:14:26 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 653E91A9832; Fri, 15 Feb 2008 05:14:34 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r628055 - in /maven/doxia/doxia/trunk/doxia-logging-api: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/maven/ src/main/java/org/apache/maven/doxia/ src/main/java/org/apache/maven/doxi... Date: Fri, 15 Feb 2008 13:14:33 -0000 To: doxia-commits@maven.apache.org From: vsiveton@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080215131434.653E91A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: vsiveton Date: Fri Feb 15 05:14:31 2008 New Revision: 628055 URL: http://svn.apache.org/viewvc?rev=628055&view=rev Log: DOXIA-145: Adding logger feature o first import of new logging module o based on lukas's work o collaborative work after good discussions on IRC Added: maven/doxia/doxia/trunk/doxia-logging-api/ maven/doxia/doxia/trunk/doxia-logging-api/pom.xml (with props) maven/doxia/doxia/trunk/doxia-logging-api/src/ maven/doxia/doxia/trunk/doxia-logging-api/src/main/ maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/ maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/ maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/ maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/ maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/ maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/ maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/Log.java (with props) maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/LogEnabled.java (with props) maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/PlexusLoggerWrapper.java (with props) maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/SystemStreamLog.java (with props) Added: maven/doxia/doxia/trunk/doxia-logging-api/pom.xml URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-logging-api/pom.xml?rev=628055&view=auto ============================================================================== --- maven/doxia/doxia/trunk/doxia-logging-api/pom.xml (added) +++ maven/doxia/doxia/trunk/doxia-logging-api/pom.xml Fri Feb 15 05:14:31 2008 @@ -0,0 +1,41 @@ + + + + + + 4.0.0 + + + doxia + org.apache.maven.doxia + 1.0-beta-1-SNAPSHOT + + + doxia-logging-api + Doxia :: Sink API + Doxia Logging API. + + + + org.codehaus.plexus + plexus-container-default + + + Propchange: maven/doxia/doxia/trunk/doxia-logging-api/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/doxia/doxia/trunk/doxia-logging-api/pom.xml ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/Log.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/Log.java?rev=628055&view=auto ============================================================================== --- maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/Log.java (added) +++ maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/Log.java Fri Feb 15 05:14:31 2008 @@ -0,0 +1,188 @@ +package org.apache.maven.doxia.logging; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +/** + * This interface supplies the API for providing feedback to the user from + * a Parser or Sink, using standard Doxia channels. + *
+ * There should be no big surprises here, although you may notice that the methods accept + * java.lang.CharSequence rather than java.lang.String. This is provided mainly as a + * convenience, to enable developers to pass things like java.lang.StringBuffer directly into the logger, + * rather than formatting first by calling toString(). + *
+ * Based on org.apache.maven.plugin.logging.Log. + * + * @author jdcasey + * @author ltheussl + * @version $Id$ + * @since 1.0-beta-1 + */ +public interface Log +{ + /** Typecode for debugging messages. */ + int LEVEL_DEBUG = 0; + + /** Typecode for informational messages. */ + int LEVEL_INFO = 1; + + /** Typecode for warning messages. */ + int LEVEL_WARN = 2; + + /** Typecode for error messages. */ + int LEVEL_ERROR = 3; + + /** Typecode for fatal error messages. */ + int LEVEL_FATAL = 4; + + /** Typecode for disabled log levels. */ + int LEVEL_DISABLED = 5; + + /** + * Set the current log level. + * + * @param level the log level to set. + */ + void setLogLevel( int level ); + + /** + * @return true if the debug error level is enabled + */ + boolean isDebugEnabled(); + + /** + * Send a message to the user in the debug error level. + * + * @param content + */ + void debug( CharSequence content ); + + /** + * Send a message (and accompanying exception) to the user in the debug error level. + *
+ * The error's stacktrace will be output when this error level is enabled. + * + * @param content + * @param error + */ + void debug( CharSequence content, Throwable error ); + + /** + * Send an exception to the user in the debug error level. + *
+ * The stack trace for this exception will be output when this error level is enabled. + * + * @param error + */ + void debug( Throwable error ); + + /** + * @return true if the info error level is enabled + */ + boolean isInfoEnabled(); + + /** + * Send a message to the user in the info error level. + * + * @param content + */ + void info( CharSequence content ); + + /** + * Send a message (and accompanying exception) to the user in the info error level. + *
+ * The error's stacktrace will be output when this error level is enabled. + * + * @param content + * @param error + */ + void info( CharSequence content, Throwable error ); + + /** + * Send an exception to the user in the info error level. + *
+ * The stack trace for this exception will be output when this error level is enabled. + * + * @param error + */ + void info( Throwable error ); + + /** + * @return true if the warn error level is enabled + */ + boolean isWarnEnabled(); + + /** + * Send a message to the user in the warn error level. + * + * @param content + */ + void warn( CharSequence content ); + + /** + * Send a message (and accompanying exception) to the user in the warn error level. + *
+ * The error's stacktrace will be output when this error level is enabled. + * + * @param content + * @param error + */ + void warn( CharSequence content, Throwable error ); + + /** + * Send an exception to the user in the warn error level. + *
+ * The stack trace for this exception will be output when this error level is enabled. + * + * @param error + */ + void warn( Throwable error ); + + /** + * @return true if the error error level is enabled + */ + boolean isErrorEnabled(); + + /** + * Send a message to the user in the error error level. + * + * @param content + */ + void error( CharSequence content ); + + /** + * Send a message (and accompanying exception) to the user in the error error level. + *
+ * The error's stacktrace will be output when this error level is enabled. + * + * @param content + * @param error + */ + void error( CharSequence content, Throwable error ); + + /** + * Send an exception to the user in the error error level. + *
+ * The stack trace for this exception will be output when this error level is enabled. + * + * @param error + */ + void error( Throwable error ); +} Propchange: maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/Log.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/Log.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/LogEnabled.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/LogEnabled.java?rev=628055&view=auto ============================================================================== --- maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/LogEnabled.java (added) +++ maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/LogEnabled.java Fri Feb 15 05:14:31 2008 @@ -0,0 +1,40 @@ +package org.apache.maven.doxia.logging; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + + +/** + * An interface for Doxia components (mainly Sink, Parser and Macro) that need the ability to log. + *
+ * Based on org.codehaus.plexus.logging.LogEnabled. + * + * @author ltheussl + * @version $Id$ + * @since 1.0-beta-1 + */ +public interface LogEnabled +{ + /** + * Enable a Doxia logger for this Doxia component. + * + * @param log a Log. + */ + void enableLogging( Log log ); +} Propchange: maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/LogEnabled.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/LogEnabled.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/PlexusLoggerWrapper.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/PlexusLoggerWrapper.java?rev=628055&view=auto ============================================================================== --- maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/PlexusLoggerWrapper.java (added) +++ maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/PlexusLoggerWrapper.java Fri Feb 15 05:14:31 2008 @@ -0,0 +1,181 @@ +package org.apache.maven.doxia.logging; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +import org.apache.maven.doxia.logging.Log; + +import org.codehaus.plexus.logging.Logger; + +/** + * Wrap a Plexus logger into a Doxia logger. + * + * @author Vincent Siveton + * @version $Id$ + * @since 1.0-beta-1 + * @see org.apache.maven.plugin.logging.Logger + */ +public class PlexusLoggerWrapper + implements Log +{ + private final Logger logger; + + /** + * @param logger + */ + public PlexusLoggerWrapper( Logger logger ) + { + this.logger = logger; + } + + /** {@inheritDoc} */ + public void setLogLevel( int level ) + { + if ( level <= LEVEL_DEBUG ) + { + logger.setThreshold( Logger.LEVEL_DEBUG ); + } + else if ( level <= LEVEL_INFO ) + { + logger.setThreshold( Logger.LEVEL_INFO ); + } + else if ( level <= LEVEL_WARN ) + { + logger.setThreshold( Logger.LEVEL_WARN ); + } + else if ( level <= LEVEL_ERROR ) + { + logger.setThreshold( Logger.LEVEL_ERROR ); + } + else + { + logger.setThreshold( Logger.LEVEL_DISABLED ); + } + } + + /** {@inheritDoc} */ + public void debug( CharSequence content ) + { + logger.debug( toString( content ) ); + } + + /** {@inheritDoc} */ + public void debug( CharSequence content, Throwable error ) + { + logger.debug( toString( content ), error ); + } + + /** {@inheritDoc} */ + public void debug( Throwable error ) + { + logger.debug( "", error ); + } + + /** {@inheritDoc} */ + public void info( CharSequence content ) + { + logger.info( toString( content ) ); + } + + /** {@inheritDoc} */ + public void info( CharSequence content, Throwable error ) + { + logger.info( toString( content ), error ); + } + + /** {@inheritDoc} */ + public void info( Throwable error ) + { + logger.info( "", error ); + } + + /** {@inheritDoc} */ + public void warn( CharSequence content ) + { + logger.warn( toString( content ) ); + } + + /** {@inheritDoc} */ + public void warn( CharSequence content, Throwable error ) + { + logger.warn( toString( content ), error ); + } + + /** {@inheritDoc} */ + public void warn( Throwable error ) + { + logger.warn( "", error ); + } + + /** {@inheritDoc} */ + public void error( CharSequence content ) + { + logger.error( toString( content ) ); + } + + /** {@inheritDoc} */ + public void error( CharSequence content, Throwable error ) + { + logger.error( toString( content ), error ); + } + + /** {@inheritDoc} */ + public void error( Throwable error ) + { + logger.error( "", error ); + } + + /** {@inheritDoc} */ + public boolean isDebugEnabled() + { + return logger.isDebugEnabled(); + } + + /** {@inheritDoc} */ + public boolean isInfoEnabled() + { + return logger.isInfoEnabled(); + } + + /** {@inheritDoc} */ + public boolean isWarnEnabled() + { + return logger.isWarnEnabled(); + } + + /** {@inheritDoc} */ + public boolean isErrorEnabled() + { + return logger.isErrorEnabled(); + } + + // ---------------------------------------------------------------------- + // Private methods + // ---------------------------------------------------------------------- + + private String toString( CharSequence content ) + { + if ( content == null ) + { + return ""; + } + + return content.toString(); + } +} Propchange: maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/PlexusLoggerWrapper.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/PlexusLoggerWrapper.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/SystemStreamLog.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/SystemStreamLog.java?rev=628055&view=auto ============================================================================== --- maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/SystemStreamLog.java (added) +++ maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/SystemStreamLog.java Fri Feb 15 05:14:31 2008 @@ -0,0 +1,239 @@ +package org.apache.maven.doxia.logging; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +import java.io.PrintWriter; +import java.io.StringWriter; + +/** + * Logger with "standard" output and error output stream. The log prefix is voluntarily in lower case. + *
+ * Based on org.apache.maven.plugin.logging.SystemStreamLog. + * + * @author jdcasey + * @author ltheussl + * @version $Id$ + * @since 1.0-beta-1 + */ +public class SystemStreamLog + implements Log +{ + private static final String EOL = System.getProperty( "line.separator" ); + + private int currentLevel = LEVEL_INFO; + + /** {@inheritDoc} */ + public void setLogLevel( int level ) + { + if ( level <= LEVEL_DEBUG ) + { + currentLevel = LEVEL_DEBUG; + } + else if ( level <= LEVEL_INFO ) + { + currentLevel = LEVEL_INFO; + } + else if ( level <= LEVEL_WARN ) + { + currentLevel = LEVEL_WARN; + } + else if ( level <= LEVEL_ERROR ) + { + currentLevel = LEVEL_ERROR; + } + else + { + currentLevel = LEVEL_DISABLED; + } + } + + /** {@inheritDoc} */ + public void debug( CharSequence content ) + { + if ( isDebugEnabled() ) + { + print( "debug", content ); + } + } + + /** {@inheritDoc} */ + public void debug( CharSequence content, Throwable error ) + { + if ( isDebugEnabled() ) + { + print( "debug", content, error ); + } + } + + /** {@inheritDoc} */ + public void debug( Throwable error ) + { + if ( isDebugEnabled() ) + { + print( "debug", error ); + } + } + + /** {@inheritDoc} */ + public void info( CharSequence content ) + { + if ( isInfoEnabled() ) + { + print( "info", content ); + } + } + + /** {@inheritDoc} */ + public void info( CharSequence content, Throwable error ) + { + if ( isInfoEnabled() ) + { + print( "info", content, error ); + } + } + + /** {@inheritDoc} */ + public void info( Throwable error ) + { + if ( isInfoEnabled() ) + { + print( "info", error ); + } + } + + /** {@inheritDoc} */ + public void warn( CharSequence content ) + { + if ( isWarnEnabled() ) + { + print( "warn", content ); + } + } + + /** {@inheritDoc} */ + public void warn( CharSequence content, Throwable error ) + { + if ( isWarnEnabled() ) + { + print( "warn", content, error ); + } + } + + /** {@inheritDoc} */ + public void warn( Throwable error ) + { + if ( isWarnEnabled() ) + { + print( "warn", error ); + } + } + + /** {@inheritDoc} */ + public void error( CharSequence content ) + { + if ( isErrorEnabled() ) + { + System.err.println( "[error] " + content.toString() ); + } + } + + /** {@inheritDoc} */ + public void error( CharSequence content, Throwable error ) + { + if ( isErrorEnabled() ) + { + StringWriter sWriter = new StringWriter(); + PrintWriter pWriter = new PrintWriter( sWriter ); + + error.printStackTrace( pWriter ); + + System.err.println( "[error] " + content.toString() + + EOL + EOL + sWriter.toString() ); + } + } + + /** {@inheritDoc} */ + public void error( Throwable error ) + { + if ( isErrorEnabled() ) + { + StringWriter sWriter = new StringWriter(); + PrintWriter pWriter = new PrintWriter( sWriter ); + + error.printStackTrace( pWriter ); + + System.err.println( "[error] " + sWriter.toString() ); + } + } + + /** {@inheritDoc} */ + public boolean isDebugEnabled() + { + return ( currentLevel <= LEVEL_DEBUG ); + } + + /** {@inheritDoc} */ + public boolean isInfoEnabled() + { + return ( currentLevel <= LEVEL_INFO ); + } + + /** {@inheritDoc} */ + public boolean isWarnEnabled() + { + return ( currentLevel <= LEVEL_WARN ); + } + + /** {@inheritDoc} */ + public boolean isErrorEnabled() + { + return ( currentLevel <= LEVEL_ERROR ); + } + + // + // private + // + + private void print( String prefix, CharSequence content ) + { + System.out.println( "[" + prefix + "] " + content.toString() ); + } + + private void print( String prefix, Throwable error ) + { + StringWriter sWriter = new StringWriter(); + PrintWriter pWriter = new PrintWriter( sWriter ); + + error.printStackTrace( pWriter ); + + System.out.println( "[" + prefix + "] " + sWriter.toString() ); + } + + private void print( String prefix, CharSequence content, Throwable error ) + { + StringWriter sWriter = new StringWriter(); + PrintWriter pWriter = new PrintWriter( sWriter ); + + error.printStackTrace( pWriter ); + + System.out.println( "[" + prefix + "] " + content.toString() + + EOL + EOL + sWriter.toString() ); + } +} Propchange: maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/SystemStreamLog.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/doxia/doxia/trunk/doxia-logging-api/src/main/java/org/apache/maven/doxia/logging/SystemStreamLog.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision"