List of usage examples for org.apache.commons.logging Log isTraceEnabled
boolean isTraceEnabled();
From source file:org.alfresco.repo.web.util.HttpRangeProcessor.java
/** * Stream a range of bytes from the given InputStream to the ServletOutputStream * //from w ww. ja v a2 s .co m * @param r Byte Range to process * @param is InputStream * @param os ServletOutputStream * @param offset Assumed InputStream position - to calculate skip bytes from * */ private void streamRangeBytes(final Range r, final InputStream is, final OutputStream os, long offset) throws IOException { final Log logger = getLogger(); final boolean trace = logger.isTraceEnabled(); // TODO: investigate using getFileChannel() on ContentReader if (r.start != 0L && r.start > offset) { long skipped = offset + is.skip(r.start - offset); if (skipped < r.start) { // Nothing left to download! return; } } long span = (r.end - r.start) + 1L; long bytesLeft = span; int read = 0; // Check that bytesLeft isn't greater than int can hold int bufSize; if (bytesLeft >= Integer.MAX_VALUE - 8) { bufSize = CHUNKSIZE; } else { bufSize = ((int) bytesLeft) < CHUNKSIZE ? (int) bytesLeft : CHUNKSIZE; } byte[] buf = new byte[bufSize]; while ((read = is.read(buf)) > 0 && bytesLeft != 0L) { os.write(buf, 0, read); bytesLeft -= (long) read; if (bytesLeft != 0L) { int resize; if (bytesLeft >= Integer.MAX_VALUE - 8) { resize = CHUNKSIZE; } else { resize = ((int) bytesLeft) < CHUNKSIZE ? (int) bytesLeft : CHUNKSIZE; } if (resize != buf.length) { buf = new byte[resize]; } } if (trace) logger.trace("...wrote " + read + " bytes, with " + bytesLeft + " to go..."); } }
From source file:org.alfresco.scripts.ScriptResourceHelper.java
/** * Resolve the import directives in the specified script. The implementation of the supplied * ScriptResourceLoader instance is responsible for handling the resource retrieval. * <p>/*from w w w . j a v a 2 s. c om*/ * Multiple includes of the same resource are dealt with correctly and nested includes of scripts * is fully supported. * <p> * Note that for performance reasons the script import directive syntax and placement in the file * is very strict. The import lines <i>must</i> always be first in the file - even before any comments. * Immediately that the script service detects a non-import line it will assume the rest of the * file is executable script and no longer attempt to search for any further import directives. Therefore * all imports should be at the top of the script, one following the other, in the correct syntax and * with no comments present - the only separators valid between import directives is white space. * * @param script The script content to resolve imports in * * @return a valid script with all nested includes resolved into a single script instance */ public static String resolveScriptImports(String script, ScriptResourceLoader loader, Log logger) { // use a linked hashmap to preserve order of includes - the key in the collection is used // to resolve multiple includes of the same scripts and therefore cyclic includes also Map<String, String> scriptlets = new LinkedHashMap<String, String>(8, 1.0f); // perform a recursive resolve of all script imports recurseScriptImports(SCRIPT_ROOT, script, loader, scriptlets, logger); if (scriptlets.size() == 1) { // quick exit for single script with no includes if (logger.isTraceEnabled()) logger.trace("Script content resolved to:\r\n" + script); return script; } else { // calculate total size of buffer required for the script and all includes int length = 0; for (String scriptlet : scriptlets.values()) { length += scriptlet.length(); } // append the scripts together to make a single script StringBuilder result = new StringBuilder(length); for (String scriptlet : scriptlets.values()) { result.append(scriptlet); } if (logger.isTraceEnabled()) logger.trace("Script content resolved to:\r\n" + result.toString()); return result.toString(); } }
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. * //from ww w .j a v a 2 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.axis2.transport.mail.MailUtils.java
public static void setupLogging(Session session, Log log, ParameterInclude params) throws AxisFault { // Note that debugging might already be enabled by the mail.debug property and we should // take care to override it. if (log.isTraceEnabled()) { // This is the old behavior: just set debug to true session.setDebug(true);//ww w . j a v a 2 s. c o m } if (ParamUtils.getOptionalParamBoolean(params, MailConstants.TRANSPORT_MAIL_DEBUG, false)) { // Redirect debug output to where it belongs, namely to the logs! session.setDebugOut(new PrintStream(new WriterOutputStream(new LogWriter(log)), true)); // Only enable debug afterwards since the call to setDebug might already cause debug output session.setDebug(true); } }
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(/*from w ww. ja v a2s.c om*/ "Invoking synchronization.onFailure: " + synchronization + " with " + exchange); } 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)); }/*w w w.j av a2 s . c o 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}// w ww.ja 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.// ww w . j a v a 2 s . c om * 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 ww w. j a va2 s . com*/ 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.apache.tools.ant.listener.CommonsLoggingListener.java
/** {@inheritDoc}. */ public void taskStarted(final BuildEvent event) { if (initialized) { final Task task = event.getTask(); Object real = task;/*from w w w. j a v a 2 s . com*/ if (task instanceof UnknownElement) { final Object realObj = ((UnknownElement) task).getTask(); if (realObj != null) { real = realObj; } } final Log log = getLog(real.getClass().getName(), null); if (log.isTraceEnabled()) { realLog(log, "Task \"" + task.getTaskName() + "\" started ", Project.MSG_VERBOSE, null); } } }