logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "vibin (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (LOG4J2-561) Custom appender configuration help.
Date Tue, 04 Mar 2014 15:11:20 GMT

     [ https://issues.apache.org/jira/browse/LOG4J2-561?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

vibin updated LOG4J2-561:
-------------------------

    Description: 
Can anyone please explain how to configure a custom appender..?
here is my code it did not work..

@Plugin(name = "EM_Appender", category = "Core", elementType = "appender", printObject = true)
public final class EventManagerAppender extends AbstractAppender{
 
protected EventManagerAppender(String name, Filter filter, Layout<? extends Serializable>
layout,
                                 boolean ignoreExceptions)
  {
    super(name, filter, layout, ignoreExceptions);
    // TODO Auto-generated constructor stub
  }

/*    @SuppressWarnings("rawtypes")
    private EventManagerAppender(String name, Layout layout, Filter filter,
                         boolean ignoreExceptions) {

    }*/
 
  
    @PluginFactory
    public static EventManagerAppender createAppender(@PluginAttribute("name") String name,
                                              @PluginAttribute("ignoreExceptions") String
ignore,
                                              @PluginElement("Layout") Layout layout,
                                              @PluginElement("Filters") Filter filter) {
 
        boolean ignoreExceptions = Boolean.parseBoolean(ignore);
        if (name == null) {
            return null;
        }
 
        if (layout == null) {
            layout = PatternLayout.createLayout(null, null, null, null, ignore, ignore);
        }
        return new EventManagerAppender(name, filter,layout, ignoreExceptions);
    }
    
    /**
     * The append method starts a job to send a message to the default console.
     */
     public void append(LogEvent event) {

        System.out.println(event.getMessage());
        System.out.println("Custome appender");
    }
}

XML configuration
**********************
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" strict="true" name="XMLConfigTest"
               packages="org.apache.logging.log4j.test,com.mycompany.abc.def.log.wrapper"
monitorInterval="30">
<Properties>
	<Property name="filename">C:/Logs/test1.log</Property>
</Properties>
<Filter type="ThresholdFilter" level="warn"/>
 
<Appenders>
	<Appender type="File" name="File" fileName="${filename}">
		<Layout type="PatternLayout">
		<Pattern>%d{dd MMM yyyy HH:mm:ss,SSS} %-5p [%c{1}:%L:%t] %m%n</Pattern>  
		</Layout>
	</Appender>
	<EM_Appender name="EM_Appender">
		<Layout type="PatternLayout">
		<Pattern>%d{dd MMM yyyy HH:mm:ss,SSS} %-5p [%c{1}:%L:%t] %m%n</Pattern>  
		</Layout>
	</EM_Appender>
</Appenders>
 
<Loggers>
	<Logger name="com.hp.im.dp" level="trace" additivity="false">
	<AppenderRef ref="File"/>
	</Logger>

	<Root level="trace">
	<AppenderRef ref="File"/>
	<AppenderRef ref="EM_Appender"/>
	</Root>
</Loggers>
 
</Configuration>


  was:
Can anyone please explain how to configure a custom appender..?
here is my code it did not work..

@Plugin(name = "EM_Appender", category = "Core", elementType = "appender", printObject = true)
public final class EventManagerAppender extends AbstractAppender{
 
protected EventManagerAppender(String name, Filter filter, Layout<? extends Serializable>
layout,
                                 boolean ignoreExceptions)
  {
    super(name, filter, layout, ignoreExceptions);
    // TODO Auto-generated constructor stub
  }

/*    @SuppressWarnings("rawtypes")
    private EventManagerAppender(String name, Layout layout, Filter filter,
                         boolean ignoreExceptions) {

    }*/
 
  
    @PluginFactory
    public static EventManagerAppender createAppender(@PluginAttribute("name") String name,
                                              @PluginAttribute("ignoreExceptions") String
ignore,
                                              @PluginElement("Layout") Layout layout,
                                              @PluginElement("Filters") Filter filter) {
 
        boolean ignoreExceptions = Boolean.parseBoolean(ignore);
        if (name == null) {
            return null;
        }
 
        if (layout == null) {
            layout = PatternLayout.createLayout(null, null, null, null, ignore, ignore);
        }
        return new EventManagerAppender(name, filter,layout, ignoreExceptions);
    }
    
    /**
     * The append method starts a job to send a message to the default console.
     */
     public void append(LogEvent event) {

        System.out.println(event.getMessage());
        System.out.println("Custome appender");
    }
}

XML configuration
**********************
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" strict="true" name="XMLConfigTest"
               packages="org.apache.logging.log4j.test,com.mycompany.abc.def.log.wrapper"
monitorInterval="30">
<Properties>
	<Property name="filename">C:/Logs/test1.log</Property>
</Properties>
<Filter type="ThresholdFilter" level="warn"/>
 
<Appenders>
	<Appender type="File" name="File" fileName="${filename}">
		<Layout type="PatternLayout">
		<Pattern>%d{dd MMM yyyy HH:mm:ss,SSS} %-5p [%c{1}:%L:%t] %m%n</Pattern>  
		</Layout>
	</Appender>
	<EM_Appender name="EventManager_Appender">
		<Layout type="PatternLayout">
		<Pattern>%d{dd MMM yyyy HH:mm:ss,SSS} %-5p [%c{1}:%L:%t] %m%n</Pattern>  
		</Layout>
	</EM_Appender>
</Appenders>
 
<Loggers>
	<Logger name="com.hp.im.dp" level="trace" additivity="false">
	<AppenderRef ref="File"/>
	</Logger>

	<Root level="trace">
	<AppenderRef ref="File"/>
	<AppenderRef ref="EM_Appender"/>
	</Root>
</Loggers>
 
</Configuration>



> Custom appender configuration help.
> -----------------------------------
>
>                 Key: LOG4J2-561
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-561
>             Project: Log4j 2
>          Issue Type: Test
>          Components: Appenders
>    Affects Versions: 2.0-rc1
>         Environment: Java
>            Reporter: vibin
>              Labels: appender, custom, customappender
>             Fix For: 2.0-rc1
>
>
> Can anyone please explain how to configure a custom appender..?
> here is my code it did not work..
> @Plugin(name = "EM_Appender", category = "Core", elementType = "appender", printObject
= true)
> public final class EventManagerAppender extends AbstractAppender{
>  
> protected EventManagerAppender(String name, Filter filter, Layout<? extends Serializable>
layout,
>                                  boolean ignoreExceptions)
>   {
>     super(name, filter, layout, ignoreExceptions);
>     // TODO Auto-generated constructor stub
>   }
> /*    @SuppressWarnings("rawtypes")
>     private EventManagerAppender(String name, Layout layout, Filter filter,
>                          boolean ignoreExceptions) {
>     }*/
>  
>   
>     @PluginFactory
>     public static EventManagerAppender createAppender(@PluginAttribute("name") String
name,
>                                               @PluginAttribute("ignoreExceptions") String
ignore,
>                                               @PluginElement("Layout") Layout layout,
>                                               @PluginElement("Filters") Filter filter)
{
>  
>         boolean ignoreExceptions = Boolean.parseBoolean(ignore);
>         if (name == null) {
>             return null;
>         }
>  
>         if (layout == null) {
>             layout = PatternLayout.createLayout(null, null, null, null, ignore, ignore);
>         }
>         return new EventManagerAppender(name, filter,layout, ignoreExceptions);
>     }
>     
>     /**
>      * The append method starts a job to send a message to the default console.
>      */
>      public void append(LogEvent event) {
>         System.out.println(event.getMessage());
>         System.out.println("Custome appender");
>     }
> }
> XML configuration
> **********************
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration status="warn" strict="true" name="XMLConfigTest"
>                packages="org.apache.logging.log4j.test,com.mycompany.abc.def.log.wrapper"
monitorInterval="30">
> <Properties>
> 	<Property name="filename">C:/Logs/test1.log</Property>
> </Properties>
> <Filter type="ThresholdFilter" level="warn"/>
>  
> <Appenders>
> 	<Appender type="File" name="File" fileName="${filename}">
> 		<Layout type="PatternLayout">
> 		<Pattern>%d{dd MMM yyyy HH:mm:ss,SSS} %-5p [%c{1}:%L:%t] %m%n</Pattern>
 
> 		</Layout>
> 	</Appender>
> 	<EM_Appender name="EM_Appender">
> 		<Layout type="PatternLayout">
> 		<Pattern>%d{dd MMM yyyy HH:mm:ss,SSS} %-5p [%c{1}:%L:%t] %m%n</Pattern>
 
> 		</Layout>
> 	</EM_Appender>
> </Appenders>
>  
> <Loggers>
> 	<Logger name="com.hp.im.dp" level="trace" additivity="false">
> 	<AppenderRef ref="File"/>
> 	</Logger>
> 	<Root level="trace">
> 	<AppenderRef ref="File"/>
> 	<AppenderRef ref="EM_Appender"/>
> 	</Root>
> </Loggers>
>  
> </Configuration>



--
This message was sent by Atlassian JIRA
(v6.2#6252)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message