List of usage examples for org.apache.commons.logging Log isWarnEnabled
boolean isWarnEnabled();
From source file:fr.gouv.vitam.utils.logging.CommonsLoggerFactory.java
@Override protected VitamLogLevel getLevelSpecific() { final Log logger = LogFactory.getFactory().getInstance("foo"); if (logger.isTraceEnabled()) { return VitamLogLevel.TRACE; } else if (logger.isDebugEnabled()) { return VitamLogLevel.DEBUG; } else if (logger.isInfoEnabled()) { return VitamLogLevel.INFO; } else if (logger.isWarnEnabled()) { return VitamLogLevel.WARN; } else if (logger.isErrorEnabled()) { return VitamLogLevel.ERROR; }//from w ww.jav a 2 s .c o m return null; }
From source file:com.sos.i18n.logging.commons.CommonsLogMsg.java
/** * Logs the given message to the log at the warn level. If the log level is not enabled, this method does * nothing and returns <code>null</code>. If a message was logged, its {@link Msg} will be returned. * * <p>The given Throwable will be passed to the logger so its stack can be dumped when appropriate.</p> * * @param log the log where the messages will go * @param throwable the throwable associated with the log message * @param basename the base name of the resource bundle * @param locale the locale to determine what bundle to use * @param key the resource bundle key name * @param varargs arguments to help fill in the resource bundle message * * @return if the message was logged, a non-<code>null</code> Msg object is returned *//*from w ww. j av a 2s .co m*/ public static Msg warn(Log log, Throwable throwable, BundleBaseName basename, Locale locale, String key, Object... varargs) { if (log.isWarnEnabled()) { Msg msg = Msg.createMsg(basename, locale, key, varargs); logWarnWithThrowable(log, key, msg, throwable); return msg; } return null; }
From source file:com.siblinks.ws.common.BaseException.java
public void log(final Log log) { if (errorLevel.equals(ErrorLevel.INFO) && log.isDebugEnabled()) { log.debug("Info Message: ID - " + uniqueID + " User Message: " + userMessageKey); log.debug(StackTracer.getStackTrace(throwable)); } else if (errorLevel.equals(ErrorLevel.WARNING) && log.isWarnEnabled()) { log.warn("Warn Message: ID - " + uniqueID + " User Message: " + userMessageKey); log.warn(StackTracer.getStackTrace(throwable)); } else if (errorLevel.equals(ErrorLevel.ERROR) && log.isErrorEnabled()) { log.error("Error Message: ID - " + uniqueID + " User Message: " + userMessageKey); log.error(StackTracer.getStackTrace(throwable)); } else if (errorLevel.equals(ErrorLevel.FATAL) && log.isFatalEnabled()) { log.fatal("Fatal Message: ID - " + uniqueID + " User Message: " + userMessageKey); log.fatal(StackTracer.getStackTrace(throwable)); }/*from ww w .j a v a 2 s . c om*/ logged = true; }
From source file:com.microsoft.tfs.client.common.framework.command.TeamExplorerLogCommandFinishedCallback.java
@Override public void onCommandFinished(final ICommand command, IStatus status) { /*//from ww w.ja va 2s . c om * Team Explorer ("private") logging. Map IStatus severity to commons * logging severity iff the severity is greater than the configured * tfsLogMinimumSeverity. */ if (status.getSeverity() >= minimumSeverity) { /* * UncaughtCommandExceptionStatus is a TeamExplorerStatus, which * does a silly trick: it makes the exception it was given * accessible only through a non-standard method. This helps when * displaying the status to the user in a dialog, but prevents the * platform logger from logging stack traces, so fix it up here. * * The right long term fix is to ditch TeamExplorerStatus entirely. */ if (status instanceof TeamExplorerStatus) { status = ((TeamExplorerStatus) status).toNormalStatus(); } /* * Don't have a static Log for this class, because then the errors * show up as coming from this class, which is not correct. Instead, * get the logger for the class the errors originated from. Note * that this is not a particularly expensive operation - it looks up * the classname in a hashmap. This should be more than suitable for * a command finished error handler. */ final Log log = LogFactory.getLog(CommandHelpers.unwrapCommand(command).getClass()); if (status.getSeverity() == IStatus.ERROR && log.isErrorEnabled()) { log.error(CommandFinishedCallbackHelpers.getMessageForStatus(status), status.getException()); } else if (status.getSeverity() == IStatus.WARNING && log.isWarnEnabled()) { log.error(CommandFinishedCallbackHelpers.getMessageForStatus(status), status.getException()); } else if (status.getSeverity() == IStatus.INFO && log.isInfoEnabled()) { log.info(CommandFinishedCallbackHelpers.getMessageForStatus(status), status.getException()); } else if (status.getSeverity() == IStatus.CANCEL && log.isInfoEnabled()) { log.info(CommandFinishedCallbackHelpers.getMessageForStatus(status), status.getException()); } else if (status.getSeverity() != IStatus.OK && log.isDebugEnabled()) { log.debug(CommandFinishedCallbackHelpers.getMessageForStatus(status), status.getException()); } else if (log.isTraceEnabled()) { log.trace(CommandFinishedCallbackHelpers.getMessageForStatus(status), status.getException()); } } }
From source file:net.sf.nmedit.jtheme.store.DefaultStorageContext.java
private ComponentElement tryBuildComponentStore(Element moduleElement, Element element) { try {//from w w w .j a v a 2 s . com return buildComponentStore(element); } catch (JTException e) { Log log = getLogger(); if (log.isWarnEnabled()) { log.warn("could not create component store for element " + element.getName() + " (parent " + moduleElement.getAttributeValue("component-id") + ")", e); } return null; } }
From source file:net.sf.nmedit.jtheme.store.DefaultStorageContext.java
private ComponentElement buildComponentStore(Element element) throws JTException { // TODO not all elements can be handled ???? try {//from w ww. j a v a 2s . co m return createStore(element); } catch (JTException e) { // TODO find a better solution for unsupported elements if (e.getMessage().startsWith("No store for element")) { Log log = getLogger(); if (log.isWarnEnabled()) { log.warn(this, e); } return null; } throw e; } }
From source file:net.sf.nmedit.jtheme.store.DefaultStorageContext.java
private void buildCssFromString(String cssText) throws JTException { CSSOMParser cssParser = CSSUtils.getCSSOMParser(); try {//from w w w. j a v a 2 s.c o m // TODO set uri ??? //source.setURI(arg0) if (cssText == null) return; org.w3c.css.sac.InputSource source = new org.w3c.css.sac.InputSource(new StringReader(cssText)); styleSheet = cssParser.parseStyleSheet(source, null, null); } catch (NullPointerException e) { Log log = getLogger(); if (log.isWarnEnabled()) { log.warn("buildCssFromString", e); } } catch (IOException e) { Log log = getLogger(); if (log.isWarnEnabled()) { log.warn("buildCssFromString", e); } return; // throw new JTException(e); } }
From source file:com.amazon.carbonado.repo.tupl.LogEventListener.java
@Override public void notify(EventType type, String message, Object... args) { int intLevel = type.level.intValue(); Log log = mLog; if (log != null) { if (intLevel <= Level.INFO.intValue()) { if (type.category == EventType.Category.CHECKPOINT) { if (log.isDebugEnabled()) { log.debug(format(type, message, args)); }/* w w w . j av a2s. c o m*/ } else if (log.isInfoEnabled()) { log.info(format(type, message, args)); } } else if (intLevel <= Level.WARNING.intValue()) { if (log.isWarnEnabled()) { log.warn(format(type, message, args)); } } else if (intLevel <= Level.SEVERE.intValue()) { if (log.isFatalEnabled()) { log.fatal(format(type, message, args)); } } } if (intLevel > Level.WARNING.intValue() && mPanicHandler != null) { mPanicHandler.onPanic(mDatabase, type, message, args); } }
From source file:net.sf.jabb.util.ex.LoggedException.java
/** * Create a new instance, and at the same time, ensure the original exception is logged. * //from www . jav a 2 s . c o m * @param log the log utility * @param level level of the log * @param message description * @param cause the original exception. If it is of type LoggedException, * then the newly created instance is a clone of itself. */ public LoggedException(Log log, int level, String message, Throwable cause) { super(cause instanceof LoggedException ? cause.getMessage() : message, cause instanceof LoggedException ? cause.getCause() : cause); if (!(cause instanceof LoggedException)) { switch (level) { case TRACE: if (log.isTraceEnabled()) { log.trace(message, cause); } break; case DEBUG: if (log.isDebugEnabled()) { log.debug(message, cause); } break; case WARN: if (log.isWarnEnabled()) { log.warn(message, cause); } break; case FATAL: log.fatal(message, cause); break; case INFO: log.info(message, cause); break; default: log.error(message, cause); } } }
From source file:dk.statsbiblioteket.util.Logs.java
/** * Log the message and the elements to the log at the specified level. * Elements are converted to Strings and appended to the message. Arrays, * Lists and similar in the elements are expanded to a certain degree of * detail.//from www.j av a2 s .c o m * * Sample input/output: * <code>log(myLog, Level.TRACE, false, "Started test", null, * 5, new String[]{"flim", "flam"});</code> * expands to * <code>log.trace("Started test (5, (flim, flam))");</code> * * @param log the log to log to. * @param level the level to log to (e.g. TRACE, DEBUG, INFO...). * @param verbose if true, the elements are expanded more than for false. * @param error the cause of this logging. If null, no cause is logged. * @param message the message for the log. * @param elements the elements to log. */ public static void log(Log log, Level level, String message, Throwable error, boolean verbose, Object... elements) { int maxLength = verbose ? VERBOSE_MAXLENGTH : DEFAULT_MAXLENGTH; int maxDepth = verbose ? VERBOSE_MAXDEPTH : DEFAULT_MAXDEPTH; String expanded = message; if (elements != null && elements.length > 0) { expanded += expand(elements, maxLength, maxDepth); } switch (level) { case TRACE: if (!log.isTraceEnabled()) { return; } if (error == null) { log.trace(expanded); } else { log.trace(expanded, error); } break; case DEBUG: if (!log.isDebugEnabled()) { return; } if (error == null) { log.debug(expanded); } else { log.debug(expanded, error); } break; case INFO: if (!log.isInfoEnabled()) { return; } if (error == null) { log.info(expanded); } else { log.info(expanded, error); } break; case WARN: if (!log.isWarnEnabled()) { return; } if (error == null) { log.warn(expanded); } else { log.warn(expanded, error); } break; case ERROR: if (!log.isErrorEnabled()) { return; } if (error == null) { log.error(expanded); } else { log.error(expanded, error); } break; case FATAL: if (!log.isFatalEnabled()) { return; } if (error == null) { log.fatal(expanded); } else { log.fatal(expanded, error); } break; default: throw new IllegalArgumentException("The level '" + level + "' is unknown"); } }