On 6/10/11 3:48 AM, Mark Struberg wrote:
We partly use slf4j internally already for tests, etc.
But moving the whole Logger mess over to slf4j would be really great. There are
lots of tests (I sadly also found productive code too) still using
System.out.println.
The question is if we (internally) drop org.codehaus.plexus.logging.Logger
completely and use slf4j directly, or if we pimp up the plexus Logger and add
various stuff.
I've been thinking about this for some time now, actually. If you look
at the MAE stuff in the sandbox, I'm pretty sure that's using log4j
directly.
Personally, I don't understand what value the Plexus
logger/loggermanager has, especially given the configurability of these
other logging frameworks.
I'd be in favor of providing a "default" logging configuration file in
either the Maven app directory or in ~/.m2, and then letting people
customize from the command line to highlight specific components/packages.
Although, having said that, one of my pet peeves about the logging
frameworks is they haven't shifted to using String.format,
MessageFormat.format, or whatever under-the-covers as a way of limiting
string concatenation in cases where a particular log level has been
disabled.
Even something as simple as the attached code would be a nice facade for
logging, IMO...but it's more of a wish-list item than anything else.
In short, yes, let's think about switching to a better logging
framework. We can deprecate the plexus logger, and eventually get rid of it!
We would need to do some compat code anyway, but I'm not sure if it pays off to
restrict ourself. At least not after I saw that even the LoggerManager uses
System.err.println:
// TODO: use a logger!
System.err.println( "There was no such logger '" + key + "' " + hashCode() +
"." );
dumdidum :)
LieGrue,
strub
--- On Fri, 6/10/11, Ralph Goers<ralph.go...@dslextreme.com> wrote:
From: Ralph Goers<ralph.go...@dslextreme.com>
Subject: Re: Get thee to the Core...
To: "Maven Developers List"<dev@maven.apache.org>
Date: Friday, June 10, 2011, 5:03 AM
On Jun 9, 2011, at 2:45 PM, Benson Margulies wrote:
I'd like to offer a small suggestion.
One of the big barriers to maven happiness is the
difficulty of
understanding, in some cases, why it does what it
does.
This suggests to me three efforts that might offer an
opportunity to
learn core code without drowning.
1: take up slf4j, and thus allow component (indeed
class) by component
log control as an alternative to the giant -X spew.
Now that is an interesting idea. For the past year I have
been working on creating Log4j 2.0 pretty much by
myself. This would be a great way to integrate it into
something useful.
Ralph
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org
For additional commands, e-mail: dev-h...@maven.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org
For additional commands, e-mail: dev-h...@maven.apache.org
--
John Casey
Developer, PMC Member - Apache Maven (http://maven.apache.org)
Blog: http://www.johnofalltrades.name/
/*
* Copyright 2011 Red Hat, Inc.
*
* 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 org.commonjava.util.logging;
import org.slf4j.LoggerFactory;
import java.text.MessageFormat;
import java.util.IllegalFormatException;
public final class Logger
{
private final org.slf4j.Logger logger;
public Logger( Class<?> clazz )
{
logger = LoggerFactory.getLogger( clazz );
}
public Logger( String name )
{
logger = LoggerFactory.getLogger( name );
}
public Logger( org.slf4j.Logger logger )
{
this.logger = logger;
}
public org.slf4j.Logger getLogger()
{
return logger;
}
public Logger debug( String format, Object...params )
{
if ( logger.isDebugEnabled() )
{
logger.debug( format( format, params ) );
}
return this;
}
public Logger debug( String format, Throwable error, Object...params )
{
if ( logger.isDebugEnabled() )
{
logger.debug( format( format, params ), error );
}
return this;
}
public Logger error( String format, Object...params )
{
if ( logger.isErrorEnabled() )
{
logger.error( format( format, params ) );
}
return this;
}
public Logger error( String format, Throwable error, Object...params )
{
if ( logger.isErrorEnabled() )
{
logger.error( format( format, params ), error );
}
return this;
}
public Logger info( String format, Object...params )
{
if ( logger.isInfoEnabled() )
{
logger.info( format( format, params ) );
}
return this;
}
public Logger info( String format, Throwable error, Object...params )
{
if ( logger.isInfoEnabled() )
{
logger.info( format( format, params ), error );
}
return this;
}
public Logger trace( String format, Object...params )
{
if ( logger.isTraceEnabled() )
{
logger.trace( format( format, params ) );
}
return this;
}
public Logger trace( String format, Throwable error, Object...params )
{
if ( logger.isTraceEnabled() )
{
logger.trace( format( format, params ), error );
}
return this;
}
public Logger warn( String format, Object...params )
{
if ( logger.isWarnEnabled() )
{
logger.warn( format( format, params ) );
}
return this;
}
public Logger warn( String format, Throwable error, Object...params )
{
if ( logger.isWarnEnabled() )
{
logger.warn( format( format, params ), error );
}
return this;
}
private String format( String format, Object[] params )
{
String out = format;
if ( params == null || params.length < 1 )
{
return out;
}
try
{
out = String.format( out, params );
}
catch ( IllegalFormatException e )
{
try
{
out = MessageFormat.format( out, params );
}
catch ( IllegalArgumentException e1 )
{
out = format;
}
}
return out;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org
For additional commands, e-mail: dev-h...@maven.apache.org