Java 类ch.qos.logback.core.pattern.Converter 实例源码
项目:bartleby
文件:FileNamePattern.java
public DateTokenConverter getPrimaryDateTokenConverter() {
Converter p = headTokenConverter;
while (p != null) {
if (p instanceof DateTokenConverter) {
DateTokenConverter dtc = (DateTokenConverter) p;
// only primary converters should be returned as
if(dtc.isPrimary())
return dtc;
}
p = p.getNext();
}
return null;
}
项目:bartleby
文件:FileNamePattern.java
public String convertMultipleArguments(Object... objectList) {
StringBuilder buf = new StringBuilder();
Converter<Object> c = headTokenConverter;
while (c != null) {
if (c instanceof MonoTypedConverter) {
MonoTypedConverter monoTyped = (MonoTypedConverter) c;
for (Object o : objectList) {
if (monoTyped.isApplicable(o)) {
buf.append(c.convert(o));
}
}
} else {
buf.append(c.convert(objectList));
}
c = c.getNext();
}
return buf.toString();
}
项目:bartleby
文件:FileNamePattern.java
/**
* Given date, convert this instance to a regular expression.
*
* Used to compute sub-regex when the pattern has both %d and %i, and the
* date is known.
*/
public String toRegexForFixedDate(Date date) {
StringBuilder buf = new StringBuilder();
Converter<Object> p = headTokenConverter;
while (p != null) {
if (p instanceof LiteralConverter) {
buf.append(p.convert(null));
} else if (p instanceof IntegerTokenConverter) {
buf.append("(\\d{1,3})");
} else if (p instanceof DateTokenConverter) {
buf.append(p.convert(date));
}
p = p.getNext();
}
return buf.toString();
}
项目:bartleby
文件:FileNamePattern.java
/**
* Given date, convert this instance to a regular expression
*/
public String toRegex() {
StringBuilder buf = new StringBuilder();
Converter<Object> p = headTokenConverter;
while (p != null) {
if (p instanceof LiteralConverter) {
buf.append(p.convert(null));
} else if (p instanceof IntegerTokenConverter) {
buf.append("\\d{1,2}");
} else if (p instanceof DateTokenConverter) {
DateTokenConverter<Object> dtc = (DateTokenConverter<Object>) p;
buf.append(dtc.toRegex());
}
p = p.getNext();
}
return buf.toString();
}
项目:bartleby
文件:HTMLLayoutBase.java
private void buildHeaderRowForTable(StringBuilder sbuf) {
Converter c = head;
String name;
sbuf.append("<tr class=\"header\">");
sbuf.append(LINE_SEPARATOR);
while (c != null) {
name = computeConverterName(c);
if (name == null) {
c = c.getNext();
continue;
}
sbuf.append("<td class=\"");
sbuf.append(computeConverterName(c));
sbuf.append("\">");
sbuf.append(computeConverterName(c));
sbuf.append("</td>");
sbuf.append(LINE_SEPARATOR);
c = c.getNext();
}
sbuf.append("</tr>");
sbuf.append(LINE_SEPARATOR);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot
文件:LogbackConfigurator.java
@SuppressWarnings({ "rawtypes", "unchecked" })
public void conversionRule(String conversionWord,
Class<? extends Converter> converterClass) {
Assert.hasLength(conversionWord, "Conversion word must not be empty");
Assert.notNull(converterClass, "Converter class must not be null");
Map<String, String> registry = (Map<String, String>) this.context
.getObject(CoreConstants.PATTERN_RULE_REGISTRY);
if (registry == null) {
registry = new HashMap<String, String>();
this.context.putObject(CoreConstants.PATTERN_RULE_REGISTRY, registry);
}
registry.put(conversionWord, converterClass.getName());
}
项目:spring-boot-concourse
文件:LogbackConfigurator.java
@SuppressWarnings({ "rawtypes", "unchecked" })
public void conversionRule(String conversionWord,
Class<? extends Converter> converterClass) {
Assert.hasLength(conversionWord, "Conversion word must not be empty");
Assert.notNull(converterClass, "Converter class must not be null");
Map<String, String> registry = (Map<String, String>) this.context
.getObject(CoreConstants.PATTERN_RULE_REGISTRY);
if (registry == null) {
registry = new HashMap<String, String>();
this.context.putObject(CoreConstants.PATTERN_RULE_REGISTRY, registry);
}
registry.put(conversionWord, converterClass.getName());
}
项目:bartleby
文件:Compiler.java
private void addToList(Converter<E> c) {
if (head == null) {
head = tail = c;
} else {
tail.setNext(c);
tail = c;
}
}
项目:bartleby
文件:FileNamePattern.java
public IntegerTokenConverter getIntegerTokenConverter() {
Converter p = headTokenConverter;
while (p != null) {
if (p instanceof IntegerTokenConverter) {
return (IntegerTokenConverter) p;
}
p = p.getNext();
}
return null;
}
项目:bartleby
文件:FileNamePattern.java
public String convert(Object o) {
StringBuilder buf = new StringBuilder();
Converter<Object> p = headTokenConverter;
while (p != null) {
buf.append(p.convert(o));
p = p.getNext();
}
return buf.toString();
}
项目:bartleby
文件:DefaultArchiveRemover.java
boolean computeParentCleaningFlag(FileNamePattern fileNamePattern) {
DateTokenConverter dtc = fileNamePattern.getPrimaryDateTokenConverter();
// if the date pattern has a /, then we need parent cleaning
if (dtc.getDatePattern().indexOf('/') != -1) {
return true;
}
// if the literal string subsequent to the dtc contains a /, we also
// need parent cleaning
Converter<Object> p = fileNamePattern.headTokenConverter;
// find the date converter
while (p != null) {
if (p instanceof DateTokenConverter) {
break;
}
p = p.getNext();
}
while (p != null) {
if (p instanceof LiteralConverter) {
String s = p.convert(null);
if (s.indexOf('/') != -1) {
return true;
}
}
p = p.getNext();
}
// no /, so we don't need parent cleaning
return false;
}
项目:bartleby
文件:HTMLLayoutBase.java
protected String computeConverterName(Converter c) {
String className = c.getClass().getSimpleName();
int index = className.indexOf("Converter");
if (index == -1) {
return className;
} else {
return className.substring(0, index);
}
}
项目:bartleby
文件:CompilerTest.java
String write(final Converter<Object> head, Object event) {
StringBuilder buf = new StringBuilder();
Converter<Object> c = head;
while (c != null) {
c.write(buf, event);
c = c.getNext();
}
return buf.toString();
}
项目:bartleby
文件:CompilerTest.java
@Test
public void testLiteral() throws Exception {
Parser<Object> p = new Parser<Object>("hello");
Node t = p.parse();
Converter<Object> head = p.compile(t, converterMap);
String result = write(head, new Object());
assertEquals("hello", result);
}
项目:bartleby
文件:CompilerTest.java
@Test
public void testWithNopEscape() throws Exception {
{
Parser<Object> p = new Parser<Object>("xyz %hello\\_world");
p.setContext(context);
Node t = p.parse();
Converter<Object> head = p.compile(t, converterMap);
String result = write(head, new Object());
assertEquals("xyz Helloworld", result);
}
}
项目:bartleby
文件:EnsureExceptionHandling.java
/**
* This method computes whether a chain of converters handles exceptions or
* not.
*
* @param head
* The first element of the chain
* @return true if can handle throwables contained in logging events
*/
public boolean chainHandlesThrowable(Converter head) {
Converter c = head;
while (c != null) {
if (c instanceof ThrowableHandlingConverter) {
return true;
}
c = c.getNext();
}
return false;
}
项目:bartleby
文件:HTMLLayout.java
public String doLayout(ILoggingEvent event) {
StringBuilder buf = new StringBuilder();
startNewTableIfLimitReached(buf);
boolean odd = true;
if (((counter++) & 1) == 0) {
odd = false;
}
String level = event.getLevel().toString().toLowerCase();
buf.append(LINE_SEPARATOR);
buf.append("<tr class=\"");
buf.append(level);
if (odd) {
buf.append(" odd\">");
} else {
buf.append(" even\">");
}
buf.append(LINE_SEPARATOR);
Converter<ILoggingEvent> c = head;
while (c != null) {
appendEventToBuffer(buf, c, event);
c = c.getNext();
}
buf.append("</tr>");
buf.append(LINE_SEPARATOR);
if (event.getThrowableProxy() != null) {
throwableRenderer.render(buf, event);
}
return buf.toString();
}
项目:bartleby
文件:HTMLLayout.java
private void appendEventToBuffer(StringBuilder buf,
Converter<ILoggingEvent> c, ILoggingEvent event) {
buf.append("<td class=\"");
buf.append(computeConverterName(c));
buf.append("\">");
buf.append(Transform.escapeTags(c.convert(event)));
buf.append("</td>");
buf.append(LINE_SEPARATOR);
}
项目:bartleby
文件:HTMLLayout.java
@Override
protected String computeConverterName(Converter c) {
if(c instanceof MDCConverter) {
MDCConverter mc = (MDCConverter) c;
String key = mc.getFirstOption();
if(key != null) {
return key;
} else {
return "MDC";
}
} else {
return super.computeConverterName(c);
}
}
项目:bartleby
文件:EnsureLineSeparation.java
/**
* Add a line separator converter so that access event appears on a separate
* line.
*/
@Override
public void process(Converter<IAccessEvent> head) {
if(head == null)
throw new IllegalArgumentException("Empty converter chain");
// if head != null, then tail != null as well
Converter<IAccessEvent> tail = ConverterUtil.findTail(head);
Converter<IAccessEvent> newLineConverter = new LineSeparatorConverter();
if (!(tail instanceof LineSeparatorConverter)) {
tail.setNext(newLineConverter);
}
}
项目:bartleby
文件:HTMLLayout.java
@Override
public String doLayout(IAccessEvent event) {
StringBuilder buf = new StringBuilder();
startNewTableIfLimitReached(buf);
boolean odd = true;
if (((counter++) & 1) == 0) {
odd = false;
}
buf.append(LINE_SEPARATOR);
buf.append("<tr class=\"");
if (odd) {
buf.append(" odd\">");
} else {
buf.append(" even\">");
}
buf.append(LINE_SEPARATOR);
Converter<IAccessEvent> c = head;
while (c != null) {
appendEventToBuffer(buf, c, event);
c = c.getNext();
}
buf.append("</tr>");
buf.append(LINE_SEPARATOR);
return buf.toString();
}
项目:bartleby
文件:HTMLLayout.java
private void appendEventToBuffer(StringBuilder buf, Converter<IAccessEvent> c,
IAccessEvent event) {
buf.append("<td class=\"");
buf.append(computeConverterName(c));
buf.append("\">");
c.write(buf, event);
buf.append("</td>");
buf.append(LINE_SEPARATOR);
}
项目:contestparser
文件:LogbackConfigurator.java
@SuppressWarnings({ "rawtypes", "unchecked" })
public void conversionRule(String conversionWord,
Class<? extends Converter> converterClass) {
Assert.hasLength(conversionWord, "Conversion word must not be empty");
Assert.notNull(converterClass, "Converter class must not be null");
Map<String, String> registry = (Map<String, String>) this.context
.getObject(CoreConstants.PATTERN_RULE_REGISTRY);
if (registry == null) {
registry = new HashMap<String, String>();
this.context.putObject(CoreConstants.PATTERN_RULE_REGISTRY, registry);
}
registry.put(conversionWord, converterClass.getName());
}
项目:sdcct
文件:LoggingInitializerRunListener.java
@SuppressWarnings({ CompilerWarnings.UNCHECKED })
private void buildConversionRule(String word, Class<? extends Converter<ILoggingEvent>> clazz) {
Map<String, String> reg = ((Map<String, String>) this.loggerContext.getObject(CoreConstants.PATTERN_RULE_REGISTRY));
if (reg == null) {
this.loggerContext.putObject(CoreConstants.PATTERN_RULE_REGISTRY, (reg = new HashMap<>()));
}
reg.put(word, clazz.getName());
}
项目:bartleby
文件:Compiler.java
Converter<E> compile() {
head = tail = null;
for (Node n = top; n != null; n = n.next) {
switch (n.type) {
case Node.LITERAL:
addToList(new LiteralConverter<E>((String) n.getValue()));
break;
case Node.COMPOSITE_KEYWORD:
CompositeNode cn = (CompositeNode) n;
CompositeConverter<E> compositeConverter = createCompositeConverter(cn);
if(compositeConverter == null) {
addError("Failed to create converter for [%"+cn.getValue()+"] keyword");
addToList(new LiteralConverter<E>("%PARSER_ERROR["+cn.getValue()+"]"));
break;
}
compositeConverter.setFormattingInfo(cn.getFormatInfo());
compositeConverter.setOptionList(cn.getOptions());
Compiler<E> childCompiler = new Compiler<E>(cn.getChildNode(),
converterMap);
childCompiler.setContext(context);
Converter<E> childConverter = childCompiler.compile();
compositeConverter.setChildConverter(childConverter);
addToList(compositeConverter);
break;
case Node.SIMPLE_KEYWORD:
SimpleKeywordNode kn = (SimpleKeywordNode) n;
DynamicConverter<E> dynaConverter = createConverter(kn);
if (dynaConverter != null) {
dynaConverter.setFormattingInfo(kn.getFormatInfo());
dynaConverter.setOptionList(kn.getOptions());
addToList(dynaConverter);
} else {
// if the appropriate dynaconverter cannot be found, then replace
// it with a dummy LiteralConverter indicating an error.
Converter<E> errConveter = new LiteralConverter<E>("%PARSER_ERROR["
+ kn.getValue() + "]");
addStatus(new ErrorStatus("[" + kn.getValue()
+ "] is not a valid conversion word", this));
addToList(errConveter);
}
}
}
return head;
}
项目:bartleby
文件:Parser.java
/**
* When the parsing step is done, the Node list can be transformed into a
* converter chain.
*
* @param top
* @param converterMap
* @return
* @throws ScanException
*/
public Converter<E> compile(final Node top, Map converterMap) {
Compiler<E> compiler = new Compiler<E>(top, converterMap);
compiler.setContext(context);
//compiler.setStatusManager(statusManager);
return compiler.compile();
}
项目:bartleby
文件:EnsureExceptionHandling.java
/**
* This implementation checks if any of the converters in the chain handles
* exceptions. If not, then this method adds a
* {@link ExtendedThrowableProxyConverter} instance to the end of the chain.
* <p>
* This allows appenders using this layout to output exception information
* event if the user forgets to add %ex to the pattern. Note that the
* appenders defined in the Core package are not aware of exceptions nor
* LoggingEvents.
* <p>
* If for some reason the user wishes to NOT print exceptions, then she can
* add %nopex to the pattern.
*
*
*/
public void process(Converter<ILoggingEvent> head) {
if(head == null) {
// this should never happen
throw new IllegalArgumentException("cannot process empty chain");
}
if (!chainHandlesThrowable(head)) {
Converter<ILoggingEvent> tail = ConverterUtil.findTail(head);
Converter<ILoggingEvent> exConverter = new ExtendedThrowableProxyConverter();
tail.setNext(exConverter);
}
}