List of usage examples for org.apache.commons.logging Log trace
void trace(Object message);
From source file:org.alfresco.scripts.ScriptResourceHelper.java
/** * Recursively resolve imports in the specified scripts, adding the imports to the * specific list of scriplets to combine later. * /* w w w. j a v a2 s . c o m*/ * @param location Script location - used to ensure duplicates are not added * @param script The script to recursively resolve imports for * @param scripts The collection of scriplets to execute with imports resolved and removed */ private static void recurseScriptImports(String location, String script, ScriptResourceLoader loader, Map<String, String> scripts, Log logger) { int index = 0; // skip any initial whitespace for (; index < script.length(); index++) { if (Character.isWhitespace(script.charAt(index)) == false) { break; } } // look for the "<import" directive marker if (script.startsWith(IMPORT_PREFIX, index)) { // skip whitespace between "<import" and "resource" boolean afterWhitespace = false; index += IMPORT_PREFIX.length() + 1; for (; index < script.length(); index++) { if (Character.isWhitespace(script.charAt(index)) == false) { afterWhitespace = true; break; } } if (afterWhitespace == true && script.startsWith(IMPORT_RESOURCE, index)) { // found an import line! index += IMPORT_RESOURCE.length(); int resourceStart = index; for (; index < script.length(); index++) { if (script.charAt(index) == '"' && script.charAt(index + 1) == '>') { // found end of import line - so we have a resource path String resource = script.substring(resourceStart, index); if (logger.isDebugEnabled()) logger.debug("Found script resource import: " + resource); if (scripts.containsKey(resource) == false) { // load the script resource (and parse any recursive includes...) String includedScript = loader.loadScriptResource(resource); if (includedScript != null) { if (logger.isDebugEnabled()) logger.debug("Succesfully located script '" + resource + "'"); recurseScriptImports(resource, includedScript, loader, scripts, logger); } } else { if (logger.isDebugEnabled()) logger.debug("Note: already imported resource: " + resource); } // continue scanning this script for additional includes // skip the last two characters of the import directive for (index += 2; index < script.length(); index++) { if (Character.isWhitespace(script.charAt(index)) == false) { break; } } recurseScriptImports(location, script.substring(index), loader, scripts, logger); return; } } // if we get here, we failed to find the end of an import line throw new ScriptException( "Malformed 'import' line - must be first in file, no comments and strictly of the form:" + "\r\n<import resource=\"...\">"); } else { throw new ScriptException( "Malformed 'import' line - must be first in file, no comments and strictly of the form:" + "\r\n<import resource=\"...\">"); } } else { // no (further) includes found - include the original script content if (logger.isDebugEnabled()) logger.debug("Imports resolved, adding resource '" + location); if (logger.isTraceEnabled()) logger.trace(script); scripts.put(location, script); } }
From source file:org.apache.camel.util.UnitOfWorkHelper.java
@SuppressWarnings("unchecked") public static void doneSynchronizations(Exchange exchange, List<Synchronization> synchronizations, Log log) { boolean failed = exchange.isFailed(); if (synchronizations != null && !synchronizations.isEmpty()) { // work on a copy of the list to avoid any modification which may cause ConcurrentModificationException List<Synchronization> copy = new ArrayList<Synchronization>(synchronizations); // reverse so we invoke it FILO style instead of FIFO Collections.reverse(copy); // and honor if any was ordered by sorting it accordingly Collections.sort(copy, new OrderedComparator()); // invoke synchronization callbacks for (Synchronization synchronization : copy) { try { if (failed) { if (log.isTraceEnabled()) { log.trace( "Invoking synchronization.onFailure: " + synchronization + " with " + exchange); }//from www . j ava2 s.c o m synchronization.onFailure(exchange); } else { if (log.isTraceEnabled()) { log.trace("Invoking synchronization.onComplete: " + synchronization + " with " + exchange); } synchronization.onComplete(exchange); } } catch (Throwable e) { // must catch exceptions to ensure all synchronizations have a chance to run log.warn("Exception occurred during onCompletion. This exception will be ignored.", e); } } } }
From source file:org.apache.hadoop.fs.swift.util.SwiftUtils.java
public static void trace(Log log, String text, Object... args) { if (log.isTraceEnabled()) { log.trace(String.format(text, args)); }/*from w ww. j a va 2 s. co m*/ }
From source file:org.apache.hadoop.yarn.server.resourcemanager.RMServerUtils.java
/** * Utility method to verify if the current user has access based on the * passed {@link AccessControlList}//from w ww . j a v a 2 s. co m * * @param authorizer the {@link AccessControlList} to check against * @param method the method name to be logged * @param module like AdminService or NodeLabelManager * @param LOG the logger to use * @return {@link UserGroupInformation} of the current user * @throws IOException */ public static UserGroupInformation verifyAdminAccess(YarnAuthorizationProvider authorizer, String method, String module, final Log LOG) throws IOException { UserGroupInformation user; try { user = UserGroupInformation.getCurrentUser(); } catch (IOException ioe) { LOG.warn("Couldn't get current user", ioe); RMAuditLogger.logFailure("UNKNOWN", method, "", "AdminService", "Couldn't get current user"); throw ioe; } if (!authorizer.isAdmin(user)) { LOG.warn("User " + user.getShortUserName() + " doesn't have permission" + " to call '" + method + "'"); RMAuditLogger.logFailure(user.getShortUserName(), method, "", module, RMAuditLogger.AuditConstants.UNAUTHORIZED_USER); throw new AccessControlException( "User " + user.getShortUserName() + " doesn't have permission" + " to call '" + method + "'"); } if (LOG.isTraceEnabled()) { LOG.trace(method + " invoked by user " + user.getShortUserName()); } return user; }
From source file:org.apache.poi.util.MethodUtils.java
/** * <p>Find an accessible method that matches the given name and has compatible parameters. * Compatible parameters mean that every method parameter is assignable from * the given parameters.//from w w w . j a va2 s . c o m * In other words, it finds a method with the given name * that will take the parameters given.<p> * * <p>This method is slightly undeterminstic since it loops * through methods names and return the first matching method.</p> * * <p>This method is used by * {@link * #invokeMethod(Object object,String methodName,Object [] args,Class[] parameterTypes)}. * * <p>This method can match primitive parameter by passing in wrapper classes. * For example, a <code>Boolean</code> will match a primitive <code>boolean</code> * parameter. * * @param clazz find method in this class * @param methodName find method with this name * @param parameterTypes find method with compatible parameters * @return The accessible method */ public static Method getMatchingAccessibleMethod(Class clazz, String methodName, Class[] parameterTypes) { // trace logging Log log = LogFactory.getLog(MethodUtils.class); if (log.isTraceEnabled()) { log.trace("Matching name=" + methodName + " on " + clazz); } MethodDescriptor md = new MethodDescriptor(clazz, methodName, parameterTypes, false); // see if we can find the method directly // most of the time this works and it's much faster try { Method method = clazz.getMethod(methodName, parameterTypes); if (log.isTraceEnabled()) { log.trace("Found straight match: " + method); log.trace("isPublic:" + Modifier.isPublic(method.getModifiers())); } setMethodAccessible(method); // Default access superclass workaround return method; } catch (NoSuchMethodException e) { /* SWALLOW */ } // search through all methods int paramSize = parameterTypes.length; Method bestMatch = null; Method[] methods = clazz.getMethods(); float bestMatchCost = Float.MAX_VALUE; float myCost = Float.MAX_VALUE; for (int i = 0, size = methods.length; i < size; i++) { if (methods[i].getName().equals(methodName)) { // log some trace information if (log.isTraceEnabled()) { log.trace("Found matching name:"); log.trace(methods[i]); } // compare parameters Class[] methodsParams = methods[i].getParameterTypes(); int methodParamSize = methodsParams.length; if (methodParamSize == paramSize) { boolean match = true; for (int n = 0; n < methodParamSize; n++) { if (log.isTraceEnabled()) { log.trace("Param=" + parameterTypes[n].getName()); log.trace("Method=" + methodsParams[n].getName()); } if (!isAssignmentCompatible(methodsParams[n], parameterTypes[n])) { if (log.isTraceEnabled()) { log.trace(methodsParams[n] + " is not assignable from " + parameterTypes[n]); } match = false; break; } } if (match) { // get accessible version of method Method method = getAccessibleMethod(clazz, methods[i]); if (method != null) { if (log.isTraceEnabled()) { log.trace(method + " accessible version of " + methods[i]); } setMethodAccessible(method); // Default access superclass workaround myCost = getTotalTransformationCost(parameterTypes, method.getParameterTypes()); if (myCost < bestMatchCost) { bestMatch = method; bestMatchCost = myCost; } } log.trace("Couldn't find accessible method."); } } } } if (bestMatch == null) { // didn't find a match log.trace("No match found."); } return bestMatch; }
From source file:org.apache.poi.util.MethodUtils.java
public static <T> Constructor<T> getMatchingAccessibleConstructor(Class<T> clazz, Class[] parameterTypes) { // trace logging Log log = LogFactory.getLog(MethodUtils.class); MethodDescriptor md = new MethodDescriptor(clazz, "dummy", parameterTypes, false); // see if we can find the method directly // most of the time this works and it's much faster try {/*from w ww . j a v a 2s . c om*/ Constructor<T> constructor = clazz.getConstructor(parameterTypes); if (log.isTraceEnabled()) { log.trace("Found straight match: " + constructor); log.trace("isPublic:" + Modifier.isPublic(constructor.getModifiers())); } setMethodAccessible(constructor); // Default access superclass workaround return constructor; } catch (NoSuchMethodException e) { /* SWALLOW */ } // search through all methods int paramSize = parameterTypes.length; Constructor<T> bestMatch = null; Constructor<?>[] constructors = clazz.getConstructors(); float bestMatchCost = Float.MAX_VALUE; float myCost = Float.MAX_VALUE; for (int i = 0, size = constructors.length; i < size; i++) { // compare parameters Class[] methodsParams = constructors[i].getParameterTypes(); int methodParamSize = methodsParams.length; if (methodParamSize == paramSize) { boolean match = true; for (int n = 0; n < methodParamSize; n++) { if (log.isTraceEnabled()) { log.trace("Param=" + parameterTypes[n].getName()); log.trace("Method=" + methodsParams[n].getName()); } if (!isAssignmentCompatible(methodsParams[n], parameterTypes[n])) { if (log.isTraceEnabled()) { log.trace(methodsParams[n] + " is not assignable from " + parameterTypes[n]); } match = false; break; } } if (match) { // get accessible version of method Constructor<T> cons = (Constructor<T>) constructors[i]; myCost = getTotalTransformationCost(parameterTypes, cons.getParameterTypes()); if (myCost < bestMatchCost) { bestMatch = cons; bestMatchCost = myCost; } } } } if (bestMatch == null) { // didn't find a match log.trace("No match found."); } return bestMatch; }
From source file:org.easyrec.utils.spring.log.LoggerUtils.java
/** * Writes the given 'message' to the Log 'logger' with level 'logLevel'. * * @param logger the Log to which the message is written * @param logLevel the level to which the message is written * @param message the message to be written *///from w w w .jav a2s.c o m public static void log(Log logger, String logLevel, String message) { if (logLevel.equalsIgnoreCase("info")) { if (logger.isInfoEnabled()) { logger.info(message); } } else if (logLevel.equalsIgnoreCase("debug")) { if (logger.isDebugEnabled()) { logger.debug(message); } } else if (logLevel.equalsIgnoreCase("error")) { if (logger.isErrorEnabled()) { logger.error(message); } } else if (logLevel.equalsIgnoreCase("trace")) { if (logger.isTraceEnabled()) { logger.trace(message); } } else if (logLevel.equalsIgnoreCase("warn")) { if (logger.isWarnEnabled()) { logger.warn(message); } } else if (logLevel.equalsIgnoreCase("fatal")) { if (logger.isFatalEnabled()) { logger.fatal(message); } } else { logger.error("Passed unknown log level " + logLevel + " to Aspect - logging to error instead!"); logger.error(message); } }
From source file:org.elasticsearch.hadoop.cascading.EsHadoopScheme.java
@Override public void sinkConfInit(FlowProcess<JobConf> flowProcess, Tap<JobConf, RecordReader, OutputCollector> tap, JobConf conf) {/*from w w w . j a v a 2s . c o m*/ conf.setOutputFormat(EsOutputFormat.class); // define an output dir to prevent Cascading from setting up a TempHfs and overriding the OutputFormat Settings set = loadSettings(conf, false); Log log = LogFactory.getLog(EsTap.class); InitializationUtils.setValueWriterIfNotSet(set, CascadingValueWriter.class, log); InitializationUtils.setValueReaderIfNotSet(set, JdkValueReader.class, log); InitializationUtils.setBytesConverterIfNeeded(set, CascadingLocalBytesConverter.class, log); InitializationUtils.setFieldExtractorIfNotSet(set, CascadingFieldExtractor.class, log); // NB: we need to set this property even though it is not being used - and since and URI causes problem, use only the resource/file //conf.set("mapred.output.dir", set.getTargetUri() + "/" + set.getTargetResource()); HadoopCfgUtils.setFileOutputFormatDir(conf, set.getResourceWrite()); HadoopCfgUtils.setOutputCommitterClass(conf, EsOutputFormat.EsOldAPIOutputCommitter.class.getName()); if (log.isTraceEnabled()) { log.trace("Initialized (sink) configuration " + HadoopCfgUtils.asProperties(conf)); } }
From source file:org.hyperic.hq.bizapp.server.session.MeasurementBossImpl.java
/** * Method findResourcesCurrentHealth./* ww w. j a v a 2 s.c o m*/ * * The size of the list of ResourceDisplaySummary beans returned will be * equivalent to the size of the entity ID's passed in. * * @return PageList of ResourceDisplaySummary beans * */ @Transactional(readOnly = true) public List<ResourceDisplaySummary> findResourcesCurrentHealth(int sessionId, AppdefEntityID[] entIds) throws AppdefEntityNotFoundException, PermissionException, SessionNotFoundException, SessionTimeoutException { final AuthzSubject subject = sessionManager.getSubject(sessionId); Log timingLog = LogFactory.getLog("DASHBOARD-TIMING"); StopWatch timer = new StopWatch(); PageList resources = new PageList(Arrays.asList(entIds), entIds.length); timingLog.trace("findResourceCurrentHealth(2) - timing [" + timer.toString() + "]"); return getResourcesCurrentHealth(subject, resources); }
From source file:org.hyperic.hq.ui.action.portlet.controlactions.ViewAction.java
public ActionForward execute(ComponentContext context, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { StopWatch timer = new StopWatch(); Log timingLog = LogFactory.getLog("DASHBOARD-TIMING"); HttpSession session = request.getSession(); WebUser user = RequestUtils.getWebUser(session); DashboardConfig dashConfig = dashboardManager .findDashboard((Integer) session.getAttribute(Constants.SELECTED_DASHBOARD_ID), user, authzBoss); ConfigResponse dashPrefs = dashConfig.getConfig(); int sessionId = user.getSessionId().intValue(); Boolean lastCompleted = Boolean.valueOf( dashPrefs.getValue(".dashContent.controlActions.useLastCompleted", Boolean.TRUE.toString())); context.putAttribute("displayLastCompleted", lastCompleted); Boolean mostFrequent = new Boolean( dashPrefs.getValue(".dashContent.controlActions.useMostFrequent", Boolean.FALSE.toString())); context.putAttribute("displayMostFrequent", mostFrequent); Boolean nextScheduled = new Boolean( dashPrefs.getValue(".dashContent.controlActions.useNextScheduled", Boolean.TRUE.toString())); context.putAttribute("displayNextScheduled", nextScheduled); if (lastCompleted.booleanValue()) { int rows = Integer.parseInt(dashPrefs.getValue(".dashContent.controlActions.lastCompleted", "5")); long past = Long.parseLong(dashPrefs.getValue(".dashContent.controlActions.past", "604800000")); PageList<ControlHistory> pageList = controlBoss.getRecentControlActions(sessionId, rows, past); context.putAttribute("lastCompleted", pageList); }/*from w ww . jav a 2s . c om*/ if (nextScheduled.booleanValue()) { int rows = Integer.parseInt(dashPrefs.getValue(".dashContent.controlActions.nextScheduled", "5")); PageList<ControlSchedule> pageList = controlBoss.getPendingControlActions(sessionId, rows); PageList<DashboardControlBean> pendingList = new PageList<DashboardControlBean>(); pendingList.setTotalSize(pageList.getTotalSize()); for (ControlSchedule control : pageList) { DashboardControlBean bean = new DashboardControlBean(); try { AppdefEntityID entity = new AppdefEntityID(control.getEntityType().intValue(), control.getEntityId()); bean.setResource(appdefBoss.findById(sessionId, entity)); bean.setControl(control); pendingList.add(bean); } catch (NullPointerException e) { // ignore the error don't add it to the page this is // added as a result of bug #7596 } } context.putAttribute("nextScheduled", pendingList); } if (mostFrequent.booleanValue()) { int size = Integer.parseInt(dashPrefs.getValue(".dashContent.controlActions.mostFrequent")); PageList<ControlFrequencyValue> pageList = controlBoss.getOnDemandControlFrequency(sessionId, size); context.putAttribute("mostFrequent", pageList); } timingLog.trace("ViewControl- timing [" + timer.toString() + "]"); return null; }