[Lutinutil-commits] r1417 - lutinutil/trunk/src/main/java/org/codelutin/log
Author: chatellier Date: 2009-04-06 15:34:47 +0000 (Mon, 06 Apr 2009) New Revision: 1417 Modified: lutinutil/trunk/src/main/java/org/codelutin/log/UserLog.java Log: Comment class. Modified: lutinutil/trunk/src/main/java/org/codelutin/log/UserLog.java =================================================================== --- lutinutil/trunk/src/main/java/org/codelutin/log/UserLog.java 2009-03-30 12:13:39 UTC (rev 1416) +++ lutinutil/trunk/src/main/java/org/codelutin/log/UserLog.java 2009-04-06 15:34:47 UTC (rev 1417) @@ -1,5 +1,5 @@ /* *##% Lutin utilities library - * Copyright (C) 2004 - 2008 CodeLutin + * Copyright (C) 2004 - 2009 CodeLutin * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -17,7 +17,6 @@ package org.codelutin.log; - import java.awt.GraphicsEnvironment; import javax.swing.JOptionPane; import org.apache.commons.logging.Log; @@ -40,27 +39,37 @@ public class UserLog { /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Log log = LogFactory.getLog(UserLog.class); + private static Log log = LogFactory.getLog(UserLog.class); - static public enum Level { + public static enum Level { DEBUG, INFO, WARN, ERROR, FATAL } - + protected static ListenerSet<Object> listeners = new ListenerSet<Object>(); protected static boolean graphicUI = true; public static void addListeners(ListenerSet<Object> l) { listeners.add(l); } + public static void removeListeners(ListenerSet<Object> l) { listeners.remove(l); } - - + + /** + * Enable/disable UI log display. + * + * @param graphicUI <tt>true</tt> to enable + */ public static void setGraphicUI(boolean graphicUI) { UserLog.graphicUI = graphicUI; } + /** + * Return true if UI login is enabled and available. + * + * @return graphicUI enable + */ public static boolean isGraphicUI() { return graphicUI && !GraphicsEnvironment.isHeadless(); } @@ -72,80 +81,153 @@ * * @param level le niveau du message * @param msg le message - * @param eee l'exception s'il y en a une + * @param cause l'exception s'il y en a une */ - protected static void show(Level level, String msg, Throwable eee) { + protected static void show(Level level, String msg, Throwable cause) { try { listeners.fire("setText", msg); - } catch (Exception zzz) { - log.warn("Can't call setText on listener", zzz); + } catch (Exception e) { + log.warn("Can't call setText on listener", e); } - + if (isGraphicUI()) { String title = level.name(); int type = JOptionPane.PLAIN_MESSAGE; switch (level) { - case DEBUG: - type = JOptionPane.PLAIN_MESSAGE; - break; - case INFO: - type = JOptionPane.INFORMATION_MESSAGE; - break; - case WARN: - type = JOptionPane.WARNING_MESSAGE; - break; - case ERROR: - case FATAL: - type = JOptionPane.ERROR_MESSAGE; - break; - } + case DEBUG: + type = JOptionPane.PLAIN_MESSAGE; + break; + case INFO: + type = JOptionPane.INFORMATION_MESSAGE; + break; + case WARN: + type = JOptionPane.WARNING_MESSAGE; + break; + case ERROR: + case FATAL: + type = JOptionPane.ERROR_MESSAGE; + break; + } JOptionPane.showMessageDialog(null, msg, title, type); } } + /** + * Log message using commons-logging and display message box if UI is + * available and non disabled. + * + * @param msg message to display + */ public static void debug(String msg) { - log.debug(msg); + if (log.isDebugEnabled()) { + log.debug(msg); + } show(Level.DEBUG, msg, null); } - public static void debug(String msg, Throwable eee) { - log.debug(msg, eee); - show(Level.DEBUG, msg, eee); + + /** + * Log message using commons-logging and display message box if UI is + * available and non disabled. + * + * @param msg message to display + * @param cause exception cause + */ + public static void debug(String msg, Throwable cause) { + if (log.isDebugEnabled()) { + log.debug(msg, cause); + } + show(Level.DEBUG, msg, cause); } + /** + * Log message using commons-logging and display message box if UI is + * available and non disabled. + * + * @param msg message to display + */ public static void info(String msg) { log.info(msg); show(Level.INFO, msg, null); } - public static void info(String msg, Throwable eee) { - log.info(msg, eee); - show(Level.INFO, msg, eee); + + /** + * Log message using commons-logging and display message box if UI is + * available and non disabled. + * + * @param msg message to display + * @param cause exception cause + */ + public static void info(String msg, Throwable cause) { + log.info(msg, cause); + show(Level.INFO, msg, cause); } + /** + * Log message using commons-logging and display message box if UI is + * available and non disabled. + * + * @param msg message to display + */ public static void warn(String msg) { log.warn(msg); show(Level.WARN, msg, null); } - public static void warn(String msg, Throwable eee) { - log.warn(msg, eee); - show(Level.WARN, msg, eee); + + /** + * Log message using commons-logging and display message box if UI is + * available and non disabled. + * + * @param msg message to display + * @param cause exception cause + */ + public static void warn(String msg, Throwable cause) { + log.warn(msg, cause); + show(Level.WARN, msg, cause); } + /** + * Log message using commons-logging and display message box if UI is + * available and non disabled. + * + * @param msg message to display + */ public static void error(String msg) { log.error(msg); show(Level.ERROR, msg, null); } - public static void error(String msg, Throwable eee) { - log.error(msg, eee); - show(Level.ERROR, msg, eee); + + /** + * Log message using commons-logging and display message box if UI is + * available and non disabled. + * + * @param msg message to display + * @param cause exception cause + */ + public static void error(String msg, Throwable cause) { + log.error(msg, cause); + show(Level.ERROR, msg, cause); } + /** + * Log message using commons-logging and display message box if UI is + * available and non disabled. + * + * @param msg message to display + */ public static void fatal(String msg) { log.fatal(msg); show(Level.FATAL, msg, null); } - public static void fatal(String msg, Throwable eee) { - log.fatal(msg, eee); - show(Level.FATAL, msg, eee); + + /** + * Log message using commons-logging and display message box if UI is + * available and non disabled. + * + * @param msg message to display + * @param cause exception cause + */ + public static void fatal(String msg, Throwable cause) { + log.fatal(msg, cause); + show(Level.FATAL, msg, cause); } - } Property changes on: lutinutil/trunk/src/main/java/org/codelutin/log/UserLog.java ___________________________________________________________________ Name: svn:keywords + Revision Date Author
participants (1)
-
chatellierï¼ users.labs.libre-entreprise.org