logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <garydgreg...@gmail.com>
Subject Re: Pluggable message creation
Date Fri, 07 Dec 2012 02:56:43 GMT
Thank you Ralph for clearing things up.

I committed this first batch of changes. Next up: Surface this in the
LogManager API (tomorrow night for me, unless someone else gets to it.)

Gary


On Thu, Dec 6, 2012 at 6:38 PM, Ralph Goers <ralph.goers@dslextreme.com>wrote:

>
> On Dec 6, 2012, at 2:02 PM, Gary Gregory wrote:
>
> On Thu, Dec 6, 2012 at 3:01 PM, Ralph Goers <ralph.goers@dslextreme.com>wrote:
>
>>
>> On Dec 6, 2012, at 11:40 AM, Gary Gregory wrote:
>>
>> Hi Ralph and all,
>>
>> On Thu, Dec 6, 2012 at 11:14 AM, Ralph Goers <ralph.goers@dslextreme.com>wrote:
>>
>>>
>>> On Dec 6, 2012, at 6:04 AM, Gary Gregory wrote:
>>>
>>> I craeted https://issues.apache.org/jira/browse/LOG4J2-133 to save a
>>> patch.
>>>
>>> I'd like to discuss it on the ML here.
>>>
>>> Thoughts?
>>>
>>>
>>> Yeah, I have a few.
>>>
>>> First, I expected MessageFactory to be an interface, not a class.
>>>
>>
>> OK, we can do that.
>>
>>
>>>
>>> Second, I expected to see 3 MessageFactory implementations to start that
>>> would allow the user to choose between ParameterizedMessage,
>>> StringFormatMessage and MessageFormatMessage (I have that in the works for
>>> JUL support).
>>>
>>
>> OK, we can have one factory with 3 methods, or three factories with one
>> method each. I like your idea, but... that means the AbstractLogger needs
>> to track three factories instead of one.
>>
>>
>> I'm not sure I was clear. The 3 MessageFactory instances would be
>> StringFormatMessageFactory, MessageFormatMessageFactory and
>> ParameterizedMessageFactory.   The newMessage method that accepts a String
>> and an Object array would use the corresponding Message implementation.
>>  Each of them could still expose a newMessage taking an Object and a new
>> Message taking just a String but those would be the same (so probably they
>> would extend an abstract class).
>>
>
> What I am not crazy about with this approach is that my call sites now
> have to look like:
>
> Logger log = LogManager.getLogger(Foo.class, new ObjectMessageFactory(),
> new StringMessageFactory(), new ParameterizedMessageFactory())
>
> instead of:
>
> Logger log = LogManager.getLogger(Foo.class, new MyMessageFactory())
>
> The fine grain of the design translates to too much work on the user side.
>
> It is still possible to use the short hand and finer design if we allow
> for a MyMessageFactory as a holder for the three message factories. It
> seems to get a little convoluted though.
>
> Thoughts?
>
>
> You are still not getting it.  We are actually agreeing. Notice I did not
> have an ObjectMessageFactory or StringMessageFactory above.
>
> What the user would do if they want to use java.text.MessageFormat is
>
> Logger log = LogManager.getLogger(Foo.class, new
> MessageFormatMessageFactory());
>
> If they want java.util.String.format then they do
>
> Logger log = LogManager.getLogger(Foo.class, new
> StringFormatMessageFactory());
>
> and if they want the default behavior they would do either:
>
> Logger log = LogManager.getLogger(Foo.class, new
> ParameterizedMessageFactory());
> or
> Logger log = LogManager.getLogger(Foo.class);
>
> So we are providing the 3 MessageFactory implementations that would
> normally be used.  And yes, each of them has the methods that you currently
> have in MessageFactory.java.  I would also create
>
> public abstract class AbstractMessageFactory implements MessageFactory {
>     public Message newMessage(Object object) {
>          return new ObjectMessage(object);
>     }
>
>    public Message new Message(String string) {
>          return new StringMessage(object):
>    }
>
>    public abstract newMessage(String format, Object... params);
>
> }
>
> and then have the 3 message factories extend that.
>
> Ralph
>
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
JUnit in Action, 2nd Ed: <http://goog_1249600977>http://bit.ly/ECvg0
Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Mime
View raw message