blob: 234d9af0c62614c41e347e47bef2faeec51ec22d [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.chemistry.opencmis.workbench;
import java.io.Serializable;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.Layout;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.StringLayout;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
import org.apache.logging.log4j.core.config.plugins.PluginElement;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
import org.apache.logging.log4j.core.layout.PatternLayout;
@Plugin(name = "ClientWriterAppender", category = "Core", elementType = "appender")
public class ClientWriterAppender extends AbstractAppender {
protected ClientWriterAppender(final String name, final Filter filter, final Layout<? extends Serializable> layout) {
super(name, filter, layout);
}
private static final long serialVersionUID = 1L;
private static JTextArea logTextArea = null;
public static void setTextArea(JTextArea textArea) {
logTextArea = textArea;
}
@Override
public void append(LogEvent event) {
if (logTextArea == null) {
return;
}
final String message = ((StringLayout) getLayout()).toSerializable(event);
if (message.length() > 0) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
logTextArea.append(message);
}
});
}
}
@PluginFactory
public static ClientWriterAppender createAppender(@PluginAttribute("name") String name,
@PluginAttribute("ignoreExceptions") boolean ignoreExceptions, @PluginElement("Layout") Layout<?> layout,
@PluginElement("Filters") Filter filter) {
if (name == null) {
LOGGER.error("No name provided for ClientWriterAppender");
return null;
}
if (layout == null) {
layout = PatternLayout.createDefaultLayout();
}
return new ClientWriterAppender(name, filter, (StringLayout) layout);
}
}