Java Code Examples for org.apache.commons.logging.Log#trace()

The following examples show how to use org.apache.commons.logging.Log#trace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleApplicationEventMulticaster.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
private void doInvokeListener(ApplicationListener listener, ApplicationEvent event) {
	try {
		listener.onApplicationEvent(event);
	}
	catch (ClassCastException ex) {
		String msg = ex.getMessage();
		if (msg == null || matchesClassCastMessage(msg, event.getClass())) {
			// Possibly a lambda-defined listener which we could not resolve the generic event type for
			// -> let's suppress the exception and just log a debug message.
			Log logger = LogFactory.getLog(getClass());
			if (logger.isTraceEnabled()) {
				logger.trace("Non-matching event type for listener: " + listener, ex);
			}
		}
		else {
			throw ex;
		}
	}
}
 
Example 2
Source File: JamonPerformanceMonitorInterceptor.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Wraps the invocation with a JAMon Monitor and writes the current
 * performance statistics to the log (if enabled).
 * @see com.jamonapi.MonitorFactory#start
 * @see com.jamonapi.Monitor#stop
 */
@Override
protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable {
	String name = createInvocationTraceName(invocation);
	MonKey key = new MonKeyImp(name, name, "ms.");

	Monitor monitor = MonitorFactory.start(key);
	try {
		return invocation.proceed();
	}
	catch (Throwable ex) {
		trackException(key, ex);
		throw ex;
	}
	finally {
		monitor.stop();
		if (!this.trackAllInvocations || isLogEnabled(logger)) {
			logger.trace("JAMon performance statistics for method [" + name + "]:\n" + monitor);
		}
	}
}
 
Example 3
Source File: ConfigFileFinder.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
public boolean readFile(Reader reader, String readFrom, String path, String baseUrl, Log log)
{
    // At the moment it is assumed the file is Json, but that does not need to be the case.
    // We have the path including extension.
    boolean successReadingConfig = true;
    try
    {
        JsonNode jsonNode = jsonObjectMapper.readValue(reader, JsonNode.class);
        String readFromMessage = readFrom + ' ' + path;
        if (log.isTraceEnabled())
        {
            log.trace(readFromMessage + " config is: " + jsonNode);
        }
        else
        {
            log.debug(readFromMessage + " config read");
        }
        readJson(jsonNode, readFromMessage, baseUrl);
    }
    catch (Exception e)
    {
        log.error("Error reading "+path, e);
        successReadingConfig = false;
    }
    return successReadingConfig;
}
 
Example 4
Source File: CustomizableTraceInterceptor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Writes the supplied message and {@link Throwable} to the
 * supplied {@code Log} instance. By default messages are written
 * at {@code TRACE} level. Sub-classes can override this method
 * to control which level the message is written at.
 */
protected void writeToLog(Log logger, String message, Throwable ex) {
	if (ex != null) {
		logger.trace(message, ex);
	}
	else {
		logger.trace(message);
	}
}
 
Example 5
Source File: HeartBeat.java    From elasticsearch-hadoop with Apache License 2.0 5 votes vote down vote up
HeartBeat(final Progressable progressable, Configuration cfg, TimeValue lead, final Log log) {
    Assert.notNull(progressable, "a valid progressable is required to report status to Hadoop");
    TimeValue tv = HadoopCfgUtils.getTaskTimeout(cfg);

    Assert.isTrue(tv.getSeconds() <= 0 || tv.getSeconds() > lead.getSeconds(), "Hadoop timeout is shorter than the heartbeat");

    this.progressable = progressable;
    long cfgMillis = (tv.getMillis() > 0 ? tv.getMillis() : 0);
    // the task is simple hence the delay = timeout - lead, that is when to start the notification right before the timeout
    this.delay = new TimeValue(Math.abs(cfgMillis - lead.getMillis()), TimeUnit.MILLISECONDS);
    this.log = log;

    String taskId;
    TaskID taskID = HadoopCfgUtils.getTaskID(cfg);

    if (taskID == null) {
        log.warn("Cannot determine task id...");
        taskId = "<unknown>";
        if (log.isTraceEnabled()) {
            log.trace("Current configuration is " + HadoopCfgUtils.asProperties(cfg));
        }
    }
    else {
        taskId = "" + taskID;
    }

    id = taskId;
}
 
