org.infinispan.commons.logging.Log类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(109)

本文整理了Java中org.infinispan.commons.logging.Log类的一些代码示例,展示了Log类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Log类的具体详情如下:
包路径:org.infinispan.commons.logging.Log
类名称:Log

Log介绍

[英]Infinispan's log abstraction layer on top of JBoss Logging.

It contains explicit methods for all INFO or above levels so that they can be internationalized. For the commons module, message ids ranging from 0901 to 1000 inclusively have been reserved.

Log log = LogFactory.getLog( getClass() ); The above will get you an instance of Log, which can be used to generate log messages either via JBoss Logging which then can delegate to Log4J (if the libraries are present) or (if not) the built-in JDK logger.

In addition to the 6 log levels available, this framework also supports parameter interpolation, similar to the JDKs String#format(String,Object...)method. What this means is, that the following block: if (log.isTraceEnabled()) { log.trace("This is a message " + message + " and some other value is " + value); }

... could be replaced with ...

if (log.isTraceEnabled()) log.tracef("This is a message %s and some other value is %s", message, value);

This greatly enhances code readability.

If you are passing a Throwable, note that this should be passed in before the vararg parameter list.
[中]Infinispan的日志抽象层位于JBoss日志之上。
它包含用于所有信息或以上级别的显式方法,以便它们可以国际化。对于commons模块,已保留范围为0901到1000(含)的消息ID。
上面的Log log = LogFactory.getLog( getClass() );将为您提供一个Log实例,可以通过JBoss日志生成日志消息,然后可以将日志消息委托给Log4J(如果有库)或(如果没有库)内置JDK日志。
除了可用的6个日志级别之外,该框架还支持参数插值,类似于JDKs字符串#格式(字符串、对象…)方法这意味着,下面的块:if (log.isTraceEnabled()) { log.trace("This is a message " + message + " and some other value is " + value); }
... 可以替换为。。。
if (log.isTraceEnabled()) log.tracef("This is a message %s and some other value is %s", message, value);
这大大提高了代码的可读性。
如果您要传递一个Throwable,请注意这应该在vararg参数列表之前传递。

代码示例

代码示例来源:origin: org.infinispan/infinispan-query

@Override
public Object fromString(String str) {
 byte[] objBytes = Base64.getDecoder().decode(str);
 try {
   ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(objBytes));
   return ois.readObject();
 } catch (IOException | ClassNotFoundException e) {
   log.error("Error while decoding object", e);
   throw new CacheException(e);
 }
}

代码示例来源:origin: org.infinispan/infinispan-spring5-remote

private String obtainEffectiveCacheName() {
 if (StringUtils.hasText(this.cacheName)) {
   if (this.logger.isDebugEnabled()) {
    this.logger.debug("Using custom cache name [" + this.cacheName + "]");
   }
   return this.cacheName;
 } else {
   if (this.logger.isDebugEnabled()) {
    this.logger.debug("Using bean name [" + this.beanName + "] as cache name");
   }
   return this.beanName;
 }
}

代码示例来源:origin: org.infinispan/infinispan-commons

private static <T> void addServices(ServiceLoader<T> loadedServices, Map<String, T> services) {
 Iterator<T> i = loadedServices.iterator();
 while (i.hasNext()) {
   try {
    T service = i.next();
    if (services.putIfAbsent(service.getClass().getName(), service) == null) {
      LOG.debugf("Loading service impl: %s", service.getClass().getName());
    } else {
      LOG.debugf("Ignoring already loaded service: %s", service.getClass().getName());
    }
   } catch (ServiceConfigurationError e) {
    LOG.debugf("Skipping service impl", e);
   }
 }
}

代码示例来源:origin: org.infinispan/infinispan-commons

private static void warnLegacy(String oldKey, String newKey) {
 if (log.isInfoEnabled())
   log.infof("Could not find value for key %1$s, but did find value under deprecated key %2$s. Please use %1$s as support for %2$s will eventually be discontinued.",
       newKey, oldKey);
}

代码示例来源:origin: org.infinispan/infinispan-commons

public boolean isSafeClass(String className) {
 // Test for classes first (faster)
 boolean isClassAllowed = classes.contains(className);
 if (isClassAllowed) return true;
 boolean regexMatch = compiled.stream().anyMatch(p -> p.matcher(className).find());
 if (regexMatch) return true;
 if (log.isTraceEnabled())
   log.tracef("Class '%s' not in whitelist", className);
 return false;
}

