[logback-dev] [JIRA] Commented: (LBCORE-57) FlushableAppender

Bruno Navert (JIRA) noreply-jira at qos.ch
Fri Sep 26 13:32:49 CEST 2008


    [ http://jira.qos.ch/browse/LBCORE-57?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=10735#action_10735 ] 

Bruno Navert commented on LBCORE-57:
------------------------------------

Here's example code using this: first a static utility method to retrieve all Appenders

    public static Set<Appender> getAllAppenders()
    {
        ContextSelector selector = StaticLoggerBinder.SINGLETON.getContextSelector();
        LoggerContext loggerContext = selector.getLoggerContext();

        Map<String, Appender> appenders = newHashMap();

        // loop through all Loggers
        for ( Logger logger : loggerContext.getLoggerList() )
        {
            // for each logger, loop through all its appenders
            Iterator iter = logger.iteratorForAppenders();
            while ( iter.hasNext() )
            {
                // appenders are uniquely identified by name, so store them in the Map thus
                // this will overwrite the same entry in the Map many times (with the same reference)
                Appender appender = ( Appender ) iter.next();
                appenders.put( appender.getName(), appender );
            }
        }

        return newHashSet( appenders.values() );
    }

Then code which runs once to load all flushable appenders in a list:

        for ( Appender appender : LogbackConfigurer.getAllAppenders() )
        {
            if ( appender instanceof FlushableAppender )
            {
                flushableAppenders.add( ( FlushableAppender ) appender );
            }
            else
            {
                log.debug( "appender {} is not Flushable, skipping", appender );
            }
        }

And when needed, flush:

        for ( FlushableAppender appender : flushableAppenders )
        {
            log.debug( "flushing appender {}", appender );
            appender.flush();
        }

> FlushableAppender
> -----------------
>
>                 Key: LBCORE-57
>                 URL: http://jira.qos.ch/browse/LBCORE-57
>             Project: logback-core
>          Issue Type: Improvement
>          Components: Appender
>    Affects Versions: 0.9.9
>            Reporter: Bruno Navert
>            Assignee: Logback dev list
>            Priority: Minor
>         Attachments: DirectoryCreateRollingFileAppender.java, FlushableAppender.java
>
>
> Create a FlushableAppender interface for appenders that can be manually flushed (only relevant if bufferingIO is enabled)
> Interface can simply extend Appender and java.io.Flushable

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the logback-dev mailing list