org.apache.logging.log4j.core.layout.AbstractStringLayout Java Examples

The following examples show how to use org.apache.logging.log4j.core.layout.AbstractStringLayout. 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 vote down vote up
@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: ServletAppender.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public void append(final LogEvent event) {
    final String serialized = ((AbstractStringLayout) getLayout()).toSerializable(event);
    if (logThrowables) {
        servletContext.log(serialized, event.getThrown());
    } else {
        servletContext.log(serialized);
    }
}