logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ralph Goers (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LOG4J2-133) Allow custom message creation via a message factory
Date Thu, 06 Dec 2012 23:47:20 GMT

    [ https://issues.apache.org/jira/browse/LOG4J2-133?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13526014#comment-13526014

Ralph Goers commented on LOG4J2-133:

I recommend creating an AbstractMessageFactory as

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 creating StringFormatMessageFactory and ObjectMessageFactory. Then change DefaultMessageFactory
to extend the abstract class. You might want to rename DefaultMessageFactory to ParameterizedMessageFactory
to be consistent with the other two factory classes.
> Allow custom message creation via a message factory
> ---------------------------------------------------
>                 Key: LOG4J2-133
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-133
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: API
>    Affects Versions: 2.0-beta3
>         Environment: Apache Maven 3.0.4 (r1232337; 2012-01-17 03:44:56-0500)
> Maven home: C:\Java\apache-maven-3.0.4\bin\..
> Java version: 1.6.0_35, vendor: Sun Microsystems Inc.
> Java home: C:\Program Files\Java\jdk1.6.0_35\jre
> Default locale: en_US, platform encoding: Cp1252
> OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
>            Reporter: Gary Gregory
>         Attachments: log4j2-133.diff
> My goal here is to be able to say:
> Logger log = LogManager.getLogger(Foo.class, new MyMessageFactory())
> Where MyMessageFactory extends a MessageFactory:
> and overrides:
>     public Message newMessage(String message, Object... params) {
>         return new ParameterizedMessage(message, params);
>     }
> as:
>     public Message newMessage(String message, Object... params) {
>         return new StringFormattedMessage(message, params);
>     }
> which would let me use native Java formatting instead of {} formatting /easily/
> I've attach the idea as the beginning of patch, which is missing the LogManager bits.
> Maybe we need a sub-interface of Message for param message, which would make me want
to rename the class ParameterizedMessage to SimpleParameterizedMessage.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org

View raw message