You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Balazs Toth <zs...@gmail.com> on 2018/11/13 20:24:19 UTC

[logging] java8 default interface methods for lazy log payload object creation

Hi,

I am wondering to extend the org.apache.commons.logging.Log interface with default methods. 

It could simplify the usage, instead of

if (log.isDebugEnabled()) {
	log.debug("something heavy  " + here);
}

could use lambda expression
log.debug(() -> "something heavy  " + here);

to prevent the payload creation if the certain log level not enabled.

so the org.apache.commons.logging.Log interface would get the following default methods:

	default void debug(Supplier<Object> msgSupplier) {
		if (isDebugEnabled()) {
			debug(msgSupplier != null ? msgSupplier.get() : null);
		}
	}

	default void debug(Supplier<Object> msgSupplier, Throwable t) {
		if (isDebugEnabled()) {
			debug(msgSupplier != null ? msgSupplier.get() : null, t);
		}
	}

of course not just for debug, I would create for all the log levels.

Obviously that should need a new version like 1.3.0 because the Java source and target level must raise to 1.8 from the current 1.6.

What do you think, is the community would accept this change?

Regards, Balazs

Re: [logging] java8 default interface methods for lazy log payload object creation

Posted by Matt Sicker <bo...@gmail.com>.
On Tue, 13 Nov 2018 at 15:21, Gary Gregory <ga...@gmail.com> wrote:

> On Tue, Nov 13, 2018 at 2:03 PM Matt Sicker <bo...@gmail.com> wrote:
>
> > I thought Commons Logging 1.2 required Java 1.2? Big leap to 8!
> >
>
> The current POM requires Java 6.
>

I must have confused that with the prior release then which is Java 1.1 I
think.

-- 
Matt Sicker <bo...@gmail.com>

Re: [logging] java8 default interface methods for lazy log payload object creation

Posted by Gary Gregory <ga...@gmail.com>.
On Tue, Nov 13, 2018 at 2:03 PM Matt Sicker <bo...@gmail.com> wrote:

> I thought Commons Logging 1.2 required Java 1.2? Big leap to 8!
>

The current POM requires Java 6.

Gary


>
> Same bias here for Log4j2, though adding simple default methods like that
> would be neat for any APIs stuck using it (like Spring Framework for
> example).
>
> On Tue, 13 Nov 2018 at 14:52, Gary Gregory <ga...@gmail.com> wrote:
>
> > Hi Balazs,
> >
> > To me, as a biased contributor to Apache Log4j 2, I think the Log4j API
> > should be new facade to use instead of Commons Logging.
> >
> > That said, please feel free to contribute PRs to Commons Logging for
> those
> > using that API ;-)
> >
> > https://github.com/apache/commons-logging
> >
> > Gary
> >
> > On Tue, Nov 13, 2018 at 1:24 PM Balazs Toth <zs...@gmail.com> wrote:
> >
> > > Hi,
> > >
> > > I am wondering to extend the org.apache.commons.logging.Log interface
> > with
> > > default methods.
> > >
> > > It could simplify the usage, instead of
> > >
> > > if (log.isDebugEnabled()) {
> > >         log.debug("something heavy  " + here);
> > > }
> > >
> > > could use lambda expression
> > > log.debug(() -> "something heavy  " + here);
> > >
> > > to prevent the payload creation if the certain log level not enabled.
> > >
> > > so the org.apache.commons.logging.Log interface would get the following
> > > default methods:
> > >
> > >         default void debug(Supplier<Object> msgSupplier) {
> > >                 if (isDebugEnabled()) {
> > >                         debug(msgSupplier != null ? msgSupplier.get() :
> > > null);
> > >                 }
> > >         }
> > >
> > >         default void debug(Supplier<Object> msgSupplier, Throwable t) {
> > >                 if (isDebugEnabled()) {
> > >                         debug(msgSupplier != null ? msgSupplier.get() :
> > > null, t);
> > >                 }
> > >         }
> > >
> > > of course not just for debug, I would create for all the log levels.
> > >
> > > Obviously that should need a new version like 1.3.0 because the Java
> > > source and target level must raise to 1.8 from the current 1.6.
> > >
> > > What do you think, is the community would accept this change?
> > >
> > > Regards, Balazs
> >
>
>
> --
> Matt Sicker <bo...@gmail.com>
>

