I have a custom appender that needs a backup logger in case there is a network 
issue or some other common error (see sample code below).
I'm running into the error indicating that my backup logger will not work 
because it was created during the default configuration phase.  It directed me 
towards the docs on substituteLogger which suggested to set up my appender in a 
separate file and then configure it after the default configuration phase.
Are there any other options?

Is there a better way to deal w/ the backup logger?  Is there a more general 
purpose way to do this?  Maybe a composite appender?

Any help would be appreciated.


My class basically looks like this:

public class FooAppender extends AppenderBase<ILoggingEvent> {
                private final Logger LOGGER = 
LoggerFactory.getLogger(FooAppender.class);
private Layout<ILoggingEvent> layout;
//A bunch of configuration and constants.
//Some setter methods

@Override
Public void append(final ILoggingEvent event) {
String message = this.layout.doLayout(event); //The thrift client will encode 
it as UTF-8 for us.
                try {
                                //log the event
                } catch (SpecificException e) {
                                LOGGER.error(message);
                }
}
}

Sample logback.xml snippet:
    <appender name="foo" class="FooAppender">
        <layout>
            <pattern>%m%n</pattern>
            
<outputPatternAsPresentationHeader>false</outputPatternAsPresentationHeader>
        </layout>
<!-more configuration -->
    </appender>
    <appender name="fooBackup" class="ch.qos.logback.core.FileAppender">
<file>/tmp/logs/fooBackup.log</file>
        <encoder>
            <charset>UTF-8</charset>
            <pattern>%m</pattern>
            
<outputPatternAsPresentationHeader>false</outputPatternAsPresentationHeader>
        </encoder>
    </appender>

<logger name="FooAppenderTester" level="INFO" additivity="false">
                <appender-ref ref="foo"/>
</logger>
<logger name="FooAppender" level="INFO" additivity="false">
                <appender-ref ref="fooBackup"/>
</logger>
_______________________________________________
Logback-user mailing list
[email protected]
http://mailman.qos.ch/mailman/listinfo/logback-user

Reply via email to