本文整理汇总了Java中org.apache.logging.log4j.core.pattern.PatternFormatter类的典型用法代码示例。如果您正苦于以下问题:Java PatternFormatter类的具体用法?Java PatternFormatter怎么用?Java PatternFormatter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PatternFormatter类属于org.apache.logging.log4j.core.pattern包,在下文中一共展示了PatternFormatter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: newInstance
import org.apache.logging.log4j.core.pattern.PatternFormatter; //导入依赖的package包/类
/**
* Creates a new instance of the class. Required by Log4J2.
*
* @param config the configuration
* @param options the options
* @return a new instance, or {@code null} if the options are invalid
*/
public static ColorConverter newInstance(Configuration config, String[] options) {
if (options.length < 1) {
LOGGER.error("Incorrect number of options on style. "
+ "Expected at least 1, received {}", options.length);
return null;
}
if (options[0] == null) {
LOGGER.error("No pattern supplied on style");
return null;
}
PatternParser parser = PatternLayout.createPatternParser(config);
List<PatternFormatter> formatters = parser.parse(options[0]);
AnsiElement element = (options.length == 1 ? null : ELEMENTS.get(options[1]));
return new ColorConverter(formatters, element);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:23,代码来源:ColorConverter.java
示例2: format
import org.apache.logging.log4j.core.pattern.PatternFormatter; //导入依赖的package包/类
@Override
public void format(LogEvent event, StringBuilder toAppendTo) {
StringBuilder buf = new StringBuilder();
for (PatternFormatter formatter : this.formatters) {
formatter.format(event, buf);
}
if (buf.length() > 0) {
AnsiElement element = this.styling;
if (element == null) {
// Assume highlighting
element = LEVELS.get(event.getLevel().intLevel());
element = (element == null ? AnsiColor.GREEN : element);
}
appendAnsiString(toAppendTo, buf.toString(), element);
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:ColorConverter.java
示例3: createFieldFormatters
import org.apache.logging.log4j.core.pattern.PatternFormatter; //导入依赖的package包/类
private Map<String, FieldFormatter> createFieldFormatters(final LoggerFields[] loggerFields,
final Configuration config) {
final Map<String, FieldFormatter> sdIdMap = new HashMap<String, FieldFormatter>();
if (loggerFields != null) {
for (final LoggerFields lField : loggerFields) {
final StructuredDataId key = lField.getSdId() == null ? mdcSDID : lField.getSdId();
final Map<String, List<PatternFormatter>> sdParams = new HashMap<String, List<PatternFormatter>>();
final Map<String, String> fields = lField.getMap();
if (!fields.isEmpty()) {
final PatternParser fieldParser = createPatternParser(config, null);
for (final Map.Entry<String, String> entry : fields.entrySet()) {
final List<PatternFormatter> formatters = fieldParser.parse(entry.getValue(), false);
sdParams.put(entry.getKey(), formatters);
}
final FieldFormatter fieldFormatter = new FieldFormatter(sdParams,
lField.getDiscardIfAllFieldsAreEmpty());
sdIdMap.put(key.toString(), fieldFormatter);
}
}
}
return sdIdMap.size() > 0 ? sdIdMap : null;
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:25,代码来源:RFC5424Layout.java
示例4: appendMessage
import org.apache.logging.log4j.core.pattern.PatternFormatter; //导入依赖的package包/类
private void appendMessage(final StringBuilder buffer, final LogEvent event) {
final Message message = event.getMessage();
final String text = message.getFormat();
if (text != null && text.length() > 0) {
buffer.append(" ").append(escapeNewlines(text, escapeNewLine));
}
if (exceptionFormatters != null && event.getThrown() != null) {
final StringBuilder exception = new StringBuilder(LF);
for (final PatternFormatter formatter : exceptionFormatters) {
formatter.format(event, exception);
}
buffer.append(escapeNewlines(exception.toString(), escapeNewLine));
}
if (includeNewLine) {
buffer.append(LF);
}
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:20,代码来源:RFC5424Layout.java
示例5: build
import org.apache.logging.log4j.core.pattern.PatternFormatter; //导入依赖的package包/类
@Override
public Serializer build() {
if (Strings.isEmpty(pattern) && Strings.isEmpty(defaultPattern)) {
return null;
}
if (patternSelector == null) {
try {
final PatternParser parser = createPatternParser(configuration);
final List<PatternFormatter> list = parser.parse(pattern == null ? defaultPattern : pattern,
alwaysWriteExceptions, disableAnsi, noConsoleNoAnsi);
final PatternFormatter[] formatters = list.toArray(new PatternFormatter[0]);
return new PatternSerializer(formatters, replace);
} catch (final RuntimeException ex) {
throw new IllegalArgumentException("Cannot parse pattern '" + pattern + "'", ex);
}
}
return new PatternSelectorSerializer(patternSelector, replace);
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:19,代码来源:PatternLayout.java
示例6: createFieldFormatters
import org.apache.logging.log4j.core.pattern.PatternFormatter; //导入依赖的package包/类
private Map<String, FieldFormatter> createFieldFormatters(final LoggerFields[] loggerFields,
final Configuration config) {
final Map<String, FieldFormatter> sdIdMap = new HashMap<>(loggerFields == null ? 0 : loggerFields.length);
if (loggerFields != null) {
for (final LoggerFields loggerField : loggerFields) {
final StructuredDataId key = loggerField.getSdId() == null ? mdcSdId : loggerField.getSdId();
final Map<String, List<PatternFormatter>> sdParams = new HashMap<>();
final Map<String, String> fields = loggerField.getMap();
if (!fields.isEmpty()) {
final PatternParser fieldParser = createPatternParser(config, null);
for (final Map.Entry<String, String> entry : fields.entrySet()) {
final List<PatternFormatter> formatters = fieldParser.parse(entry.getValue());
sdParams.put(entry.getKey(), formatters);
}
final FieldFormatter fieldFormatter = new FieldFormatter(sdParams,
loggerField.getDiscardIfAllFieldsAreEmpty());
sdIdMap.put(key.toString(), fieldFormatter);
}
}
}
return sdIdMap.size() > 0 ? sdIdMap : null;
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:24,代码来源:Rfc5424Layout.java
示例7: appendMessage
import org.apache.logging.log4j.core.pattern.PatternFormatter; //导入依赖的package包/类
private void appendMessage(final StringBuilder buffer, final LogEvent event) {
final Message message = event.getMessage();
// This layout formats StructuredDataMessages instead of delegating to the Message itself.
final String text = (message instanceof StructuredDataMessage || message instanceof MessageCollectionMessage)
? message.getFormat() : message.getFormattedMessage();
if (text != null && text.length() > 0) {
buffer.append(' ').append(escapeNewlines(text, escapeNewLine));
}
if (exceptionFormatters != null && event.getThrown() != null) {
final StringBuilder exception = new StringBuilder(LF);
for (final PatternFormatter formatter : exceptionFormatters) {
formatter.format(event, exception);
}
buffer.append(escapeNewlines(exception.toString(), escapeNewLine));
}
if (includeNewLine) {
buffer.append(LF);
}
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:22,代码来源:Rfc5424Layout.java
示例8: toSerializable
import org.apache.logging.log4j.core.pattern.PatternFormatter; //导入依赖的package包/类
@Override
public String toSerializable(LogEvent event) {
PatternSelector selector = getSelector(event);
final StringBuilder buf = getStringBuilder();
PatternFormatter[] formatters = selector.getFormatters(event);
final int len = formatters.length;
for (int i = 0; i < len; i++) {
formatters[i].format(event, buf);
}
String str = buf.toString();
return str;
}
开发者ID:SAP,项目名称:cf-java-logging-support,代码行数:13,代码来源:JsonPatternLayout.java
示例9: handlesThrowable
import org.apache.logging.log4j.core.pattern.PatternFormatter; //导入依赖的package包/类
@Override
public boolean handlesThrowable() {
for (PatternFormatter formatter : this.formatters) {
if (formatter.handlesThrowable()) {
return true;
}
}
return super.handlesThrowable();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:ColorConverter.java
示例10: newInstance
import org.apache.logging.log4j.core.pattern.PatternFormatter; //导入依赖的package包/类
/**
* Obtains an instance of pattern converter.
*
* @param config The Configuration.
* @param options options, may be null.
* @return instance of pattern converter.
*/
public static SimpleJSONPatternConverter newInstance(final Configuration config, final String[] options) {
if (options.length != 1) {
LOGGER.error("Incorrect number of options on json. Expected 1, received " + options.length);
return null;
}
if (options[0] == null) {
LOGGER.error("No pattern supplied on json");
return null;
}
final PatternParser parser = PatternLayout.createPatternParser(config);
final List<PatternFormatter> formatters = parser.parse(options[0]);
return new SimpleJSONPatternConverter(formatters);
}
开发者ID:ggrandes,项目名称:log4j2-simplejson,代码行数:21,代码来源:SimpleJSONPatternConverter.java
示例11: format
import org.apache.logging.log4j.core.pattern.PatternFormatter; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void format(final LogEvent event, final StringBuilder toAppendTo) {
final StringBuilder buf = new StringBuilder();
for (final PatternFormatter formatter : formatters) {
formatter.format(event, buf);
}
EncoderJSON.escapeJSON(buf, toAppendTo);
}
开发者ID:ggrandes,项目名称:log4j2-simplejson,代码行数:12,代码来源:SimpleJSONPatternConverter.java
示例12: format
import org.apache.logging.log4j.core.pattern.PatternFormatter; //导入依赖的package包/类
public StructuredDataElement format(final LogEvent event) {
final Map<String, String> map = new HashMap<String, String>();
for (final Map.Entry<String, List<PatternFormatter>> entry : delegateMap.entrySet()) {
final StringBuilder buffer = new StringBuilder();
for (final PatternFormatter formatter : entry.getValue()) {
formatter.format(event, buffer);
}
map.put(entry.getKey(), buffer.toString());
}
return new StructuredDataElement(map, discardIfEmpty);
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:13,代码来源:RFC5424Layout.java
示例13: toSerializable
import org.apache.logging.log4j.core.pattern.PatternFormatter; //导入依赖的package包/类
/**
* Formats a logging event to a writer.
*
*
* @param event logging event to be formatted.
* @return The event formatted as a String.
*/
@Override
public String toSerializable(final LogEvent event) {
final StringBuilder buf = new StringBuilder();
for (final PatternFormatter formatter : formatters) {
formatter.format(event, buf);
}
String str = buf.toString();
if (replace != null) {
str = replace.format(str);
}
return str;
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:20,代码来源:PatternLayout.java
示例14: createFormatters
import org.apache.logging.log4j.core.pattern.PatternFormatter; //导入依赖的package包/类
/**
*/
private static PatternFormatter[] createFormatters() {
final Configuration config = new DefaultConfiguration();
final PatternParser parser = new PatternParser(config, "Converter", LogEventPatternConverter.class);
final List<PatternFormatter> result = parser.parse(LOG4JPATTERN, false, true);
return result.toArray(new PatternFormatter[result.size()]);
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:9,代码来源:ThreadLocalVsPoolBenchmark.java
示例15: getFormatters
import org.apache.logging.log4j.core.pattern.PatternFormatter; //导入依赖的package包/类
@Override
public PatternFormatter[] getFormatters(final LogEvent event) {
final Marker marker = event.getMarker();
if (marker == null) {
return defaultFormatters;
}
for (final String key : formatterMap.keySet()) {
if (marker.isInstanceOf(key)) {
return formatterMap.get(key);
}
}
return defaultFormatters;
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:14,代码来源:MarkerPatternSelector.java
示例16: toSerializable
import org.apache.logging.log4j.core.pattern.PatternFormatter; //导入依赖的package包/类
@Override
public StringBuilder toSerializable(final LogEvent event, final StringBuilder buffer) {
final PatternFormatter[] formatters = patternSelector.getFormatters(event);
final int len = formatters.length;
for (int i = 0; i < len; i++) {
formatters[i].format(event, buffer);
}
if (replace != null) { // creates temporary objects
String str = buffer.toString();
str = replace.format(str);
buffer.setLength(0);
buffer.append(str);
}
return buffer;
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:16,代码来源:PatternLayout.java
示例17: getFormatters
import org.apache.logging.log4j.core.pattern.PatternFormatter; //导入依赖的package包/类
@Override
public PatternFormatter[] getFormatters(final LogEvent event) {
final SimpleBindings bindings = new SimpleBindings();
bindings.putAll(configuration.getProperties());
bindings.put("substitutor", configuration.getStrSubstitutor());
bindings.put("logEvent", event);
final Object object = configuration.getScriptManager().execute(script.getName(), bindings);
if (object == null) {
return defaultFormatters;
}
final PatternFormatter[] patternFormatter = formatterMap.get(object.toString());
return patternFormatter == null ? defaultFormatters : patternFormatter;
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:15,代码来源:ScriptPatternSelector.java
示例18: format
import org.apache.logging.log4j.core.pattern.PatternFormatter; //导入依赖的package包/类
public StructuredDataElement format(final LogEvent event) {
final Map<String, String> map = new HashMap<>(delegateMap.size());
for (final Map.Entry<String, List<PatternFormatter>> entry : delegateMap.entrySet()) {
final StringBuilder buffer = new StringBuilder();
for (final PatternFormatter formatter : entry.getValue()) {
formatter.format(event, buffer);
}
map.put(entry.getKey(), buffer.toString());
}
return new StructuredDataElement(map, eventPrefix, discardIfEmpty);
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:13,代码来源:Rfc5424Layout.java
示例19: ColorConverter
import org.apache.logging.log4j.core.pattern.PatternFormatter; //导入依赖的package包/类
private ColorConverter(List<PatternFormatter> formatters, AnsiElement styling) {
super("style", "style");
this.formatters = formatters;
this.styling = styling;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:6,代码来源:ColorConverter.java
示例20: FieldFormatter
import org.apache.logging.log4j.core.pattern.PatternFormatter; //导入依赖的package包/类
public FieldFormatter(final Map<String, List<PatternFormatter>> fieldMap, final boolean discardIfEmpty) {
this.discardIfEmpty = discardIfEmpty;
this.delegateMap = fieldMap;
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:5,代码来源:RFC5424Layout.java
注:本文中的org.apache.logging.log4j.core.pattern.PatternFormatter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论