List of usage examples for org.apache.commons.logging Log debug
void debug(Object message, Throwable t);
From source file:net.sf.nmedit.nordmodular.Installer.java
private void loadLastSession() { TempDir tmpDir = TempDir.forObject(this); File sessionFile = getSessionFile(tmpDir); if (!sessionFile.exists()) return;/* w w w . ja va 2 s. com*/ Properties props = new Properties(); InputStream in; try { in = new BufferedInputStream(new FileInputStream(sessionFile)); try { props.load(in); } finally { in.close(); } } catch (Exception e) { Log log = LogFactory.getLog(getClass()); if (log.isDebugEnabled()) { log.debug("exception while loading session file", e); } e.printStackTrace(); // ignore // delete corrupt session file sessionFile.delete(); return; } loadSessionFromProperties(tmpDir, props); }
From source file:com.jaspersoft.jasperserver.api.logging.access.service.impl.AccessServiceImpl.java
public List<AccessEvent> getAllEvents(int firstResult, int maxResults) { DetachedCriteria criteria = DetachedCriteria .forClass(persistentClassFactory.getImplementationClass(AccessEvent.class)); criteria.addOrder(Order.asc("eventDate")); List results = getHibernateTemplate().findByCriteria(criteria, firstResult, maxResults); if (results != null && !results.isEmpty()) { List<AccessEvent> clientEventsList = new ArrayList<AccessEvent>(results.size()); Log logger = LogFactory.getLog(COMMAND_OUT_LOGGER); for (Object event : results) { try { AccessEvent accessEvent = (AccessEvent) ((IdedObject) event).toClient(clientClassFactory); clientEventsList.add(accessEvent); } catch (AccessEventImpl.TranslateException aex) { logger.debug( "Unable to translate access event: resource = " + aex.getResource().getClass() + ", factory = " + aex.getResourceFactory().getClass(), aex.getOriginalException()); } catch (Exception ex) { logger.debug("Unable to translate access event", ex); }/*from ww w. ja v a 2s .c o m*/ } return clientEventsList; } else { return Collections.emptyList(); } }
From source file:net.sf.nmedit.nordmodular.Installer.java
private void saveCurrentSession() { DefaultDocumentManager dm = Nomad.sharedInstance().getDocumentManager(); List<NMPatch> patches = new ArrayList<NMPatch>(); for (Document doc : dm.getDocuments()) { if (doc instanceof PatchDocument) { patches.add(((PatchDocument) doc).getPatch()); }/* w w w. ja v a2 s. c o m*/ } TempDir tmpDir = TempDir.forObject(this); Properties props = new Properties(); int pcount = 0; for (NMPatch patch : patches) { File saveAs = getPatchTmpFile(tmpDir, pcount); try { OutputStream out = new BufferedOutputStream(new FileOutputStream(saveAs)); PatchFileWriter pfw = new PatchFileWriter(out); PatchExporter export = new PatchExporter(); export.export(patch, pfw); out.flush(); out.close(); } catch (Exception e) { Log log = LogFactory.getLog(getClass()); if (log.isDebugEnabled()) { log.debug("exception while storing session file", e); } e.printStackTrace(); continue; } // tmp file written File sourceFile = patch.getFile(); if (sourceFile != null) props.put(getSourceFileKey(pcount), sourceFile.getAbsolutePath()); else { // source file unknown, since patch file contains no title we have to remember it String name = patch.getName(); if (name != null) props.put(getTitleKey(pcount), name); } pcount++; } props.put(SESSION_PATCHCOUNT, String.valueOf(pcount)); File sessionFile = getSessionFile(tmpDir); try { OutputStream out = new BufferedOutputStream(new FileOutputStream(sessionFile)); props.store(out, "generated file - do not edit manually"); out.close(); } catch (Exception e) { Log log = LogFactory.getLog(getClass()); if (log.isDebugEnabled()) { log.debug("exception while storing session file", e); } e.printStackTrace(); // ignore } }
From source file:ductive.log.JDKToCommonsHandler.java
@Override public void publish(LogRecord record) { String name = record.getLoggerName(); Log log = logs.get(name); if (log == null) logs.put(name, log = LogFactory.getLog(name)); String message = record.getMessage(); Throwable ex = record.getThrown(); Level level = record.getLevel(); if (Level.SEVERE == level) log.error(message, ex);/*from w w w . ja v a 2s . co m*/ else if (Level.WARNING == level) log.warn(message, ex); else if (Level.INFO == level) log.info(message, ex); else if (Level.CONFIG == level) log.debug(message, ex); else log.trace(message, ex); }
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. * /*w w w .ja va 2s . com*/ * @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:com.healthmarketscience.rmiio.RemoteRetry.java
/** * Implementation of the actual retry logic. Calls the call() method of the * given Caller, returning results. All Throwables will be caught and * shouldRetry() will be queried to see if the call should be reattempted. * Iff shouldRetry() returns <code>true</code>, backoff() is called in order * to allow the other end of the connection to have a breather and then the * call() is reattempted (and the cycle repeats). Otherwise, the original * Throwable is thrown to the caller./*from ww w. ja va 2 s . co m*/ * * @param caller * implementation of the actual remote method call */ protected final <RetType> RetType callImpl(Caller<RetType> caller, Log log) throws Throwable { int numTries = 0; do { try { // attempt actual remote call return caller.call(); } catch (Throwable e) { // keep track of number of retries ++numTries; // determine if caller wants to retry if (!shouldRetry(e, numTries)) { // guess not... log.warn("Retry for caller " + caller + " giving up!"); throw e; } if (log.isDebugEnabled()) { log.debug("Caller " + caller + " got exception, retrying", e); } // wait for a bit before retrying backOff(numTries, log); } } while (true); }
From source file:com.microsoft.tfs.client.common.framework.command.TeamExplorerLogCommandFinishedCallback.java
@Override public void onCommandFinished(final ICommand command, IStatus status) { /*/* www.j a v a 2 s . c o m*/ * 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:com.ayovel.nian.exception.XLog.java
private void log(Level level, int loggerMask, String msgTemplate, Object... params) { loggerMask |= STD;/*from w ww . j av a 2 s . c om*/ if (isEnabled(level, loggerMask)) { String prefix = getMsgPrefix() != null ? getMsgPrefix() : Info.get().getPrefix(); prefix = (prefix != null && prefix.length() > 0) ? prefix + " " : ""; String msg = prefix + format(msgTemplate, params); Throwable throwable = getCause(params); for (int i = 0; i < LOGGER_MASKS.length; i++) { if (isEnabled(level, loggerMask & LOGGER_MASKS[i])) { Log log = loggers[i]; switch (level) { case FATAL: log.fatal(msg, throwable); break; case ERROR: log.error(msg, throwable); break; case INFO: log.info(msg, throwable); break; case WARN: log.warn(msg, throwable); break; case DEBUG: log.debug(msg, throwable); break; case TRACE: log.trace(msg, throwable); break; } } } } }
From source file:name.livitski.tools.springlet.Launcher.java
/** * Configures the manager using command-line arguments. * The arguments are checked in their command line sequence. * If an argument begins with {@link Command#COMMAND_PREFIX}, * its part that follows it is treated as a (long) command's name. * If an argument begins with {@link Command#SWITCH_PREFIX}, * the following character(s) are treated as a switch. * The name or switch extracted this way, prepended with * a bean name prefix for a {@link #BEAN_NAME_PREFIX_COMMAND command} * or a {@link #BEAN_NAME_PREFIX_SWITCH switch}, becomes the name * of a bean to look up in the framework's * {@link #MAIN_BEAN_CONFIG_FILE configuration file(s)}. * The bean that handles a command must extend the * {@link Command} class. Once a suitable bean is found, * it is called to act upon the command or switch and process * any additional arguments associated with it. * If no bean can be found or the argument is not prefixed * properly, it is considered unclaimed. You may configure a * special subclass of {@link Command} to process such arguments * by placing a bean named {@link #BEAN_NAME_DEFAULT_HANDLER} on * the configuration. If there is no such bean configured, or when * any {@link Command} bean throws an exception while processing * a command, a command line error is reported and the application * quits./* w ww .jav a 2s . c o m*/ * @param args the command line * @return this manager object */ public Launcher withArguments(String[] args) { configureDefaultLogging(); final Log log = log(); ListIterator<String> iargs = Arrays.asList(args).listIterator(); while (iargs.hasNext()) { String arg = iargs.next(); String prefix = null; String beanPrefix = null; Command cmd = null; if (arg.startsWith(Command.COMMAND_PREFIX)) prefix = Command.COMMAND_PREFIX; else if (arg.startsWith(Command.SWITCH_PREFIX)) prefix = Command.SWITCH_PREFIX; if (null != prefix) { arg = arg.substring(prefix.length()); beanPrefix = Command.SWITCH_PREFIX == prefix ? BEAN_NAME_PREFIX_SWITCH : BEAN_NAME_PREFIX_COMMAND; try { cmd = getBeanFactory().getBean(beanPrefix + arg, Command.class); } catch (NoSuchBeanDefinitionException noBean) { log.debug("Could not find a handler for command-line argument " + prefix + arg, noBean); } } if (null == cmd) { iargs.previous(); try { cmd = getBeanFactory().getBean(BEAN_NAME_DEFAULT_HANDLER, Command.class); } catch (RuntimeException ex) { log.error("Unknown command line argument: " + (null != prefix ? prefix : "") + arg, ex); status = STATUS_COMMAND_PARSING_FAILURE; break; } } try { cmd.process(iargs); } catch (SkipApplicationRunRequest skip) { if (log.isTraceEnabled()) log.trace("Handler for argument " + (null != prefix ? prefix : "") + arg + " requested to skip the application run", skip); status = STATUS_RUN_SKIPPED; break; } catch (RuntimeException err) { log.error("Invalid command line argument(s) near " + (null != prefix ? prefix : "") + arg + ": " + err.getMessage(), err); status = STATUS_COMMAND_PARSING_FAILURE; break; } catch (ApplicationBeanException err) { log.error("Error processing command line argument " + (null != prefix ? prefix : "") + arg + ": " + err.getMessage(), err); try { err.updateBeanStatus(); } catch (RuntimeException noStatus) { final ApplicationBean appBean = err.getApplicationBean(); log.warn("Could not obtain status code" + (null != appBean ? " from " + appBean : ""), noStatus); status = STATUS_INTERNAL_ERROR; } break; } } return this; }
From source file:javadz.beanutils.MethodUtils.java
/** * Try to make the method accessible/*from www .ja v a 2s. co m*/ * @param method The source arguments */ private static void setMethodAccessible(Method method) { try { // // XXX Default access superclass workaround // // When a public class has a default access superclass // with public methods, these methods are accessible. // Calling them from compiled code works fine. // // Unfortunately, using reflection to invoke these methods // seems to (wrongly) to prevent access even when the method // modifer is public. // // The following workaround solves the problem but will only // work from sufficiently privilages code. // // Better workarounds would be greatfully accepted. // if (!method.isAccessible()) { method.setAccessible(true); } } catch (SecurityException se) { // log but continue just in case the method.invoke works anyway Log log = LogFactory.getLog(MethodUtils.class); if (!loggedAccessibleWarning) { boolean vulnerableJVM = false; try { String specVersion = System.getProperty("java.specification.version"); if (specVersion.charAt(0) == '1' && (specVersion.charAt(2) == '0' || specVersion.charAt(2) == '1' || specVersion.charAt(2) == '2' || specVersion.charAt(2) == '3')) { vulnerableJVM = true; } } catch (SecurityException e) { // don't know - so display warning vulnerableJVM = true; } if (vulnerableJVM) { log.warn("Current Security Manager restricts use of workarounds for reflection bugs " + " in pre-1.4 JVMs."); } loggedAccessibleWarning = true; } log.debug("Cannot setAccessible on method. Therefore cannot use jvm access bug workaround.", se); } }