代码示例来源:origin: org.infinispan/infinispan-commons

@Test(expected = IllegalArgumentException.class)
public void testInvalidGlobalTransaction() {
 long seed = System.currentTimeMillis();
 log.infof("[testInvalidGlobalTransaction] seed: %s", seed);
 Random random = new Random(seed);
 Xid xid = XidImpl.create(random.nextInt(), Util.EMPTY_BYTE_ARRAY, new byte[]{0});
 log.debugf("Invalid XID: %s", xid);
}

代码示例来源:origin: org.infinispan/infinispan-commons

@Override
public int nextSize(Object obj) {
 if (isTrace)
   log.tracef("Next predicted buffer size for object type '%s' will be %d",
      obj == null ? "Null" : obj.getClass().getName(), nextBufferSize);
 return nextBufferSize;
}

代码示例来源:origin: org.infinispan/infinispan-commons

classes.add(claz);
} catch (NoClassDefFoundError ncdfe) {
  log.warnf("%s has reference to a class %s that could not be loaded from classpath",
       cf.getAbsolutePath(), ncdfe.getMessage());
} catch (Throwable e) {
  log.warn("On path " + cf.getAbsolutePath() + " could not load class "+ clazz, e);
  jar = new JarFile(path);
} catch (Exception ex) {
  log.warnf("Could not create jar file on path %s", path);
  return classes;
      classes.add(claz);
     } catch (NoClassDefFoundError ncdfe) {
      log.warnf("%s has reference to a class %s that could not be loaded from classpath",
           entry.getName(), ncdfe.getMessage());
     } catch (Throwable e) {
      log.warn("From jar path " + entry.getName() + " could not load class "+ clazz, e);
   jar.close();
  } catch (IOException e) {
   log.debugf(e, "error closing jar file %s", jar);

代码示例来源:origin: org.infinispan/infinispan-commons

/**
* Register the given dynamic JMX MBean.
*
* @param mbean Dynamic MBean to register
* @param objectName {@link ObjectName} under which to register the MBean.
* @param mBeanServer {@link MBeanServer} where to store the MBean.
* @throws Exception If registration could not be completed.
*/
public static void registerMBean(Object mbean, ObjectName objectName, MBeanServer mBeanServer) throws Exception {
 if (!mBeanServer.isRegistered(objectName)) {
   try {
    SecurityActions.registerMBean(mbean, objectName, mBeanServer);
    log.tracef("Registered %s under %s", mbean, objectName);
   } catch (InstanceAlreadyExistsException e) {
    //this might happen if multiple instances are trying to concurrently register same objectName
    log.couldNotRegisterObjectName(objectName, e);
   }
 } else {
   log.debugf("Object name %s already registered", objectName);
 }
}

代码示例来源:origin: org.infinispan/infinispan-spring5-embedded

/**
* @see InitializingBean#afterPropertiesSet()
*/
@Override
public void afterPropertiesSet() throws Exception {
 if (this.infinispanCacheContainer == null) {
   throw new IllegalStateException("No Infinispan CacheContainer has been set");
 }
 this.logger.info("Initializing named Infinispan cache ...");
 this.infinispanCache = this.infinispanCacheContainer.getCache();
 this.logger.info("New Infinispan cache [" + this.infinispanCache + "] initialized");
}

代码示例来源:origin: org.infinispan/infinispan-commons

log.debug("Read error", e);
log.debug("Write error", e);

代码示例来源:origin: org.infinispan/infinispan-commons

public boolean enlistResource(XAResource resource) throws RollbackException, IllegalStateException, SystemException {
 if (trace) {
   log.tracef("Transaction.enlistResource(%s) invoked in transaction with Xid=%s", resource, xid);
   try {
    if (otherResourceEntry.getKey().isSameRM(resource)) {
      log.debug("Ignoring resource. It is already there.");
      return true;
    log.tracef("XaResource.start() invoked in transaction with Xid=%s", xid);
       format("Resource %s rolled back the transaction while XaResource.start()", resource), e);
    markRollbackOnly(exception);
    log.errorEnlistingResource(e);
    throw exception;
   log.errorEnlistingResource(e);
   throw new SystemException(e.getMessage());

代码示例来源:origin: org.infinispan/infinispan-commons

/**
* Looks up the file, see : {@link DefaultFileLookup}.
*
* @param filename might be the name of the file (too look it up in the class path) or an url to a file.
* @return an input stream to the file or null if nothing found through all lookup steps.
* @throws FileNotFoundException if file cannot be found
*/
@Override
public InputStream lookupFileStrict(String filename, ClassLoader cl) throws FileNotFoundException {
 InputStream is = filename == null || filename.length() == 0 ? null : getAsInputStreamFromClassLoader(filename, cl);
 if (is == null) {
   if (log.isDebugEnabled())
    log.debugf("Unable to find file %s in classpath; searching for this file on the filesystem instead.", filename);
   return new FileInputStream(filename);
 }
 return is;
}

代码示例来源:origin: org.infinispan/infinispan-commons

@Override
final public void finishObjectOutput(final ObjectOutput oo) {
 try {
   if (trace) log.trace("Stop marshaller");
   ((org.jboss.marshalling.Marshaller) oo).finish();
 } catch (IOException ignored) {
 }
}

代码示例来源:origin: org.infinispan/infinispan-commons

public void rollback() throws IllegalStateException, SystemException {
 if (trace) {
   log.tracef("Transaction.rollback() invoked in transaction with Xid=%s", xid);
   runCommit(false);
 } catch (HeuristicMixedException | HeuristicRollbackException e) {
   log.errorRollingBack(e);
   SystemException systemException = new SystemException("Unable to rollback transaction");
   systemException.initCause(e);
    log.trace("RollbackException thrown while rolling back", e);

代码示例来源:origin: org.infinispan/infinispan-commons

public boolean runPrepare() {
 if (trace) {
   log.tracef("runPrepare() invoked in transaction with Xid=%s", xid);
      log.tracef("XaResource.prepare() for %s", res);
   } catch (XAException e) {
    if (trace) {
      log.trace("The resource wants to rollback!", e);
    markRollbackOnly(newRollbackException(
       format("Unexpected error in XaResource.prepare() for %s. Rollback transaction.", res), th));
    log.unexpectedErrorFromResourceManager(th);
    return false;

代码示例来源:origin: org.infinispan/infinispan-avro-server

log.debug(request.toString());
final Schema schema = MetadataManager.getInstance().retrieveSchema(request.getSchemaName());
Query q = parsingResult.getQuery();
log.trace("Executing query "+q+ "["+q.getClass()+"]");
log.debug("#results="+list.size());

代码示例来源:origin: org.infinispan/infinispan-hibernate-cache-commons

@Override
public Void apply(EntryView.ReadWriteEntryView<Object, Object> view) {
  if (trace) {
    log.tracef("Applying %s to %s", this, view.find().orElse(null));
      versionComparator = region.getComparator(subclass);
      if (versionComparator == null) {
        log.errorf("Cannot find comparator for %s", subclass);
      int compareResult = versionComparator.compare(version, oldVersion);
      if (trace) {
        log.tracef("Comparing %s and %s -> %d (using %s)", version, oldVersion, compareResult, versionComparator);

代码示例来源:origin: org.infinispan/infinispan-commons

private void notifyAfterCompletion(int status) {
 for (Synchronization s : getEnlistedSynchronization()) {
   if (trace) {
    log.tracef("Synchronization.afterCompletion() for %s", s);
   }
   try {
    s.afterCompletion(status);
   } catch (Throwable t) {
    log.afterCompletionFailed(s.toString(), t);
   }
 }
 syncs.clear();
}

代码示例来源:origin: org.infinispan/infinispan-commons

private void notifyBeforeCompletion() {
 for (Synchronization s : getEnlistedSynchronization()) {
   if (trace) {
    log.tracef("Synchronization.beforeCompletion() for %s", s);
   }
   try {
    s.beforeCompletion();
   } catch (Throwable t) {
    markRollbackOnly(
       newRollbackException(format("Synchronization.beforeCompletion() for %s wants to rollback.", s), t));
    log.beforeCompletionFailed(s.toString(), t);
   }
 }
}

相关文章

微信公众号

最新文章

更多