Re: [logging] java8 default interface methods for lazy log payload object creation

Posted by Matt Sicker <bo...@gmail.com>.
I thought Commons Logging 1.2 required Java 1.2? Big leap to 8!

Same bias here for Log4j2, though adding simple default methods like that
would be neat for any APIs stuck using it (like Spring Framework for
example).

On Tue, 13 Nov 2018 at 14:52, Gary Gregory <ga...@gmail.com> wrote:

> Hi Balazs,
>
> To me, as a biased contributor to Apache Log4j 2, I think the Log4j API
> should be new facade to use instead of Commons Logging.
>
> That said, please feel free to contribute PRs to Commons Logging for those
> using that API ;-)
>
> https://github.com/apache/commons-logging
>
> Gary
>
> On Tue, Nov 13, 2018 at 1:24 PM Balazs Toth <zs...@gmail.com> wrote:
>
> > Hi,
> >
> > I am wondering to extend the org.apache.commons.logging.Log interface
> with
> > default methods.
> >
> > It could simplify the usage, instead of
> >
> > if (log.isDebugEnabled()) {
> >         log.debug("something heavy  " + here);
> > }
> >
> > could use lambda expression
> > log.debug(() -> "something heavy  " + here);
> >
> > to prevent the payload creation if the certain log level not enabled.
> >
> > so the org.apache.commons.logging.Log interface would get the following
> > default methods:
> >
> >         default void debug(Supplier<Object> msgSupplier) {
> >                 if (isDebugEnabled()) {
> >                         debug(msgSupplier != null ? msgSupplier.get() :
> > null);
> >                 }
> >         }
> >
> >         default void debug(Supplier<Object> msgSupplier, Throwable t) {
> >                 if (isDebugEnabled()) {
> >                         debug(msgSupplier != null ? msgSupplier.get() :
> > null, t);
> >                 }
> >         }
> >
> > of course not just for debug, I would create for all the log levels.
> >
> > Obviously that should need a new version like 1.3.0 because the Java
> > source and target level must raise to 1.8 from the current 1.6.
> >
> > What do you think, is the community would accept this change?
> >
> > Regards, Balazs
>


-- 
Matt Sicker <bo...@gmail.com>

Re: [logging] java8 default interface methods for lazy log payload object creation

Posted by Gary Gregory <ga...@gmail.com>.
Hi Balazs,

To me, as a biased contributor to Apache Log4j 2, I think the Log4j API
should be new facade to use instead of Commons Logging.

That said, please feel free to contribute PRs to Commons Logging for those
using that API ;-)

https://github.com/apache/commons-logging

Gary

On Tue, Nov 13, 2018 at 1:24 PM Balazs Toth <zs...@gmail.com> wrote:

> Hi,
>
> I am wondering to extend the org.apache.commons.logging.Log interface with
> default methods.
>
> It could simplify the usage, instead of
>
> if (log.isDebugEnabled()) {
>         log.debug("something heavy  " + here);
> }
>
> could use lambda expression
> log.debug(() -> "something heavy  " + here);
>
> to prevent the payload creation if the certain log level not enabled.
>
> so the org.apache.commons.logging.Log interface would get the following
> default methods:
>
>         default void debug(Supplier<Object> msgSupplier) {
>                 if (isDebugEnabled()) {
>                         debug(msgSupplier != null ? msgSupplier.get() :
> null);
>                 }
>         }
>
>         default void debug(Supplier<Object> msgSupplier, Throwable t) {
>                 if (isDebugEnabled()) {
>                         debug(msgSupplier != null ? msgSupplier.get() :
> null, t);
>                 }
>         }
>
> of course not just for debug, I would create for all the log levels.
>
> Obviously that should need a new version like 1.3.0 because the Java
> source and target level must raise to 1.8 from the current 1.6.
>
> What do you think, is the community would accept this change?
>
> Regards, Balazs