package logging.ex02c_theDifferentLevels;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import madkit.kernel.Agent;
import madkit.kernel.AgentLogger;
public class TheDifferentLevels extends Agent {
private static List<Level> levels = Arrays.asList(Level.ALL, Level.FINEST, Level.FINER, Level.FINE, Level.CONFIG, Level.INFO, Level.WARNING, Level.SEVERE, Level.OFF);
@Override
protected void activate() {
pause(2000);
}
@Override
protected void live() {
getLogger().talk("\n\t************************************\n" + "\t The different levels of display\n" + "\t************************************\n\n");
pause(1000);
getLogger().talk("\n\nLog level = " + getLogger().getLevel() + " (default Level)\n");
getLogger().severe("Default log level = " + getLogger().getLevel());
getLogger().warning("Default log level = " + getLogger().getLevel());
getLogger().info("Default log level = " + getLogger().getLevel());
getLogger().config("Default log level = " + getLogger().getLevel());
getLogger().fine("Default log level = " + getLogger().getLevel());
getLogger().finer("Default log level = " + getLogger().getLevel());
getLogger().finest("Default log level = " + getLogger().getLevel());
pause(2000);
int i = 10;
for (Level l : levels) {
getLogger().talk("\n\nLog level --> " + l + "\n");
getLogger().setLevel(l);
getLogger().severe("severe message");
getLogger().warning("warning message");
getLogger().info("info message");
getLogger().config("config message");
getLogger().fine("fine message");
getLogger().finer("finer message");
getLogger().finest("finest message");
pause(1000 * (i--));
}
if (getLogger().getLevel() == Level.OFF) {
System.out.println("This message is displayed thanks to System.out.println()\n" + "In fact with the log level OFF neither is displayed.\n");
pause(2000);
}
getLogger().setLevel(Level.INFO);
getLogger().talk("\nThe loggger is set back to " + getLogger().getLevel() + "\n\n\n");
pause(1000);
}
@Override
protected void end() {
getLogger().info("Bye bye !");
pause(5000);
}
public static void main(String[] args) {
executeThisAgent();
}
}