Example 6
Source File: SimpleTraceInterceptor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable {
	String invocationDescription = getInvocationDescription(invocation);
	logger.trace("Entering " + invocationDescription);
	try {
		Object rval = invocation.proceed();
		logger.trace("Exiting " + invocationDescription);
		return rval;
	}
	catch (Throwable ex) {
		logger.trace("Exception thrown in " + invocationDescription, ex);
		throw ex;
	}
}
 
Example 7
Source File: RMServerUtils.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Utility method to verify if the current user has access based on the
 * passed {@link AccessControlList}
 * @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;
}
 
Example 8
Source File: AbstractManifestProcessorBase.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Puts information about current <code>childRef</code> and its <code>parentRef</code> into log in TRACE level. Information includes 'name', 'fromRepositoryId', 'aliened' and
 * 'invadedBy' properties. Additionally, collects the same information for children of <code>childRef</code>
 * 
 * @param parentRef - {@link NodeRef} instance of child node
 * @param childRef - {@link NodeRef} instance of parent of the <code>childRef</code>
 * @param nodeService - {@link NodeService} instance to get properties and checking other states
 * @param log - {@link Log} instance to put log for appropriate class
 */
protected void logInvasionHierarchy(NodeRef parentRef, NodeRef childRef, NodeService nodeService, Log log)
{
    Map<QName, Serializable> properties = nodeService.getProperties(childRef);
    Map<QName, Serializable> parentProperties = nodeService.getProperties(parentRef);
    StringBuilder message = new StringBuilder("Information about '").append(properties.get(ContentModel.PROP_NAME)).append("' node:\n    fromRepositoryId: ").append(
            properties.get(TransferModel.PROP_FROM_REPOSITORY_ID)).append("\n").append("    invadedBy: ").append(properties.get(TransferModel.PROP_INVADED_BY)).append("\n")
            .append("    alien: ").append(nodeService.hasAspect(childRef, TransferModel.ASPECT_ALIEN)).append("\n").append("    repositoryId: ").append(
                    properties.get(TransferModel.PROP_REPOSITORY_ID)).append("\n").append("    parent: ").append(parentProperties.get(ContentModel.PROP_NAME)).append("(")
            .append(parentProperties.get(TransferModel.PROP_FROM_REPOSITORY_ID)).append(")").append(parentProperties.get(TransferModel.PROP_INVADED_BY)).append(": ").append(
                    nodeService.hasAspect(parentRef, TransferModel.ASPECT_ALIEN)).append("\n").append("    children:\n");

    List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(childRef);

    if ((null != childAssocs) && !childAssocs.isEmpty())
    {
        for (ChildAssociationRef child : childAssocs)
        {
            properties = nodeService.getProperties(child.getChildRef());
            message.append("        ").append(properties.get(ContentModel.PROP_NAME)).append("(").append(properties.get(TransferModel.PROP_FROM_REPOSITORY_ID)).append(")")
                    .append(properties.get(TransferModel.PROP_INVADED_BY)).append(": ").append(nodeService.hasAspect(child.getChildRef(), TransferModel.ASPECT_ALIEN)).append(
                            "\n");
        }
    }

    log.trace(message.toString());
}
 
Example 9
Source File: RMServerUtils.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Utility method to verify if the current user has access based on the
 * passed {@link AccessControlList}
 * @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;
}
 
Example 10
Source File: ScriptResourceHelper.java    From alfresco-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Recursively resolve imports in the specified scripts, adding the imports to the
 * specific list of scriplets to combine later.
 * 
 * @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);
    }
}
 
