Updated EnvoyLogger -> still not working
This commit is contained in:
		@@ -92,7 +92,7 @@ public class Settings {
 | 
				
			|||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * updates prefs when save button is clicked
 | 
						 * updates prefs when save button is clicked
 | 
				
			||||||
	 * 
 | 
						 * 
 | 
				
			||||||
	 * @throws IOException
 | 
						 * @throws IOException if saving was not successful
 | 
				
			||||||
	 * @since Envoy v0.2-alpha
 | 
						 * @since Envoy v0.2-alpha
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public void save() throws IOException {
 | 
						public void save() throws IOException {
 | 
				
			||||||
@@ -111,7 +111,7 @@ public class Settings {
 | 
				
			|||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * adds new theme to the theme map and sets current theme to the new theme.
 | 
						 * adds new theme to the theme map and sets current theme to the new theme.
 | 
				
			||||||
	 * 
 | 
						 * 
 | 
				
			||||||
	 * @param theme
 | 
						 * @param theme the theme to add
 | 
				
			||||||
	 * @since Envoy v0.2-alpha
 | 
						 * @since Envoy v0.2-alpha
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public void addNewThemeToMap(Theme theme) {
 | 
						public void addNewThemeToMap(Theme theme) {
 | 
				
			||||||
@@ -120,7 +120,7 @@ public class Settings {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * @return {@link currentTheme}
 | 
						 * @return the name of the current theme
 | 
				
			||||||
	 * @since Envoy v0.2-alpha
 | 
						 * @since Envoy v0.2-alpha
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public String getCurrentTheme() { return currentTheme; }
 | 
						public String getCurrentTheme() { return currentTheme; }
 | 
				
			||||||
@@ -128,7 +128,7 @@ public class Settings {
 | 
				
			|||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Sets the currentTheme
 | 
						 * Sets the currentTheme
 | 
				
			||||||
	 * 
 | 
						 * 
 | 
				
			||||||
	 * @param themeName
 | 
						 * @param themeName the name of the new current theme
 | 
				
			||||||
	 * @since Envoy v0.2-alpha
 | 
						 * @since Envoy v0.2-alpha
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public void setCurrentTheme(String themeName) { currentTheme = themeName; }
 | 
						public void setCurrentTheme(String themeName) { currentTheme = themeName; }
 | 
				
			||||||
@@ -174,16 +174,16 @@ public class Settings {
 | 
				
			|||||||
	public void setEnterToSend(boolean enterToSend) { this.enterToSend = enterToSend; }
 | 
						public void setEnterToSend(boolean enterToSend) { this.enterToSend = enterToSend; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * @return {@link themes} map
 | 
						 * @return the map of all themes by name and colorContent
 | 
				
			||||||
	 * @since Envoy v0.2-alpha
 | 
						 * @since Envoy v0.2-alpha
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public Map<String, Theme> getThemes() { return themes; }
 | 
						public Map<String, Theme> getThemes() { return themes; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Sets {@link themes}
 | 
						 * @deprecated not used
 | 
				
			||||||
	 * 
 | 
						 * 
 | 
				
			||||||
	 * @param themes
 | 
						 * @param themes the the the the
 | 
				
			||||||
	 * @since Envoy v0.2-alpha
 | 
						 * @since Envoy v0.2-alpha
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public void setThemes(Map<String, Theme> themes) { this.themes = themes; }
 | 
						public void setThemes(Map<String, Theme> themes) { this.themes = themes; }// TODO delete, if there is no usage
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -3,7 +3,6 @@ package envoy.client.event;
 | 
				
			|||||||
import java.io.IOException;
 | 
					import java.io.IOException;
 | 
				
			||||||
import java.util.logging.ConsoleHandler;
 | 
					import java.util.logging.ConsoleHandler;
 | 
				
			||||||
import java.util.logging.FileHandler;
 | 
					import java.util.logging.FileHandler;
 | 
				
			||||||
import java.util.logging.Handler;
 | 
					 | 
				
			||||||
import java.util.logging.Level;
 | 
					import java.util.logging.Level;
 | 
				
			||||||
import java.util.logging.LogRecord;
 | 
					import java.util.logging.LogRecord;
 | 
				
			||||||
import java.util.logging.Logger;
 | 
					import java.util.logging.Logger;
 | 
				
			||||||
@@ -20,40 +19,24 @@ import java.util.logging.SimpleFormatter;
 | 
				
			|||||||
public class EnvoyLogger extends Logger {
 | 
					public class EnvoyLogger extends Logger {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private Logger	logger;
 | 
						private Logger	logger;
 | 
				
			||||||
	private int		fileLevel	= 800;
 | 
						private Level	fileLevelBarrier	= Level.CONFIG;
 | 
				
			||||||
 | 
					 | 
				
			||||||
	private Handler handler = new Handler() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		@Override
 | 
					 | 
				
			||||||
		public void publish(LogRecord arg0) {
 | 
					 | 
				
			||||||
			ConsoleHandler	ch;
 | 
					 | 
				
			||||||
			FileHandler		fh;
 | 
					 | 
				
			||||||
			SimpleFormatter	formatter	= new SimpleFormatter();
 | 
					 | 
				
			||||||
			if (arg0.getLevel().intValue() >= fileLevel) {// Case if level >= info
 | 
					 | 
				
			||||||
				try {
 | 
					 | 
				
			||||||
					fh = new FileHandler("Envoy_user.log");
 | 
					 | 
				
			||||||
					logger.addHandler(fh);
 | 
					 | 
				
			||||||
					formatter.formatMessage(arg0);
 | 
					 | 
				
			||||||
					fh.setFormatter(formatter);
 | 
					 | 
				
			||||||
				} catch (SecurityException | IOException e) {
 | 
					 | 
				
			||||||
					e.printStackTrace();
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			ch = new ConsoleHandler();
 | 
					 | 
				
			||||||
			logger.addHandler(ch);
 | 
					 | 
				
			||||||
			formatter.formatMessage(arg0);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		@Override
 | 
					 | 
				
			||||||
		public void flush() {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		@Override
 | 
					 | 
				
			||||||
		public void close() throws SecurityException {}
 | 
					 | 
				
			||||||
	};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public EnvoyLogger(String name) {
 | 
						public EnvoyLogger(String name) {
 | 
				
			||||||
		super(name, null);
 | 
							super(name, null);
 | 
				
			||||||
		logger.addHandler(handler);
 | 
							try {
 | 
				
			||||||
 | 
								SimpleFormatter	formatter	= new SimpleFormatter();
 | 
				
			||||||
 | 
								FileHandler		fh			= new FileHandler("envoy_user.log");
 | 
				
			||||||
 | 
								fh.setLevel(fileLevelBarrier);
 | 
				
			||||||
 | 
								fh.setFormatter(formatter);
 | 
				
			||||||
 | 
								ConsoleHandler ch = new ConsoleHandler();
 | 
				
			||||||
 | 
								ch.setLevel(Level.FINEST);
 | 
				
			||||||
 | 
								ch.setFormatter(formatter);
 | 
				
			||||||
 | 
								logger.addHandler(fh);
 | 
				
			||||||
 | 
								logger.addHandler(ch);
 | 
				
			||||||
 | 
							} catch (IOException | SecurityException e) {
 | 
				
			||||||
 | 
								e.printStackTrace();
 | 
				
			||||||
 | 
								this.log(Level.FINE, "Ironically, the logger encountered an error while initialising. That certainly needs to be logged :)");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
@@ -84,20 +67,17 @@ public class EnvoyLogger extends Logger {
 | 
				
			|||||||
	public void log(LogRecord logRecord) { logger.log(logRecord); }
 | 
						public void log(LogRecord logRecord) { logger.log(logRecord); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * @return the fileLevel: The current barrier for writing logs to a file. It can
 | 
						 * @return the fileLevelBarrier: The current barrier for writing logs to a file.
 | 
				
			||||||
	 *         range from 100-1000 in steps of one hundred with 1000 being
 | 
					 | 
				
			||||||
	 *         Level.SEVERE
 | 
					 | 
				
			||||||
	 * @since Envoy v0.2-alpha
 | 
						 * @since Envoy v0.2-alpha
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public int getFileLevel() { return fileLevel; }
 | 
						public Level getFileLevelBarrier() { return fileLevelBarrier; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * @param fileLevel the severity above which on logRecords will be written in a
 | 
						 * @param fileLevelBarrier the severity below which logRecords will be written
 | 
				
			||||||
	 *                  file instead of the console
 | 
						 *                         only to the console. At or above they'll also be
 | 
				
			||||||
 | 
						 *                         logged in a file. Can be written either in Digits
 | 
				
			||||||
 | 
						 *                         from 0 - 1000 or with the according name of the level
 | 
				
			||||||
	 * @since Envoy v0.2-alpha
 | 
						 * @since Envoy v0.2-alpha
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public void setFileLevel(int fileLevel) {
 | 
						public void setFileLevel(String fileLevelBarrier) { this.fileLevelBarrier = Level.parse(fileLevelBarrier); }
 | 
				
			||||||
		if (fileLevel <= 10) fileLevel *= 100;
 | 
					 | 
				
			||||||
		this.fileLevel = fileLevel;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -245,11 +245,11 @@ public class ChatWindow extends JFrame {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Used to immediately reload the ChatWindow when settings were changed.
 | 
						 * Used to immediately reload the ChatWindow when settings were changed.
 | 
				
			||||||
	 * 
 | 
						 * @param themeName the name of the theme to change the colors into
 | 
				
			||||||
	 * @since Envoy v0.1-alpha
 | 
						 * @since Envoy v0.1-alpha
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public void changeChatWindowColors(String key) {
 | 
						public void changeChatWindowColors(String themeName) {
 | 
				
			||||||
		Theme theme = Settings.getInstance().getThemes().get(key);
 | 
							Theme theme = Settings.getInstance().getThemes().get(themeName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// contentPane
 | 
							// contentPane
 | 
				
			||||||
		contentPane.setBackground(theme.getBackgroundColor());
 | 
							contentPane.setBackground(theme.getBackgroundColor());
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user