Java Code Examples for java.util.logging.Handler#setFilter()

The following examples show how to use java.util.logging.Handler#setFilter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PHPTestBase.java    From netbeans with Apache License 2.0 7 votes vote down vote up
private static void suppressUselessLogging() {
    for (Handler handler : Logger.getLogger("").getHandlers()) {
        handler.setFilter(new Filter() {

            @Override
            public boolean isLoggable(LogRecord record) {
                boolean result = true;
                if (record.getSourceClassName().startsWith("org.netbeans.modules.parsing.impl.indexing.LogContext")
                        || record.getSourceClassName().startsWith("org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater")
                        || record.getSourceClassName().startsWith("org.netbeans.modules.editor.settings.storage.keybindings.KeyMapsStorage")
                        || record.getSourceClassName().startsWith("org.netbeans.modules.settings.RecognizeInstanceObjects$OverObjects")) { //NOI18N
                    result = false;
                }
                return result;
            }
        });
    }
}
 
Example 2
Source File: LatteTestBase.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void suppressUselessLogging() {
    for (Handler handler : Logger.getLogger("").getHandlers()) {
        handler.setFilter(new Filter() {

            @Override
            public boolean isLoggable(LogRecord record) {
                boolean result = true;
                if (record.getSourceClassName().startsWith("org.netbeans.modules.parsing.impl.indexing.LogContext")
                        || record.getSourceClassName().startsWith("org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater")
                        || record.getSourceClassName().startsWith("org.netbeans.modules.editor.settings.storage.keybindings.KeyMapsStorage")) { //NOI18N
                    result = false;
                }
                return result;
            }
        });
    }
}
 
Example 3
Source File: RefactoringTestBase.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void suppressUselessLogging() {
    for (Handler handler : Logger.getLogger("").getHandlers()) {
        handler.setFilter(new Filter() {

            @Override
            public boolean isLoggable(LogRecord record) {
                boolean result = true;
                if (record.getSourceClassName().startsWith("org.netbeans.modules.parsing.impl.indexing.LogContext")
                        || record.getSourceClassName().startsWith("org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater")
                        || record.getSourceClassName().startsWith("org.netbeans.modules.editor.settings.storage.keybindings.KeyMapsStorage")) { //NOI18N
                    result = false;
                }
                return result;
            }
        });
    }
}
 
Example 4
Source File: TwigTestBase.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void suppressUselessLogging() {
    for (Handler handler : Logger.getLogger("").getHandlers()) {
        handler.setFilter(new Filter() {

            @Override
            public boolean isLoggable(LogRecord record) {
                boolean result = true;
                if (record.getSourceClassName().startsWith("org.netbeans.modules.parsing.impl.indexing.LogContext")
                        || record.getSourceClassName().startsWith("org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater")
                        || record.getSourceClassName().startsWith("org.netbeans.modules.editor.settings.storage.keybindings.KeyMapsStorage")) { //NOI18N
                    result = false;
                }
                return result;
            }
        });
    }
}
 
Example 5
Source File: ShellBase.java    From kalang with MIT License 6 votes vote down vote up
private void setLogLevel(Level logLevel) {
    Logger rootLogger = LogManager.getLogManager().getLogger("");
    int oldLevel = rootLogger.getLevel().intValue();
    int newLevel = logLevel.intValue();
    rootLogger.setLevel(logLevel);
    for (Handler h : rootLogger.getHandlers()) {
        h.setFilter(record -> {
            int lv = record.getLevel().intValue();
            if (lv > oldLevel) {
                return true;
            }
            String ln = record.getLoggerName();
            return  ln != null && ln.startsWith("kalang.compiler") && lv > newLevel;
        });
        h.setLevel(logLevel);
    }
}
 
Example 6
Source File: Util.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Disable logging of logging messages from DatabaseUILogger. See #215375.
 *
 * Usefulness of the whole logger seems to be doubtful
 */
public static void suppressSuperfluousLogging() {
    for (Handler h : Logger.getLogger("").getHandlers()) {
        h.setFilter(new Filter() {
            @Override
            public boolean isLoggable(LogRecord lr) {
                if (lr.getSourceClassName().equals("org.netbeans.modules.db.explorer.DatabaseUILogger")
                        || lr.getSourceClassName().startsWith("org.netbeans.modules.settings.RecognizeInstanceObjects")) {
                    return false;
                } else if (lr.getSourceClassName().equals(
                        "org.netbeans.api.db.sql.support.SQLIdentifiers$DatabaseMetaDataQuoter")) {
                    if (lr.getSourceMethodName().equals("getExtraNameChars")
                            && lr.getLevel() == Level.WARNING
                            && lr.getMessage().startsWith(
                                    "DatabaseMetaData.getExtraNameCharacters() failed")) {
                        return false;
                    } else if (lr.getSourceMethodName().equals("needToQuote")
                            && lr.getLevel().intValue()
                            <= Level.INFO.intValue()) {
                        return false;
                    } else {
                        return true;
                    }
                } else if (lr.getSourceClassName().equals(
                        "org.netbeans.modules.db.explorer.DatabaseConnection") &&
                        lr.getSourceMethodName().equals("doConnect")) {
                    return false;
                } else {
                    return true;
                }
            }
        });
    }
}
 
Example 7
Source File: DBTestUtil.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Disable logging of logging messages from DatabaseMetaDataQuoter.
 *
 * This method is a workaround of problems in the database modules and can
 * be removed, when the problem is really fixed.
 *
 */
public static void suppressSuperfluousLogging() {
    // TODO: Remove this code and fix the core problem
    for (Handler h : Logger.getLogger("").getHandlers()) {
        h.setFilter(new Filter() {
            @Override
            public boolean isLoggable(LogRecord lr) {
                if (lr.getSourceClassName().equals(
                        "org.netbeans.api.db.sql.support.SQLIdentifiers$DatabaseMetaDataQuoter")) {
                    if (lr.getSourceMethodName().equals("getExtraNameChars")
                            && lr.getLevel() == Level.WARNING
                            && lr.getMessage().startsWith(
                            "DatabaseMetaData.getExtraNameCharacters() failed")) {
                        return false;
                    } else if (lr.getSourceMethodName().equals("needToQuote")
                            && lr.getLevel().intValue() <= Level.INFO.intValue()) {
                        return false;
                    } else {
                        return true;
                    }
                } else {
                    return true;
                }
            }
        });
    }
}
 
Example 8
Source File: LoggingExample.java    From journaldev with MIT License 5 votes vote down vote up
public static void main(String[] args) {
    try {
        LogManager.getLogManager().readConfiguration(new FileInputStream("mylogging.properties"));
    } catch (SecurityException | IOException e1) {
        e1.printStackTrace();
    }
    logger.setLevel(Level.FINE);
    logger.addHandler(new ConsoleHandler());
    //adding custom handler
    logger.addHandler(new MyHandler());
    try {
        //FileHandler file name with max size and number of log files limit
        Handler fileHandler = new FileHandler("/Users/pankaj/tmp/logger.log", 2000, 5);
        fileHandler.setFormatter(new MyFormatter());
        //setting custom filter for FileHandler
        fileHandler.setFilter(new MyFilter());
        logger.addHandler(fileHandler);
        
        for(int i=0; i<1000; i++){
            //logging messages
            logger.log(Level.INFO, "Msg"+i);
        }
        logger.log(Level.CONFIG, "Config data");
    } catch (SecurityException | IOException e) {
        e.printStackTrace();
    }
}