Re: Issue of creating and configuring custom appenders

2014-06-05 Thread Matt Sicker
That sounds more like a text editor at that point. Interactive /usr/bin/tail


On 4 June 2014 07:34, James Hutton  wrote:

> Yeah, ideally there's a limit to the buffer in both choices, however why
> aren't you just logging to a file and using the jtextarea to display the
> file contents? Then you don't have as much a worry about memory usage.
> On Jun 4, 2014 8:27 AM, "Gary Gregory"  wrote:
>
> > Note that you will shoot yourself in the foot with such an appender by
> > causing memory to be exhausted unless the appender never lets the
> contents
> > of the text area grow beyond some limit.
> >
> > Gary
> >
> >
> > On Mon, Jun 2, 2014 at 3:05 AM, Alex Wu  wrote:
> >
> > > Hi all, I have followed Ralph's suggestion in this issue and the source
> > > code of ConsoleAppender from apache to tried to create a custom
> appender
> > > for appending logs to a JTextArea.
> > >
> > > https://issues.apache.org/jira/browse/LOG4J2-303
> > >
> > > But I am having trouble to make it to work, could anyone please give me
> > > some help for this?
> > >
> > > the problems I am facing are,
> > >
> > > - I cannot find a way to pass that JTextArea object to my
> > TextAreaAppender
> > > - I am also having problem creating the manager, in ConsoleAppender,
> they
> > > use "new OutputStreamManager(data.os, data.type, data.layout)", and
> it's
> > > actually a "protected" constructor, how is this possible? BTW, eclipse
> is
> > > also showing error about this. *Actually, I got around with this by
> > > creating a subclass of OutputStreamManager in my test and make the
> > > constructor public, not sure if I have done it in a right way though.*
> > >
> > > Any help would be appreciated.
> > >
> > > Test classes are as follow,
> > >
> > > *TextAreaAppender.java*
> > >
> > > package testing;
> > >
> > > import java.io.IOException;
> > > import java.io.OutputStream;
> > > import java.io.Serializable;
> > >
> > > import javax.swing.JTextArea;
> > >
> > > import org.apache.logging.log4j.core.Filter;
> > > import org.apache.logging.log4j.core.Layout;
> > > import
> > org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender;
> > > import org.apache.logging.log4j.core.appender.ManagerFactory;
> > > import org.apache.logging.log4j.core.appender.OutputStreamManager;
> > > 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.helpers.Booleans;
> > > import org.apache.logging.log4j.core.layout.PatternLayout;
> > >
> > > import testing.ConsoleAppender.ConsoleManagerFactory;
> > >
> > >
> > > public class TextAreaAppender extends
> > > AbstractOutputStreamAppender{
> > > private static TextAreaManagerFactory factory = new
> > > TextAreaManagerFactory();
> > >  public enum Target {
> > > TEXTAREA
> > > }
> > >
> > > protected TextAreaAppender(String name, Layout
> > > layout, Filter filter,
> > > OutputStreamManager manager, boolean ignoreExceptions) {
> > > super(name, layout, filter, ignoreExceptions, true, manager);
> > > // TODO Auto-generated constructor stub
> > > }
> > >  @PluginFactory
> > > public static TextAreaAppender createAppender(
> > > @PluginElement("Layout") Layout
> > layout,
> > > @PluginElement("Filters") final Filter filter,
> > > @PluginAttribute("target") final String t,
> > > @PluginAttribute("name") final String name,
> > > @PluginAttribute("follow") final String follow,
> > > @PluginAttribute("ignoreExceptions") final String ignore) {
> > > if (name == null) {
> > > LOGGER.error("No name provided for TextAreaAppender");
> > > return null;
> > > }
> > > if (layout == null) {
> > > layout = PatternLayout.createLayout(null, null, null, null,
> > > null, null);
> > > }
> > > final boolean isFollow = Boolean.parseBoolean(follow);
> > > final boolean ignoreExceptions = Booleans.parseBoolean(ignore,
> > > true);
> > > final Target target = t == null ? Target.TEXTAREA :
> > > Target.valueOf(t);
> > > return new TextAreaAppender(name, layout, filter,
> > > getManager(isFollow, target, layout), ignoreExceptions);
> > > }
> > >  private static OutputStreamManager getManager(final boolean follow,
> > final
> > > Target target, final Layout layout) {
> > > final String type = target.name();
> > > //should change to getOutputStream(JTextArea),
> > > //but not sure how I can pass textarea object to this class
> > > final OutputStream os = getOutputStream(follow, target);
> > > return OutputStreamManager.getManager(target.name() + "." +
> > > follow,
> > > new FactoryData(os, type, layout), factory);
> > > }
> > >  private static OutputStream getOutputStream(JTextArea ta){
> > > return new TextAreaOutputStre

Re: Issue of creating and configuring custom appenders

2014-06-04 Thread James Hutton
Yeah, ideally there's a limit to the buffer in both choices, however why
aren't you just logging to a file and using the jtextarea to display the
file contents? Then you don't have as much a worry about memory usage.
On Jun 4, 2014 8:27 AM, "Gary Gregory"  wrote:

> Note that you will shoot yourself in the foot with such an appender by
> causing memory to be exhausted unless the appender never lets the contents
> of the text area grow beyond some limit.
>
> Gary
>
>
> On Mon, Jun 2, 2014 at 3:05 AM, Alex Wu  wrote:
>
> > Hi all, I have followed Ralph's suggestion in this issue and the source
> > code of ConsoleAppender from apache to tried to create a custom appender
> > for appending logs to a JTextArea.
> >
> > https://issues.apache.org/jira/browse/LOG4J2-303
> >
> > But I am having trouble to make it to work, could anyone please give me
> > some help for this?
> >
> > the problems I am facing are,
> >
> > - I cannot find a way to pass that JTextArea object to my
> TextAreaAppender
> > - I am also having problem creating the manager, in ConsoleAppender, they
> > use "new OutputStreamManager(data.os, data.type, data.layout)", and it's
> > actually a "protected" constructor, how is this possible? BTW, eclipse is
> > also showing error about this. *Actually, I got around with this by
> > creating a subclass of OutputStreamManager in my test and make the
> > constructor public, not sure if I have done it in a right way though.*
> >
> > Any help would be appreciated.
> >
> > Test classes are as follow,
> >
> > *TextAreaAppender.java*
> >
> > package testing;
> >
> > import java.io.IOException;
> > import java.io.OutputStream;
> > import java.io.Serializable;
> >
> > import javax.swing.JTextArea;
> >
> > import org.apache.logging.log4j.core.Filter;
> > import org.apache.logging.log4j.core.Layout;
> > import
> org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender;
> > import org.apache.logging.log4j.core.appender.ManagerFactory;
> > import org.apache.logging.log4j.core.appender.OutputStreamManager;
> > 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.helpers.Booleans;
> > import org.apache.logging.log4j.core.layout.PatternLayout;
> >
> > import testing.ConsoleAppender.ConsoleManagerFactory;
> >
> >
> > public class TextAreaAppender extends
> > AbstractOutputStreamAppender{
> > private static TextAreaManagerFactory factory = new
> > TextAreaManagerFactory();
> >  public enum Target {
> > TEXTAREA
> > }
> >
> > protected TextAreaAppender(String name, Layout
> > layout, Filter filter,
> > OutputStreamManager manager, boolean ignoreExceptions) {
> > super(name, layout, filter, ignoreExceptions, true, manager);
> > // TODO Auto-generated constructor stub
> > }
> >  @PluginFactory
> > public static TextAreaAppender createAppender(
> > @PluginElement("Layout") Layout
> layout,
> > @PluginElement("Filters") final Filter filter,
> > @PluginAttribute("target") final String t,
> > @PluginAttribute("name") final String name,
> > @PluginAttribute("follow") final String follow,
> > @PluginAttribute("ignoreExceptions") final String ignore) {
> > if (name == null) {
> > LOGGER.error("No name provided for TextAreaAppender");
> > return null;
> > }
> > if (layout == null) {
> > layout = PatternLayout.createLayout(null, null, null, null,
> > null, null);
> > }
> > final boolean isFollow = Boolean.parseBoolean(follow);
> > final boolean ignoreExceptions = Booleans.parseBoolean(ignore,
> > true);
> > final Target target = t == null ? Target.TEXTAREA :
> > Target.valueOf(t);
> > return new TextAreaAppender(name, layout, filter,
> > getManager(isFollow, target, layout), ignoreExceptions);
> > }
> >  private static OutputStreamManager getManager(final boolean follow,
> final
> > Target target, final Layout layout) {
> > final String type = target.name();
> > //should change to getOutputStream(JTextArea),
> > //but not sure how I can pass textarea object to this class
> > final OutputStream os = getOutputStream(follow, target);
> > return OutputStreamManager.getManager(target.name() + "." +
> > follow,
> > new FactoryData(os, type, layout), factory);
> > }
> >  private static OutputStream getOutputStream(JTextArea ta){
> > return new TextAreaOutputStream(ta);
> > }
> > private static class TextAreaOutputStream extends OutputStream {
> > private final JTextArea output;
> > public TextAreaOutputStream(JTextArea ta){
> > this.output = ta;
> > }
> > @Override
> > public void write(int i) throws IOException{
> > output.append(String.valueOf((char) i));
> > }
> > }
> >  /**
> >  * Data to pass to factory meth

Re: Issue of creating and configuring custom appenders

2014-06-04 Thread Gary Gregory
Note that you will shoot yourself in the foot with such an appender by
causing memory to be exhausted unless the appender never lets the contents
of the text area grow beyond some limit.

Gary


On Mon, Jun 2, 2014 at 3:05 AM, Alex Wu  wrote:

> Hi all, I have followed Ralph's suggestion in this issue and the source
> code of ConsoleAppender from apache to tried to create a custom appender
> for appending logs to a JTextArea.
>
> https://issues.apache.org/jira/browse/LOG4J2-303
>
> But I am having trouble to make it to work, could anyone please give me
> some help for this?
>
> the problems I am facing are,
>
> - I cannot find a way to pass that JTextArea object to my TextAreaAppender
> - I am also having problem creating the manager, in ConsoleAppender, they
> use "new OutputStreamManager(data.os, data.type, data.layout)", and it's
> actually a "protected" constructor, how is this possible? BTW, eclipse is
> also showing error about this. *Actually, I got around with this by
> creating a subclass of OutputStreamManager in my test and make the
> constructor public, not sure if I have done it in a right way though.*
>
> Any help would be appreciated.
>
> Test classes are as follow,
>
> *TextAreaAppender.java*
>
> package testing;
>
> import java.io.IOException;
> import java.io.OutputStream;
> import java.io.Serializable;
>
> import javax.swing.JTextArea;
>
> import org.apache.logging.log4j.core.Filter;
> import org.apache.logging.log4j.core.Layout;
> import org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender;
> import org.apache.logging.log4j.core.appender.ManagerFactory;
> import org.apache.logging.log4j.core.appender.OutputStreamManager;
> 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.helpers.Booleans;
> import org.apache.logging.log4j.core.layout.PatternLayout;
>
> import testing.ConsoleAppender.ConsoleManagerFactory;
>
>
> public class TextAreaAppender extends
> AbstractOutputStreamAppender{
> private static TextAreaManagerFactory factory = new
> TextAreaManagerFactory();
>  public enum Target {
> TEXTAREA
> }
>
> protected TextAreaAppender(String name, Layout
> layout, Filter filter,
> OutputStreamManager manager, boolean ignoreExceptions) {
> super(name, layout, filter, ignoreExceptions, true, manager);
> // TODO Auto-generated constructor stub
> }
>  @PluginFactory
> public static TextAreaAppender createAppender(
> @PluginElement("Layout") Layout layout,
> @PluginElement("Filters") final Filter filter,
> @PluginAttribute("target") final String t,
> @PluginAttribute("name") final String name,
> @PluginAttribute("follow") final String follow,
> @PluginAttribute("ignoreExceptions") final String ignore) {
> if (name == null) {
> LOGGER.error("No name provided for TextAreaAppender");
> return null;
> }
> if (layout == null) {
> layout = PatternLayout.createLayout(null, null, null, null,
> null, null);
> }
> final boolean isFollow = Boolean.parseBoolean(follow);
> final boolean ignoreExceptions = Booleans.parseBoolean(ignore,
> true);
> final Target target = t == null ? Target.TEXTAREA :
> Target.valueOf(t);
> return new TextAreaAppender(name, layout, filter,
> getManager(isFollow, target, layout), ignoreExceptions);
> }
>  private static OutputStreamManager getManager(final boolean follow, final
> Target target, final Layout layout) {
> final String type = target.name();
> //should change to getOutputStream(JTextArea),
> //but not sure how I can pass textarea object to this class
> final OutputStream os = getOutputStream(follow, target);
> return OutputStreamManager.getManager(target.name() + "." +
> follow,
> new FactoryData(os, type, layout), factory);
> }
>  private static OutputStream getOutputStream(JTextArea ta){
> return new TextAreaOutputStream(ta);
> }
> private static class TextAreaOutputStream extends OutputStream {
> private final JTextArea output;
> public TextAreaOutputStream(JTextArea ta){
> this.output = ta;
> }
> @Override
> public void write(int i) throws IOException{
> output.append(String.valueOf((char) i));
> }
> }
>  /**
>  * Data to pass to factory method.
>  */
> private static class FactoryData {
> private final OutputStream os;
> private final String type;
> private final Layout layout;
>
> /**
>  * Constructor.
>  * @param os The OutputStream.
>  * @param type The name of the target.
>  * @param layout A Serializable layout
>  */
> public FactoryData(final OutputStream os, final String type, final
> Layout layout) {
> this.os = os;
> th

Re: Issue of creating and configuring custom appenders

2014-06-04 Thread James Hutton
Maybe have the appender be the owner of the jtextarea such that you could
call a gettextarea method when initializing your ui? Or you could buffer
until you call an initialize method with the jtext area.  With the first
one not sure if you can write to the text area if it isn't in a frame, but
I'm not a swing expert.
On Jun 2, 2014 3:06 AM, "Alex Wu"  wrote:

> Hi all, I have followed Ralph's suggestion in this issue and the source
> code of ConsoleAppender from apache to tried to create a custom appender
> for appending logs to a JTextArea.
>
> https://issues.apache.org/jira/browse/LOG4J2-303
>
> But I am having trouble to make it to work, could anyone please give me
> some help for this?
>
> the problems I am facing are,
>
> - I cannot find a way to pass that JTextArea object to my TextAreaAppender
> - I am also having problem creating the manager, in ConsoleAppender, they
> use "new OutputStreamManager(data.os, data.type, data.layout)", and it's
> actually a "protected" constructor, how is this possible? BTW, eclipse is
> also showing error about this. *Actually, I got around with this by
> creating a subclass of OutputStreamManager in my test and make the
> constructor public, not sure if I have done it in a right way though.*
>
> Any help would be appreciated.
>
> Test classes are as follow,
>
> *TextAreaAppender.java*
>
> package testing;
>
> import java.io.IOException;
> import java.io.OutputStream;
> import java.io.Serializable;
>
> import javax.swing.JTextArea;
>
> import org.apache.logging.log4j.core.Filter;
> import org.apache.logging.log4j.core.Layout;
> import org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender;
> import org.apache.logging.log4j.core.appender.ManagerFactory;
> import org.apache.logging.log4j.core.appender.OutputStreamManager;
> 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.helpers.Booleans;
> import org.apache.logging.log4j.core.layout.PatternLayout;
>
> import testing.ConsoleAppender.ConsoleManagerFactory;
>
>
> public class TextAreaAppender extends
> AbstractOutputStreamAppender{
> private static TextAreaManagerFactory factory = new
> TextAreaManagerFactory();
>  public enum Target {
> TEXTAREA
> }
>
> protected TextAreaAppender(String name, Layout
> layout, Filter filter,
> OutputStreamManager manager, boolean ignoreExceptions) {
> super(name, layout, filter, ignoreExceptions, true, manager);
> // TODO Auto-generated constructor stub
> }
>  @PluginFactory
> public static TextAreaAppender createAppender(
> @PluginElement("Layout") Layout layout,
> @PluginElement("Filters") final Filter filter,
> @PluginAttribute("target") final String t,
> @PluginAttribute("name") final String name,
> @PluginAttribute("follow") final String follow,
> @PluginAttribute("ignoreExceptions") final String ignore) {
> if (name == null) {
> LOGGER.error("No name provided for TextAreaAppender");
> return null;
> }
> if (layout == null) {
> layout = PatternLayout.createLayout(null, null, null, null,
> null, null);
> }
> final boolean isFollow = Boolean.parseBoolean(follow);
> final boolean ignoreExceptions = Booleans.parseBoolean(ignore,
> true);
> final Target target = t == null ? Target.TEXTAREA :
> Target.valueOf(t);
> return new TextAreaAppender(name, layout, filter,
> getManager(isFollow, target, layout), ignoreExceptions);
> }
>  private static OutputStreamManager getManager(final boolean follow, final
> Target target, final Layout layout) {
> final String type = target.name();
> //should change to getOutputStream(JTextArea),
> //but not sure how I can pass textarea object to this class
> final OutputStream os = getOutputStream(follow, target);
> return OutputStreamManager.getManager(target.name() + "." +
> follow,
> new FactoryData(os, type, layout), factory);
> }
>  private static OutputStream getOutputStream(JTextArea ta){
> return new TextAreaOutputStream(ta);
> }
> private static class TextAreaOutputStream extends OutputStream {
> private final JTextArea output;
> public TextAreaOutputStream(JTextArea ta){
> this.output = ta;
> }
> @Override
> public void write(int i) throws IOException{
> output.append(String.valueOf((char) i));
> }
> }
>  /**
>  * Data to pass to factory method.
>  */
> private static class FactoryData {
> private final OutputStream os;
> private final String type;
> private final Layout layout;
>
> /**
>  * Constructor.
>  * @param os The OutputStream.
>  * @param type The name of the target.
>  * @param layout A Serializable layout
>  */
> public Facto