001/* Copyright (C) 2013 TU Dortmund 002 * This file is part of LearnLib, http://www.learnlib.de/. 003 * 004 * LearnLib is free software; you can redistribute it and/or 005 * modify it under the terms of the GNU Lesser General Public 006 * License version 3.0 as published by the Free Software Foundation. 007 * 008 * LearnLib is distributed in the hope that it will be useful, 009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 011 * Lesser General Public License for more details. 012 * 013 * You should have received a copy of the GNU Lesser General Public 014 * License along with LearnLib; if not, see 015 * <http://www.gnu.de/documents/lgpl.en.html>. 016 */ 017 018package de.learnlib.logging.filter; 019 020import java.util.EnumSet; 021import java.util.logging.Filter; 022import java.util.logging.LogRecord; 023 024import de.learnlib.logging.Category; 025import de.learnlib.logging.LearnLogRecord; 026 027/** 028 * Filters log messages based on categories. Non-LearnLib log records 029 * are filed under category SYSTEM. 030 * 031 * @author falkhowar 032 */ 033public class CategoryFilter implements Filter { 034 035 private final EnumSet<Category> categories; 036 037 public CategoryFilter(EnumSet<Category> categories) { 038 this.categories = categories; 039 } 040 041 @Override 042 public boolean isLoggable(LogRecord record) { 043 if (!record.getClass().getName().equals(LearnLogRecord.class.getName())) { 044 return categories.contains(Category.SYSTEM); 045 } 046 LearnLogRecord lrec = (LearnLogRecord)record; 047 return categories.contains(lrec.getCategory()); 048 } 049 050}