package org.usfirst.frc4915.debuggersystem;

import java.util.HashMap;
import java.util.Map;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.Logger;

/*
 * This is a custom system that allows for easy debug logging 
 * and sorting from any system on the robot
 * 
 * TO ADD ON TO THE SYSTEM
 * Simply add or take away parts from the enum LoggerNames
 * at the top of the class file, the initializer will take care of the rest
 * 
 * setFilter(LoggerNames)
 * takes the desired LoggerNames enumerator that the user only wants
 * the debug log to process (ex. if only LoggerNames.DRIVETRAIN was to be
 * seen, the call of object.setFilter(LoggerNames.DRIVETRAIN) would be used)
 *
 * resetFilter()
 * resets the filter to allow all LoggerNames
 *
 * stopParentHandlerLoggerUse()
 * a private utility method that should only ever be called by customDebugger itself
 *
 * setFormatter()
 * a private utility method that the customDebugger uses for its initialization
 *
 * checkFilter()
 * returns an array of booleans that represent whether a LoggerNames at index i
 * is on or off
 *
 * logError(LoggerNames, String)
 * after constructing a customDebugger object, this is how to log errors from any system
 * in the robot code, specify what LoggerNames you would like the system to log it as
 * and then pass it the desired error or debug message, the error will print out in format:
 * Chosen LoggerNames: String
 *
 */

public class CustomDebugger {

	private Map<LoggerNames, Logger> loggerMap = new HashMap<>();

	/**
	 * Constructor.
	 *
	 * <p>
	 * This method:
	 * </p>
	 * <ul>
	 * <li>Fills the <code>loggerMap</code> with the loggers defined in
	 * {@link LoggerNames}.</li>
	 * <li>Calls {@link #setFormatter()} and
	 * {@link #stopParentHandlerLoggerUse()}</li>
	 * </ul>
	 */
	public CustomDebugger() {
		for (LoggerNames n : LoggerNames.values()) {
			loggerMap.put(n, Logger.getLogger(n.name()));
		}
		this.setFormatter();
		this.stopParentHandlerLoggerUse();
	}

	/**
	 *
	 * Sets the internal logger filter. This turns all loggers other than
	 * <code>logger</code> off.
	 *
	 * @param logger
	 *            Logger to filter the output of
	 */
	public void setFilter(LoggerNames logger) {
		for (Logger n : loggerMap.values()) {
			if (!n.getName().equalsIgnoreCase(logger.name())) {
				n.setLevel(Level.OFF);
			}
		}
	}

	/**
	 * Clears the filter set by {@link #setFilter}.
	 *
	 * This must be called before another filter is set.
	 */
	public void resetFilter() {
		for (Logger n : loggerMap.values()) {
			n.setLevel(Level.ALL);
		}
	}

	/**
	 * Sets the internal Java logger's <code>setUseParentHandlers</code> option
	 * to false
	 *
	 * <p>
	 * This is an important step in getting this system to even work.
	 * </p>
	 */
	private void stopParentHandlerLoggerUse() {
		for (Logger n : loggerMap.values()) {
			n.setUseParentHandlers(false);
		}
	}

	/**
	 * Gives each logger a preconfigured handler during initialization.
	 */
	private void setFormatter() {
		CustomFormatter customFormatter = new CustomFormatter();
		ConsoleHandler handler = new ConsoleHandler();

		handler.setFormatter(customFormatter);
		for (Logger n : loggerMap.values()) {
			n.addHandler(handler);
		}
	}

	/**
	 *
	 * Check the filter state of each logger
	 *
	 * @return Array representing the filter state of the Logger at index i
	 *         relative to position in {@link LoggerNames}
	 */
	public boolean[] checkFilter() {
		// returns an array of booleans showing if a logger is off or on (false
		// for off true for on)
		boolean[] output = new boolean[loggerMap.size()];
		int i = 0;
		for (Logger n : loggerMap.values()) {
			output[i] = (n.getLevel() == Level.OFF);
			i++;
		}

		return output;
	}

	/**
	 *
	 * Outputs a message to a specified logger.
	 *
	 * @param logger
	 *            Logger to throw the error with
	 * @param message
	 *            Message to send to <code>logger</code>
	 */
	public void logError(LoggerNames logger, String message) {
		loggerMap.get(logger).info(message);
	}

	/**
	 * Collection of logger names (categories)
	 */
	public static enum LoggerNames {
		DRIVETRAIN, GRABBER, GENERAL, AUTONOMOUS, ELEVATOR
	}

}

@@ -195,16 +195,17 @@
 ger;%0A%0A/*
+*
 %0A * This
@@ -315,470 +315,90 @@
 %0A * 
-TO ADD ON TO THE SYSTEM%0A * Simply add or take away parts from the enum LoggerNames%0A * at the top of the class file, the initializer will take care of the rest%0A * %0A * setFilter(LoggerNames)%0A * takes the desired LoggerNames enumerator that the user only wants%0A * the debug log to process (ex. if only LoggerNames.DRIVETRAIN was to be%0A * seen, the call of object.setFilter(LoggerNames.DRIVETRAIN) would be used)%0A *%0A * resetFilter()%0A * resets the filter to allow all
+%3Cp%3ETo add other categories to the system simply add or take away parts from %7B@link
  Log
@@ -409,686 +409,97 @@
 ames
-%0A *
+%7D
 %0A * 
-stopParentHandlerLoggerUse()%0A * a private utility method that should only ever be called by customDebugger itself%0A *%0A * setFormatter()%0A * a private utility method that the customDebugger uses for its initialization%0A *%0A * checkFilter()%0A * returns an array of booleans that represent whether a LoggerNames at index i%0A * is on or off%0A *%0A * logError(LoggerNames, String)%0A * after constructing a customDebugger object, this is how to log errors from any system%0A * in the robot code, specify what LoggerNames you would like the system to log it as%0A * and then pass it the desired error or debug message, the error will print out in format:%0A * Chosen LoggerNames: String
+at the top of the class file, the initializer will take care of the rest%3C/p%3E
 %0A *%0A */%0A
 %0Apub
@@ -494,17 +494,16 @@
 %0A *%0A */%0A
-%0A
 public c
@@ -1131,20 +1131,16 @@
 her than
-%0A%09 *
  %3Ccode%3El
@@ -1164,41 +1164,125 @@
 %0A%09 *
+ 
 %0A%09 * 
-@param logger%0A%09 *           
+%3Cp%3EYou %3Cstrong%3Emust%3C/strong%3E call %7B@link #resetFilter%7D before setting another filter.%3C/p%3E%0A%09 *%0A%09 * @param logger
  Log
@@ -1560,17 +1560,37 @@
 %09 * 
+%3Cp%3E
 This 
-must
+%3Cstrong%3Emust%3C/strong%3E
  be 
@@ -1625,16 +1625,20 @@
  is set.
+%3C/p%3E
 %0A%09 */%0A%09p
@@ -1832,16 +1832,17 @@
 to false
+.
 %0A%09 *%0A%09 *
@@ -2515,28 +2515,16 @@
  index i
-%0A%09 *        
  relativ
@@ -2886,24 +2886,25 @@
 %09%7D%0A%0A%09/**%0A%09 *
+ 
 %0A%09 * Outputs
@@ -2958,31 +2958,16 @@
 m logger
-%0A%09 *           
  Logger 
@@ -3012,23 +3012,8 @@
 sage
-%0A%09 *           
  Mes

Format debugger javadocs