Example 11
Source File: RestService.java    From elasticsearch-hadoop with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static List<PartitionDefinition> findPartitions(Settings settings, Log log) {
    Version.logVersion();

    InitializationUtils.validateSettings(settings);

    ClusterInfo clusterInfo = InitializationUtils.discoverClusterInfo(settings, log);
    InitializationUtils.validateSettingsForReading(settings);
    List<NodeInfo> nodes = InitializationUtils.discoverNodesIfNeeded(settings, log);
    InitializationUtils.filterNonClientNodesIfNeeded(settings, log);
    InitializationUtils.filterNonDataNodesIfNeeded(settings, log);
    InitializationUtils.filterNonIngestNodesIfNeeded(settings, log);

    RestRepository client = new RestRepository(settings);
    try {
        boolean indexExists = client.resourceExists(true);

        List<List<Map<String, Object>>> shards = null;

        if (!indexExists) {
            if (settings.getIndexReadMissingAsEmpty()) {
                log.info(String.format("Index [%s] missing - treating it as empty", settings.getResourceRead()));
                shards = Collections.emptyList();
            } else {
                throw new EsHadoopIllegalArgumentException(
                        String.format("Index [%s] missing and settings [%s] is set to false", settings.getResourceRead(), ConfigurationOptions.ES_INDEX_READ_MISSING_AS_EMPTY));
            }
        } else {
            shards = client.getReadTargetShards();
            if (log.isTraceEnabled()) {
                log.trace("Creating splits for shards " + shards);
            }
        }

        log.info(String.format("Reading from [%s]", settings.getResourceRead()));

        MappingSet mapping = null;
        if (!shards.isEmpty()) {
            mapping = client.getMappings();
            if (log.isDebugEnabled()) {
                log.debug(String.format("Discovered resolved mapping {%s} for [%s]", mapping.getResolvedView(), settings.getResourceRead()));
            }
            // validate if possible
            FieldPresenceValidation validation = settings.getReadFieldExistanceValidation();
            if (validation.isRequired()) {
                MappingUtils.validateMapping(SettingsUtils.determineSourceFields(settings), mapping.getResolvedView(), validation, log);
            }
        }
        final Map<String, NodeInfo> nodesMap = new HashMap<String, NodeInfo>();
        if (nodes != null) {
            for (NodeInfo node : nodes) {
                nodesMap.put(node.getId(), node);
            }
        }
        final List<PartitionDefinition> partitions;
        if (clusterInfo.getMajorVersion().onOrAfter(EsMajorVersion.V_5_X) && settings.getMaxDocsPerPartition() != null) {
            partitions = findSlicePartitions(client.getRestClient(), settings, mapping, nodesMap, shards, log);
        } else {
            partitions = findShardPartitions(settings, mapping, nodesMap, shards, log);
        }
        Collections.shuffle(partitions);
        return partitions;
    } finally {
        client.close();
    }
}
 
Example 12
Source File: HttpRangeProcessor.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Stream a range of bytes from the given InputStream to the ServletOutputStream
 * 
 * @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...");
   }
}
 
Example 13
Source File: LogUtils.java    From alfresco-bulk-import with Apache License 2.0 4 votes vote down vote up
public final static void trace(final Log log, final String message)
{
    log.trace(PREFIX + message);
}
 
Example 14
Source File: ServletServerHttpRequest.java    From spring-analysis-note with MIT License 4 votes vote down vote up
protected final void logBytesRead(int read) {
	Log rsReadLogger = AbstractListenerReadPublisher.rsReadLogger;
	if (rsReadLogger.isTraceEnabled()) {
		rsReadLogger.trace(getLogPrefix() + "Read " + read + (read != -1 ? " bytes" : ""));
	}
}
 
Example 15
Source File: LogUtils.java    From alfresco-bulk-import with Apache License 2.0 4 votes vote down vote up
public final static void trace(final Log log, final String message, final Throwable cause)
{
    log.trace(PREFIX + message, cause);
}
 
