17
17
package org .apache .logging .log4j .message ;
18
18
19
19
import java .io .Serializable ;
20
- import org .apache .logging .log4j .spi .AbstractLogger ;
21
- import org .apache .logging .log4j .util .LoaderUtil ;
20
+ import java .util .Objects ;
22
21
import org .apache .logging .log4j .util .StringBuilderFormattable ;
23
22
import org .apache .logging .log4j .util .StringBuilders ;
24
23
import org .apache .logging .log4j .util .Strings ;
@@ -34,6 +33,8 @@ public class DefaultFlowMessageFactory implements FlowMessageFactory, Serializab
34
33
private static final String ENTRY_DEFAULT_PREFIX = "Enter" ;
35
34
private static final long serialVersionUID = 8578655591131397576L ;
36
35
36
+ public static final FlowMessageFactory INSTANCE = new DefaultFlowMessageFactory ();
37
+
37
38
private final String entryText ;
38
39
private final String exitText ;
39
40
private final MessageFactory messageFactory ;
@@ -51,17 +52,22 @@ public DefaultFlowMessageFactory() {
51
52
* @param exitText the text to use for trace exit, like {@code "Exit"}.
52
53
*/
53
54
public DefaultFlowMessageFactory (final String entryText , final String exitText ) {
55
+ this (entryText , exitText , createDefaultMessageFactory ());
56
+ }
57
+
58
+ public DefaultFlowMessageFactory (final MessageFactory messageFactory ) {
59
+ this (ENTRY_DEFAULT_PREFIX , EXIT_DEFAULT_PREFIX , Objects .requireNonNull (messageFactory ));
60
+ }
61
+
62
+ private DefaultFlowMessageFactory (
63
+ final String entryText , final String exitText , final MessageFactory messageFactory ) {
54
64
this .entryText = entryText ;
55
65
this .exitText = exitText ;
56
- this .messageFactory = createDefaultMessageFactory () ;
66
+ this .messageFactory = messageFactory ;
57
67
}
58
68
59
69
private static MessageFactory createDefaultMessageFactory () {
60
- try {
61
- return LoaderUtil .newInstanceOf (AbstractLogger .DEFAULT_MESSAGE_FACTORY_CLASS );
62
- } catch (final ReflectiveOperationException e ) {
63
- throw new IllegalStateException (e );
64
- }
70
+ return ParameterizedMessageFactory .INSTANCE ;
65
71
}
66
72
67
73
private static class AbstractFlowMessage implements FlowMessage , StringBuilderFormattable {
0 commit comments