Skip to content

Commit 2742a97

Browse files
committed
adding support for composite keywords
1 parent fc45086 commit 2742a97

24 files changed

+530
-348
lines changed

goscp

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
TARGET=cgulcu@hqchnesoa07:/srv/jboss-eap-4.3.0.GA_CP05/jboss-as/server/nesoa-04-esb-01/lib/
2+
3+
scp logback-core/target/logback-core-0.9.27-SNAPSHOT.jar logback-classic/target/logback-classic-0.9.27-SNAPSHOT.jar logback-access/target/logback-access-0.9.27-SNAPSHOT.jar $TARGET

logback-classic/src/main/java/ch/qos/logback/classic/pattern/DateConverter.java

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class DateConverter extends ClassicConverter {
2929

3030
public void start() {
3131

32+
3233
String datePattern = getFirstOption();
3334
if (datePattern == null) {
3435
datePattern = CoreConstants.ISO8601_PATTERN;

logback-classic/src/test/java/ch/qos/logback/classic/turbo/ReconfigureOnChangeTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ void verify(long expectedReconfigurations) {
179179
// we can't have the test succeed under JDK 1.5, punt and require 1.6+
180180
if (Env.isJDK6OrHigher()) {
181181
assertTrue(failMsg,
182-
(effectiveResets * 1.3) >= (expectedReconfigurations * 1.0));
182+
(effectiveResets * 1.4) >= (expectedReconfigurations * 1.0));
183183
}
184184
}
185185

logback-core/src/main/java/ch/qos/logback/core/OutputStreamAppender.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,9 @@ protected void subAppend(E event) {
210210
if (event instanceof DeferredProcessingAware) {
211211
((DeferredProcessingAware) event).prepareForDeferredProcessing();
212212
}
213-
// the synchronized prevents the OutputStream from being closed while we
214-
// are writing
213+
// the synchronization prevents the OutputStream from being closed while we
214+
// are writing. It also prevents multiple thread from entering the same
215+
// converter. Converters assume that they are in a synchronized block.
215216
synchronized (lock) {
216217
writeOut(event);
217218
}

logback-core/src/main/java/ch/qos/logback/core/html/HTMLLayoutBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void start() {
8383
Parser<E> p = new Parser<E>(pattern);
8484
p.setContext(getContext());
8585
Node t = p.parse();
86-
this.head = p.compile(t, getEffectiveConverterMap());
86+
this.head = p.compile(t, getEffectiveConverterMap(), Parser.DEFAULT_COMPOSITE_CONVERTER_MAP);
8787
ConverterUtil.startConverters(this.head);
8888
} catch (ScanException ex) {
8989
addError("Incorrect pattern found", ex);

logback-core/src/main/java/ch/qos/logback/core/pattern/CompositeConverter.java

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Logback: the reliable, generic, fast and flexible logging framework.
3-
* Copyright (C) 1999-2009, QOS.ch. All rights reserved.
3+
* Copyright (C) 1999-2010, QOS.ch. All rights reserved.
44
*
55
* This program and the accompanying materials are dual-licensed under
66
* either the terms of the Eclipse Public License v1.0 as published by
@@ -13,24 +13,22 @@
1313
*/
1414
package ch.qos.logback.core.pattern;
1515

16-
public class CompositeConverter<E> extends FormattingConverter<E> {
16+
abstract public class CompositeConverter<E> extends DynamicConverter<E> {
1717

18-
StringBuilder buf = new StringBuilder();
1918
Converter<E> childConverter;
2019

2120
public String convert(E event) {
22-
if (buf.capacity() > MAX_CAPACITY) {
23-
buf = new StringBuilder(INITIAL_BUF_SIZE);
24-
} else {
25-
buf.setLength(0);
26-
}
21+
StringBuilder buf = new StringBuilder();
2722

2823
for (Converter<E> c = childConverter; c != null; c = c.next) {
2924
c.write(buf, event);
3025
}
31-
return buf.toString();
26+
String intermediary = buf.toString();
27+
return transform(intermediary);
3228
}
3329

30+
abstract String transform(String in);
31+
3432
public void setChildConverter(Converter<E> child) {
3533
childConverter = child;
3634
}

logback-core/src/main/java/ch/qos/logback/core/pattern/ConverterUtil.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,28 @@ public class ConverterUtil {
1717

1818
/**
1919
* Start converters in the chain of converters.
20+
*
2021
* @param head
2122
*/
2223
public static void startConverters(Converter head) {
2324
Converter c = head;
2425
while (c != null) {
25-
if (c instanceof DynamicConverter) {
26-
DynamicConverter dc = (DynamicConverter) c;
27-
dc.start();
28-
} else if(c instanceof CompositeConverter){
26+
// CompositeConverter is a subclass of DynamicConverter
27+
if (c instanceof CompositeConverter) {
2928
CompositeConverter cc = (CompositeConverter) c;
3029
Converter childConverter = cc.childConverter;
3130
startConverters(childConverter);
31+
cc.start();
32+
} else if (c instanceof DynamicConverter) {
33+
DynamicConverter dc = (DynamicConverter) c;
34+
dc.start();
3235
}
3336
c = c.getNext();
3437
}
3538
}
3639

37-
38-
public static<E> Converter<E> findTail(Converter<E> head) {
40+
41+
public static <E> Converter<E> findTail(Converter<E> head) {
3942
Converter<E> p = head;
4043
while (p != null) {
4144
Converter<E> next = p.getNext();

logback-core/src/main/java/ch/qos/logback/core/pattern/DynamicConverter.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ abstract public class DynamicConverter<E> extends FormattingConverter<E>
2121
implements LifeCycle {
2222

2323
// Contains a list of option Strings.
24-
private List optionList;
24+
private List<String> optionList;
2525

2626
/**
2727
* Is this component active?
@@ -46,7 +46,7 @@ public boolean isStarted() {
4646
return started;
4747
}
4848

49-
public void setOptionList(List optionList) {
49+
public void setOptionList(List<String> optionList) {
5050
this.optionList = optionList;
5151
}
5252

@@ -60,11 +60,11 @@ public String getFirstOption() {
6060
if (optionList == null || optionList.size() == 0) {
6161
return null;
6262
} else {
63-
return (String) optionList.get(0);
63+
return optionList.get(0);
6464
}
6565
}
6666

67-
protected List getOptionList() {
67+
protected List<String> getOptionList() {
6868
return optionList;
6969
}
7070
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Logback: the reliable, generic, fast and flexible logging framework.
3+
* Copyright (C) 1999-2010, QOS.ch. All rights reserved.
4+
*
5+
* This program and the accompanying materials are dual-licensed under
6+
* either the terms of the Eclipse Public License v1.0 as published by
7+
* the Eclipse Foundation
8+
*
9+
* or (per the licensee's choosing)
10+
*
11+
* under the terms of the GNU Lesser General Public License version 2.1
12+
* as published by the Free Software Foundation.
13+
*/
14+
package ch.qos.logback.core.pattern;
15+
16+
public class IdentityCompositeConverter<E> extends CompositeConverter<E> {
17+
18+
@Override
19+
String transform(String in) {
20+
return in;
21+
}
22+
}

logback-core/src/main/java/ch/qos/logback/core/pattern/PatternLayoutBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void start() {
8181
p.setContext(getContext());
8282
}
8383
Node t = p.parse();
84-
this.head = p.compile(t, getEffectiveConverterMap());
84+
this.head = p.compile(t, getEffectiveConverterMap(), Parser.DEFAULT_COMPOSITE_CONVERTER_MAP);
8585
if (postCompileProcessor != null) {
8686
postCompileProcessor.process(head);
8787
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Logback: the reliable, generic, fast and flexible logging framework.
3+
* Copyright (C) 1999-2010, QOS.ch. All rights reserved.
4+
*
5+
* This program and the accompanying materials are dual-licensed under
6+
* either the terms of the Eclipse Public License v1.0 as published by
7+
* the Eclipse Foundation
8+
*
9+
* or (per the licensee's choosing)
10+
*
11+
* under the terms of the GNU Lesser General Public License version 2.1
12+
* as published by the Free Software Foundation.
13+
*/
14+
package ch.qos.logback.core.pattern;
15+
16+
import java.util.List;
17+
18+
public class ReplacingCompositeConverter<E> extends CompositeConverter<E> {
19+
20+
String regex;
21+
String by;
22+
23+
public void start() {
24+
final List<String> optionList = getOptionList();
25+
regex = optionList.get(0);
26+
}
27+
@Override
28+
String transform(String in) {
29+
return null; //To change body of implemented methods use File | Settings | File Templates.
30+
}
31+
}

logback-core/src/main/java/ch/qos/logback/core/pattern/parser/Compiler.java

+69-40
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515

1616
import java.util.Map;
1717

18-
import ch.qos.logback.core.pattern.CompositeConverter;
19-
import ch.qos.logback.core.pattern.Converter;
20-
import ch.qos.logback.core.pattern.DynamicConverter;
21-
import ch.qos.logback.core.pattern.LiteralConverter;
18+
import ch.qos.logback.core.pattern.*;
2219
import ch.qos.logback.core.spi.ContextAwareBase;
2320
import ch.qos.logback.core.status.ErrorStatus;
2421
import ch.qos.logback.core.util.OptionHelper;
@@ -29,46 +26,49 @@ class Compiler<E> extends ContextAwareBase {
2926
Converter<E> tail;
3027
final Node top;
3128
final Map converterMap;
29+
final Map compositeConverterMap;
3230

33-
Compiler(final Node top, final Map converterMap) {
31+
Compiler(final Node top, final Map converterMap, Map compositeConverterMap) {
3432
this.top = top;
3533
this.converterMap = converterMap;
34+
this.compositeConverterMap = compositeConverterMap;
3635
}
3736

3837
Converter<E> compile() {
3938
head = tail = null;
4039
for (Node n = top; n != null; n = n.next) {
4140
switch (n.type) {
42-
case Node.LITERAL:
43-
addToList(new LiteralConverter<E>((String) n.getValue()));
44-
break;
45-
case Node.COMPOSITE:
46-
CompositeNode cn = (CompositeNode) n;
47-
CompositeConverter<E> compositeConverter = new CompositeConverter<E>();
48-
compositeConverter.setFormattingInfo(cn.getFormatInfo());
49-
Compiler<E> childCompiler = new Compiler<E>(cn.getChildNode(),
50-
converterMap);
51-
childCompiler.setContext(context);
52-
Converter<E> childConverter = childCompiler.compile();
53-
compositeConverter.setChildConverter(childConverter);
54-
addToList(compositeConverter);
55-
break;
56-
case Node.KEYWORD:
57-
KeywordNode kn = (KeywordNode) n;
58-
DynamicConverter<E> dynaConverter = createConverter(kn);
59-
if (dynaConverter != null) {
60-
dynaConverter.setFormattingInfo(kn.getFormatInfo());
61-
dynaConverter.setOptionList(kn.getOptions());
62-
addToList(dynaConverter);
63-
} else {
64-
// if the appropriate dynaconverter cannot be found, then replace
65-
// it with a dummy LiteralConverter indicating an error.
66-
Converter<E> errConveter = new LiteralConverter<E>("%PARSER_ERROR["
67-
+ kn.getValue()+"]");
68-
addStatus(new ErrorStatus("[" + kn.getValue()
69-
+ "] is not a valid conversion word", this));
70-
addToList(errConveter);
71-
}
41+
case Node.LITERAL:
42+
addToList(new LiteralConverter<E>((String) n.getValue()));
43+
break;
44+
case Node.COMPOSITE_KEYWORD:
45+
CompositeNode cn = (CompositeNode) n;
46+
CompositeConverter<E> compositeConverter = createCompiteConverter(cn);
47+
compositeConverter.setFormattingInfo(cn.getFormatInfo());
48+
compositeConverter.setOptionList(cn.getOptions());
49+
Compiler<E> childCompiler = new Compiler<E>(cn.getChildNode(),
50+
converterMap, compositeConverterMap);
51+
childCompiler.setContext(context);
52+
Converter<E> childConverter = childCompiler.compile();
53+
compositeConverter.setChildConverter(childConverter);
54+
addToList(compositeConverter);
55+
break;
56+
case Node.SIMPLE_KEYWORD:
57+
SimpleKeywordNode kn = (SimpleKeywordNode) n;
58+
DynamicConverter<E> dynaConverter = createConverter(kn);
59+
if (dynaConverter != null) {
60+
dynaConverter.setFormattingInfo(kn.getFormatInfo());
61+
dynaConverter.setOptionList(kn.getOptions());
62+
addToList(dynaConverter);
63+
} else {
64+
// if the appropriate dynaconverter cannot be found, then replace
65+
// it with a dummy LiteralConverter indicating an error.
66+
Converter<E> errConveter = new LiteralConverter<E>("%PARSER_ERROR["
67+
+ kn.getValue() + "]");
68+
addStatus(new ErrorStatus("[" + kn.getValue()
69+
+ "] is not a valid conversion word", this));
70+
addToList(errConveter);
71+
}
7272

7373
}
7474
}
@@ -87,31 +87,60 @@ private void addToList(Converter<E> c) {
8787
/**
8888
* Attempt to create a converter using the information found in
8989
* 'converterMap'.
90-
*
90+
*
9191
* @param kn
9292
* @return
9393
*/
9494
@SuppressWarnings("unchecked")
95-
DynamicConverter<E> createConverter(KeywordNode kn) {
95+
DynamicConverter<E> createConverter(SimpleKeywordNode kn) {
9696
String keyword = (String) kn.getValue();
9797
String converterClassStr = (String) converterMap.get(keyword);
9898

9999
if (converterClassStr != null) {
100100
try {
101101
return (DynamicConverter) OptionHelper.instantiateByClassName(
102-
converterClassStr, DynamicConverter.class, context);
102+
converterClassStr, DynamicConverter.class, context);
103103
} catch (Exception e) {
104104
addError("Failed to instantiate converter class [" + converterClassStr
105-
+ "]", e);
105+
+ "]", e);
106106
return null;
107107
}
108108
} else {
109109
addError("There is no conversion class registered for conversion word ["
110-
+ keyword + "]");
110+
+ keyword + "]");
111111
return null;
112112
}
113113
}
114114

115+
/**
116+
* Attempt to create a converter using the information found in
117+
* 'compositeConverterMap'.
118+
*
119+
* @param cn
120+
* @return
121+
*/
122+
@SuppressWarnings("unchecked")
123+
CompositeConverter<E> createCompiteConverter(CompositeNode cn) {
124+
String keyword = (String) cn.getValue();
125+
String converterClassStr = (String) compositeConverterMap.get(keyword);
126+
127+
if (converterClassStr != null) {
128+
try {
129+
return (CompositeConverter) OptionHelper.instantiateByClassName(
130+
converterClassStr, CompositeConverter.class, context);
131+
} catch (Exception e) {
132+
addError("Failed to instantiate converter class [" + converterClassStr
133+
+ "]", e);
134+
return null;
135+
}
136+
} else {
137+
addError("There is no conversion class registered for composite conversion word ["
138+
+ keyword + "]");
139+
return null;
140+
}
141+
}
142+
143+
115144
// public void setStatusManager(StatusManager statusManager) {
116145
// this.statusManager = statusManager;
117146
// }

logback-core/src/main/java/ch/qos/logback/core/pattern/parser/CompositeNode.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
*/
1414
package ch.qos.logback.core.pattern.parser;
1515

16-
public class CompositeNode extends FormattingNode {
16+
public class CompositeNode extends SimpleKeywordNode {
1717
Node childNode;
1818

19-
CompositeNode() {
20-
super(Node.COMPOSITE);
19+
CompositeNode(String keyword) {
20+
super(Node.COMPOSITE_KEYWORD, keyword);
21+
2122
}
2223

2324
public Node getChildNode() {

logback-core/src/main/java/ch/qos/logback/core/pattern/parser/Node.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
public class Node {
1717
static final int LITERAL = 0;
18-
static final int KEYWORD = 1;
19-
static final int COMPOSITE = 2;
18+
static final int SIMPLE_KEYWORD = 1;
19+
static final int COMPOSITE_KEYWORD = 2;
2020

2121
final int type;
2222
final Object value;

0 commit comments

Comments
 (0)