Example 16
Source File: AbstractTraceInterceptor.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Write the supplied trace message and {@link Throwable} to the
 * supplied {@code Log} instance.
 * <p>To be called by {@link #invokeUnderTrace} for enter/exit outcomes,
 * potentially including an exception. Note that an exception's stack trace
 * won't get logged when {@link #setLogExceptionStackTrace} is "false".
 * <p>By default messages are written at {@code TRACE} level. Subclasses
 * can override this method to control which level the message is written
 * at, typically also overriding {@link #isLogEnabled} accordingly.
 * @since 4.3.10
 * @see #setLogExceptionStackTrace
 * @see #isLogEnabled
 */
protected void writeToLog(Log logger, String message, Throwable ex) {
	if (ex != null && this.logExceptionStackTrace) {
		logger.trace(message, ex);
	}
	else {
		logger.trace(message);
	}
}
 
Example 17
Source File: LogFormatUtils.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * Use this to log a message with different levels of detail (or different
 * messages) at TRACE vs DEBUG log levels. Effectively, a substitute for:
 * <pre class="code">
 * if (logger.isDebugEnabled()) {
 *   String str = logger.isTraceEnabled() ? "..." : "...";
 *   if (logger.isTraceEnabled()) {
 *     logger.trace(str);
 *   }
 *   else {
 *     logger.debug(str);
 *   }
 * }
 * </pre>
 * @param logger the logger to use to log the message
 * @param messageFactory function that accepts a boolean set to the value
 * of {@link Log#isTraceEnabled()}
 */
public static void traceDebug(Log logger, Function<Boolean, String> messageFactory) {
	if (logger.isDebugEnabled()) {
		String logMessage = messageFactory.apply(logger.isTraceEnabled());
		if (logger.isTraceEnabled()) {
			logger.trace(logMessage);
		}
		else {
			logger.debug(logMessage);
		}
	}
}
 
Example 18
Source File: AbstractTraceInterceptor.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * Write the supplied trace message and {@link Throwable} to the
 * supplied {@code Log} instance.
 * <p>To be called by {@link #invokeUnderTrace} for enter/exit outcomes,
 * potentially including an exception. Note that an exception's stack trace
 * won't get logged when {@link #setLogExceptionStackTrace} is "false".
 * <p>By default messages are written at {@code TRACE} level. Subclasses
 * can override this method to control which level the message is written
 * at, typically also overriding {@link #isLogEnabled} accordingly.
 * @since 4.3.10
 * @see #setLogExceptionStackTrace
 * @see #isLogEnabled
 */
protected void writeToLog(Log logger, String message, @Nullable Throwable ex) {
	if (ex != null && this.logExceptionStackTrace) {
		logger.trace(message, ex);
	}
	else {
		logger.trace(message);
	}
}
 
Example 19
Source File: AbstractTraceInterceptor.java    From spring-analysis-note with MIT License 3 votes vote down vote up
/**
 * Write the supplied trace message and {@link Throwable} to the
 * supplied {@code Log} instance.
 * <p>To be called by {@link #invokeUnderTrace} for enter/exit outcomes,
 * potentially including an exception. Note that an exception's stack trace
 * won't get logged when {@link #setLogExceptionStackTrace} is "false".
 * <p>By default messages are written at {@code TRACE} level. Subclasses
 * can override this method to control which level the message is written
 * at, typically also overriding {@link #isLogEnabled} accordingly.
 * @since 4.3.10
 * @see #setLogExceptionStackTrace
 * @see #isLogEnabled
 */
protected void writeToLog(Log logger, String message, @Nullable Throwable ex) {
	if (ex != null && this.logExceptionStackTrace) {
		logger.trace(message, ex);
	}
	else {
		logger.trace(message);
	}
}
 
Example 20
Source File: SwiftUtils.java    From hadoop with Apache License 2.0 2 votes vote down vote up
/**
 * Sprintf() to the log iff the log is at trace level. If the log
 * is not at trace level, the printf operation is skipped, so
 * no time is spent generating the string.
 * @param log log to use
 * @param text text message
 * @param args args arguments to the print statement
 */
public static void trace(Log log, String text, Object... args) {
  if (log.isTraceEnabled()) {
    log.trace(String.format(text, args));
  }
}