Java Code Examples for org.apache.logging.log4j.core.layout.PatternLayout#createDefaultLayout()
The following examples show how to use
org.apache.logging.log4j.core.layout.PatternLayout#createDefaultLayout() .
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: ServletAppender.java From logging-log4j2 with Apache License 2.0 | 7 votes |
@Override public ServletAppender build() { final String name = getName(); if (name == null) { LOGGER.error("No name provided for ServletAppender"); } final ServletContext servletContext = WebLoggerContextUtils.getServletContext(); if (servletContext == null) { LOGGER.error("No servlet context is available"); return null; } Layout<? extends Serializable> layout = getLayout(); if (layout == null) { layout = PatternLayout.createDefaultLayout(); } else if (!(layout instanceof AbstractStringLayout)) { LOGGER.error("Layout must be a StringLayout to log to ServletContext"); return null; } return new ServletAppender(name, layout, getFilter(), servletContext, isIgnoreExceptions(), logThrowables, getPropertyArray()); }
Example 2
Source File: LogTestRule.java From ArchUnit with Apache License 2.0 | 6 votes |
public void watch(Class<?> loggerClass, Level level) { this.loggerClass = loggerClass; Appender appender = new AbstractAppender(APPENDER_NAME, null, PatternLayout.createDefaultLayout()) { @Override public void append(LogEvent event) { logEvents.add(new RecordedLogEvent(event)); } }; appender.start(); final LoggerContext ctx = getLoggerContext(); LoggerConfig loggerConfig = ctx.getConfiguration().getLoggerConfig(loggerClass.getName()); oldLevel = loggerConfig.getLevel(); loggerConfig.setLevel(level); loggerConfig.addAppender(appender, level, null); ctx.updateLoggers(); }
Example 3
Source File: S2STestService.java From Openfire with Apache License 2.0 | 6 votes |
String addAppender(final Writer writer) { final String name = "openfire-s2s-test-appender-" + StringUtils.randomString( 10 ); final LoggerContext context = LoggerContext.getContext(false); final Configuration config = context.getConfiguration(); final PatternLayout layout = PatternLayout.createDefaultLayout(config); final Appender appender = WriterAppender.createAppender(layout, null, writer, name, false, true); appender.start(); config.addAppender(appender); final Level level = null; final Filter filter = null; for (final LoggerConfig loggerConfig : config.getLoggers().values()) { loggerConfig.addAppender(appender, level, filter); } config.getRootLogger().addAppender(appender, level, filter); return name; }
Example 4
Source File: LogPanelAppender.java From ghidra with Apache License 2.0 | 5 votes |
@PluginFactory public static LogPanelAppender createAppender(@PluginAttribute("name") String name, @PluginElement("Layout") Layout<? extends Serializable> layout, @PluginElement("Filter") final Filter filter, @PluginAttribute("otherAttribute") String otherAttribute) { if (name == null) { LOGGER.error("No name provided for LogPanelAppender"); return null; } if (layout == null) { layout = PatternLayout.createDefaultLayout(); } return new LogPanelAppender(name, filter, layout); }
Example 5
Source File: JSwingAppender.java From collect-earth with MIT License | 5 votes |
@PluginFactory public static JSwingAppender createAppender(@PluginAttribute("name") String name, @PluginElement("Layout") Layout<?> layout, @PluginElement("Filters") Filter filter, @PluginAttribute("ignoreExceptions") boolean ignoreExceptions) { if (name == null) { LoggerFactory.getLogger( JSwingAppender.class ).error("No name provided for JTextAreaAppender"); return null; } if (layout == null) { layout = PatternLayout.createDefaultLayout(); } return new JSwingAppender(name, filter, layout, ignoreExceptions); }
Example 6
Source File: CircularQueueLogAppender.java From engine with GNU General Public License v3.0 | 5 votes |
@PluginFactory public static CircularQueueLogAppender createAppender( @PluginAttribute(value = "name") String name, @PluginElement(value = "Filters") Filter filter, @PluginElement(value = "Layout") Layout<? extends Serializable> layout, @PluginAttribute(value = "ignoreExceptions") boolean ignoreExceptions, @PluginAttribute(value = "maxQueueSize") int maxQueueSize, @PluginAttribute(value = "dateFormat") String dateFormat, @PluginAttribute(value = "global") boolean global) { if (StringUtils.isEmpty(name)) { LOGGER.error("No name provided for " + PLUGIN_NAME); return null; } if (Objects.isNull(layout)) { layout = PatternLayout.createDefaultLayout(); } if (Objects.isNull(buffer)) { LOGGER.debug("Initializing circular log queue buffer"); if (maxQueueSize <= 0) { throw new IllegalArgumentException("maxQueueSize must be a integer bigger that 0"); } buffer = BufferUtils.synchronizedBuffer(new CircularFifoBuffer(maxQueueSize)); } CircularQueueLogAppender appender = new CircularQueueLogAppender(name, filter, layout, ignoreExceptions, null); appender.dateFormat = DateTimeFormatter.ofPattern(dateFormat).withZone(ZoneId.of("UTC")); appender.global = global; return appender; }
Example 7
Source File: OutputStreamAppenderTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
/** * Tests that you can add an output stream appender dynamically. */ private void addAppender(final OutputStream outputStream, final String outputStreamName) { final LoggerContext context = LoggerContext.getContext(false); final Configuration config = context.getConfiguration(); final PatternLayout layout = PatternLayout.createDefaultLayout(config); final Appender appender = OutputStreamAppender.createAppender(layout, null, outputStream, outputStreamName, false, true); appender.start(); config.addAppender(appender); ConfigurationTestUtils.updateLoggers(appender, config); }
Example 8
Source File: ConsoleAppender.java From Flashtool with GNU General Public License v3.0 | 5 votes |
/** * Factory method. Log4j will parse the configuration and call this factory * method to construct the appender with * the configured attributes. * * @param name Name of appender * @param layout Log layout of appender * @param filter Filter for appender * @return The TextAreaAppender */ @PluginFactory public static ConsoleAppender createAppender( @PluginAttribute("name") String name, @PluginElement("Layout") Layout<? extends Serializable> layout, @PluginElement("Filter") final Filter filter) { if (name == null) { LOGGER.error("No name provided for TextAreaAppender2"); return null; } if (layout == null) { layout = PatternLayout.createDefaultLayout(); } return new ConsoleAppender(name, filter, layout, true); }
Example 9
Source File: TextAreaAppender.java From Flashtool with GNU General Public License v3.0 | 5 votes |
/** * Factory method. Log4j will parse the configuration and call this factory * method to construct the appender with * the configured attributes. * * @param name Name of appender * @param layout Log layout of appender * @param filter Filter for appender * @return The TextAreaAppender */ @PluginFactory public static TextAreaAppender createAppender( @PluginAttribute("name") String name, @PluginElement("Layout") Layout<? extends Serializable> layout, @PluginElement("Filter") final Filter filter) { if (name == null) { LOGGER.error("No name provided for TextAreaAppender2"); return null; } if (layout == null) { layout = PatternLayout.createDefaultLayout(); } return new TextAreaAppender(name, filter, layout, true); }
Example 10
Source File: InMemoryAppenderTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Test public void testAppender() { final Layout<String> layout = PatternLayout.createDefaultLayout(); final boolean writeHeader = true; final InMemoryAppender app = new InMemoryAppender("test", layout, null, false, writeHeader, null); final String expectedHeader = null; assertMessage("Test", app, expectedHeader); }
Example 11
Source File: TextAreaAppender.java From ModPackDownloader with MIT License | 5 votes |
/** * Factory method. Log4j will parse the configuration and call this factory * method to construct the appender with * the configured attributes. * * @param name Name of appender * @param layout Log layout of appender * @param filter Filter for appender * @return The TextAreaAppender */ @PluginFactory public static TextAreaAppender createAppender( @PluginAttribute("name") String name, @PluginElement("Layout") Layout<? extends Serializable> layout, @PluginElement("Filter") final Filter filter) { if (name == null) { LOGGER.error("No name provided for TextAreaAppender"); return null; } if (layout == null) { layout = PatternLayout.createDefaultLayout(); } return new TextAreaAppender(name, filter, layout, true); }
Example 12
Source File: MCRWebCLIContainer.java From mycore with GNU General Public License v3.0 | 5 votes |
ProcessCallable(MCRSession session, Session webSocketSession, ReentrantLock lock) { this.commands = new ArrayList<>(); this.session = session; this.lock = lock; this.stopLogs = false; this.webSocketSession = webSocketSession; this.logGrabber = new Log4JGrabber(MCRWebCLIContainer.class.getSimpleName() + session.getID(), null, PatternLayout.createDefaultLayout(), true, Property.EMPTY_ARRAY); this.logGrabber.start(); startLogging(true); cmdListPublisher = new SubmissionPublisher<>(ForkJoinPool.commonPool(), 1); this.currentCommand = ""; this.continueIfOneFails = false; startSendingCommandQueue(); }
Example 13
Source File: WriterAppenderTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
private void addAppender(final Writer writer, final String writerName) { final LoggerContext context = LoggerContext.getContext(false); final Configuration config = context.getConfiguration(); final PatternLayout layout = PatternLayout.createDefaultLayout(config); final Appender appender = WriterAppender.createAppender(layout, null, writer, writerName, false, true); appender.start(); config.addAppender(appender); ConfigurationTestUtils.updateLoggers(appender, config); }
Example 14
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 15
Source File: FrontConsoleAppender.java From molicode with Apache License 2.0 | 5 votes |
@PluginFactory public static FrontConsoleAppender createAppender(@PluginAttribute("name") String name, @PluginAttribute("fileName") String fileName, @PluginElement("Filter") final Filter filter, @PluginElement("Layout") Layout<? extends Serializable> layout, @PluginAttribute("ignoreExceptions") boolean ignoreExceptions) { if (name == null) { LOGGER.error("no name defined in conf."); return null; } if (layout == null) { layout = PatternLayout.createDefaultLayout(); } return new FrontConsoleAppender(name, filter, layout, ignoreExceptions, fileName); }
Example 16
Source File: Log4j2Test.java From flogger with Apache License 2.0 | 4 votes |
CapturingAppender() { super(NAME, null, PatternLayout.createDefaultLayout(), true, null); start(); }
Example 17
Source File: AbstractADTest.java From anomaly-detection with Apache License 2.0 | 4 votes |
protected TestAppender(String name) { super(name, null, PatternLayout.createDefaultLayout(), true); }
Example 18
Source File: JeroMqAppender.java From logging-log4j2 with Apache License 2.0 | 4 votes |
@PluginFactory public static JeroMqAppender createAppender( // @formatter:off @Required(message = "No name provided for JeroMqAppender") @PluginAttribute final String name, @PluginElement Layout<?> layout, @PluginElement final Filter filter, @PluginElement final Property[] properties, // Super attributes @PluginAttribute final boolean ignoreExceptions, // ZMQ attributes; defaults picked from zmq.Options. @PluginAttribute(defaultLong = 0) final long affinity, @PluginAttribute(defaultLong = DEFAULT_BACKLOG) final long backlog, @PluginAttribute final boolean delayAttachOnConnect, @PluginAttribute final byte[] identity, @PluginAttribute(defaultBoolean = true) final boolean ipv4Only, @PluginAttribute(defaultLong = -1) final long linger, @PluginAttribute(defaultLong = -1) final long maxMsgSize, @PluginAttribute(defaultLong = DEFAULT_RCV_HWM) final long rcvHwm, @PluginAttribute(defaultLong = 0) final long receiveBufferSize, @PluginAttribute(defaultLong = -1) final int receiveTimeOut, @PluginAttribute(defaultLong = DEFAULT_IVL) final long reconnectIVL, @PluginAttribute(defaultLong = 0) final long reconnectIVLMax, @PluginAttribute(defaultLong = 0) final long sendBufferSize, @PluginAttribute(defaultLong = -1) final int sendTimeOut, @PluginAttribute(defaultLong = DEFAULT_SND_HWM) final long sndHwm, @PluginAttribute(defaultInt = -1) final int tcpKeepAlive, @PluginAttribute(defaultLong = -1) final long tcpKeepAliveCount, @PluginAttribute(defaultLong = -1) final long tcpKeepAliveIdle, @PluginAttribute(defaultLong = -1) final long tcpKeepAliveInterval, @PluginAttribute final boolean xpubVerbose // @formatter:on ) { if (layout == null) { layout = PatternLayout.createDefaultLayout(); } List<String> endpoints; if (properties == null) { endpoints = new ArrayList<>(0); } else { endpoints = new ArrayList<>(properties.length); for (final Property property : properties) { if ("endpoint".equalsIgnoreCase(property.getName())) { final String value = property.getValue(); if (Strings.isNotEmpty(value)) { endpoints.add(value); } } } } LOGGER.debug("Creating JeroMqAppender with name={}, filter={}, layout={}, ignoreExceptions={}, endpoints={}", name, filter, layout, ignoreExceptions, endpoints); return new JeroMqAppender(name, filter, layout, ignoreExceptions, endpoints, affinity, backlog, delayAttachOnConnect, identity, ipv4Only, linger, maxMsgSize, rcvHwm, receiveBufferSize, receiveTimeOut, reconnectIVL, reconnectIVLMax, sendBufferSize, sendTimeOut, sndHwm, tcpKeepAlive, tcpKeepAliveCount, tcpKeepAliveIdle, tcpKeepAliveInterval, xpubVerbose, Property.EMPTY_ARRAY); }
Example 19
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 20
Source File: OutputStreamAppender.java From logging-log4j2 with Apache License 2.0 | 3 votes |
/** * Creates an OutputStream Appender. * * @param layout * The layout to use or null to get the default layout. * @param filter * The Filter or null. * @param target * an output stream. * @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 OutputStreamAppender createAppender(Layout<? extends Serializable> layout, final Filter filter, final OutputStream target, final String name, final boolean follow, final boolean ignore) { if (name == null) { LOGGER.error("No name provided for OutputStreamAppender"); return null; } if (layout == null) { layout = PatternLayout.createDefaultLayout(); } return new OutputStreamAppender(name, layout, filter, getManager(target, follow, layout), ignore, null); }