org.apache.logging.log4j.core.StringLayout Java Examples
The following examples show how to use
org.apache.logging.log4j.core.StringLayout.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpenCensusLog4jLogCorrelationTest.java From opencensus-java with Apache License 2.0 | 7 votes |
private static String logWithSpanAndLog4jConfiguration( String log4jPattern, SpanContext spanContext, Function<Logger, Void> loggingFunction) { StringWriter output = new StringWriter(); StringLayout layout = PatternLayout.newBuilder().withPattern(log4jPattern).build(); Appender appender = WriterAppender.newBuilder() .setTarget(output) .setLayout(layout) .setName("TestAppender") .build(); ((LoggerContext) LogManager.getContext(false)).updateLoggers(); appender.start(); logger.addAppender(appender); logger.setLevel(Level.ALL); try { logWithSpan(spanContext, loggingFunction, logger); return output.toString(); } finally { logger.removeAppender(appender); } }
Example #2
Source File: TextAreaAppender.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public void append(LogEvent event) { readLock.lock(); try { if (textArea == null) { // just ignore any events logged before the area is available return; } final String message = ((StringLayout) getLayout()).toSerializable(event); SwingUtilities.invokeLater(() -> { textArea.append(message); }); } finally { readLock.unlock(); } }
Example #3
Source File: WriterManager.java From logging-log4j2 with Apache License 2.0 | 6 votes |
public WriterManager(final Writer writer, final String streamName, final StringLayout layout, final boolean writeHeader) { super(null, streamName); this.writer = writer; this.layout = layout; if (writeHeader && layout != null) { final byte[] header = layout.getHeader(); if (header != null) { try { this.writer.write(new String(header, layout.getCharset())); } catch (final IOException e) { logError("Unable to write header", e); } } } }
Example #4
Source File: WriterAppender.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Override public WriterAppender build() { final StringLayout layout = (StringLayout) getLayout(); final StringLayout actualLayout = layout != null ? layout : PatternLayout.createDefaultLayout(); return new WriterAppender(getName(), actualLayout, getFilter(), getManager(target, follow, actualLayout), isIgnoreExceptions(), getPropertyArray()); }
Example #5
Source File: ColumnMapping.java From logging-log4j2 with Apache License 2.0 | 5 votes |
private ColumnMapping(final String name, final String source, final StringLayout layout, final String literalValue, final String parameter, final Class<?> type) { this.name = name; this.nameKey = toKey(name); this.source = source; this.layout = layout; this.literalValue = literalValue; this.parameter = parameter; this.type = type; }
Example #6
Source File: LoggerPanelAppender.java From jmeter-debugger with Apache License 2.0 | 4 votes |
public StringLayout getStringLayout() { return (StringLayout) getLayout(); }
Example #7
Source File: ClassicLogger.java From logging-log4j2 with Apache License 2.0 | 4 votes |
@Override protected StringLayout createLayout() { return PatternLayout.newBuilder().setCharset(StandardCharsets.UTF_8).setPattern("%m").build(); }
Example #8
Source File: AbstractWriterAppender.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public StringLayout getStringLayout() { return (StringLayout) getLayout(); }
Example #9
Source File: WriterAppender.java From logging-log4j2 with Apache License 2.0 | 4 votes |
private static WriterManager getManager(final Writer target, final boolean follow, final StringLayout layout) { final Writer writer = new CloseShieldWriter(target); final String managerName = target.getClass().getName() + "@" + Integer.toHexString(target.hashCode()) + '.' + follow; return WriterManager.getManager(managerName, new FactoryData(writer, managerName, layout), factory); }
Example #10
Source File: WriterAppender.java From logging-log4j2 with Apache License 2.0 | 4 votes |
private WriterAppender(final String name, final StringLayout layout, final Filter filter, final WriterManager manager, final boolean ignoreExceptions, Property[] properties) { super(name, layout, filter, ignoreExceptions, true, properties, manager); }
Example #11
Source File: ColumnMapping.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public StringLayout getLayout() { return layout; }
Example #12
Source File: AbstractWriterAppender.java From logging-log4j2 with Apache License 2.0 | 3 votes |
/** * Instantiates. * * @param name * The name of the Appender. * @param layout * The layout to format the message. * @param properties Optional properties. * @param manager * The OutputStreamManager. */ protected AbstractWriterAppender(final String name, final StringLayout layout, final Filter filter, final boolean ignoreExceptions, final boolean immediateFlush, Property[] properties, final M manager) { super(name, filter, layout, ignoreExceptions, properties); this.manager = manager; this.immediateFlush = immediateFlush; }
Example #13
Source File: WriterAppender.java From logging-log4j2 with Apache License 2.0 | 3 votes |
/** * Creates a WriterAppender. * * @param layout * The layout to use or null to get the default layout. * @param filter * The Filter or null. * @param target * The target Writer * @param follow * If true will follow changes to the underlying output stream. * Use false as the default. * @param name * The name of the Appender (required). * @param ignore * If {@code "true"} (default) exceptions encountered when * appending events are logged; otherwise they are propagated to * the caller. Use true as the default. * @return The ConsoleAppender. */ @PluginFactory public static WriterAppender createAppender(StringLayout layout, final Filter filter, final Writer target, final String name, final boolean follow, final boolean ignore) { if (name == null) { LOGGER.error("No name provided for WriterAppender"); return null; } if (layout == null) { layout = PatternLayout.createDefaultLayout(); } return new WriterAppender(name, layout, filter, getManager(target, follow, layout), ignore, Property.EMPTY_ARRAY); }
Example #14
Source File: WriterAppender.java From logging-log4j2 with Apache License 2.0 | 2 votes |
/** * Builds instances. * * @param writer * The OutputStream. * @param type * The name of the target. * @param layout * A String layout */ public FactoryData(final Writer writer, final String type, final StringLayout layout) { this.writer = writer; this.name = type; this.layout = layout; }
Example #15
Source File: ColumnMapping.java From logging-log4j2 with Apache License 2.0 | 2 votes |
/** * Layout of value to write to database (before type conversion). Not applicable if {@link #setType(Class)} is * a {@link ReadOnlyStringMap}, {@link ThreadContextMap}, or {@link ThreadContextStack}. * * @return this. */ public Builder setLayout(final StringLayout layout) { this.layout = layout; return this; }