org.teiid.logging.LogManager类的使用及代码示例

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

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

LogManager介绍

[英]This class represents the interface to a single logging framework that is easily accessible by any component. Using the LogManager, a component can quickly submit a log message, and can rely upon the LogManager to determine (a) whether that message is to be recorded or discarded; and (b) where to send any recorded messages. Thus, the component's code that submits messages does not have to be modified to alter the logging behavior of the application.

By default, all context(s) are logged by the LogManager. The messages that the LogManager actually records and sends to the destinations can be controlled using two different and orthogonal parameters. The first is a message level that filters messages based upon detail, and the second is a message context that filters messages based upon origin. The LogManager tracks only those context(s) that should NOT be logged. Only if a message (which also is defined with these two parameters) passes both filters will it be sent to the destinations.

Each message is submitted with one of the following levels (determined by the particular method used to submit the message), sorted from the least detailed to the greatest:

  • Critical: This level of message is generally used to record an event or error that must be recorded (if any logging is used). If it is used to record an error, it generally means that the system encountered a critical error which affects the integrity, accuracy, reliability and/or capability of the system.
  • Error: Error messages are generally used to record unexpected problems, or errors that are not critical in nature and from which the system can automatically recover.
  • Warning: Warning messages generally described expected errors from which the system should recover. However, this level is used to record the fact that such an error or event did occur.
  • Information: This level of logging is the usually the normal level. All interesting periodic events should be logged at this level so someone looking through the log can see the amount and kind of processing happening in the system.
  • Detail: Such messages are moderately detailed, and help to debug typical problems in the system. Generally, these messages are not so detailed that the big picture gets lost.
  • Trace: A trace message is the most detailed logging level, used to trace system execution for really nasty problems. At this level, logging will be so verbose that the system performance may be affected.

The context for a message is any application-specified String. Again, only those message contexts that match those in the LogManager's configuration will be sent to the destinations.
[中]此类表示单个日志框架的接口,任何组件都可以轻松访问该框架。使用LogManager,组件可以快速提交日志消息,并且可以依赖LogManager来确定(a)是记录还是丢弃该消息;以及(b)在何处发送任何记录的信息。因此,提交消息的组件代码不必修改以改变应用程序的日志记录行为。
默认情况下,所有上下文都由LogManager记录。LogManager实际记录并发送到目的地的消息可以使用两个不同的正交参数进行控制。第一个是基于细节过滤消息的消息级别,第二个是基于来源过滤消息的消息上下文。LogManager只跟踪那些不应该记录的上下文。只有当消息(也使用这两个参数定义)通过两个过滤器时,它才会被发送到目的地。
每封邮件的提交级别为以下级别之一(由用于提交邮件的特定方法确定),从最不详细到最大排序:
*关键:此级别的消息通常用于记录必须记录的事件或错误(如果使用任何日志记录)。如果用于记录错误,通常意味着系统遇到影响系统完整性、准确性、可靠性和/或能力的关键错误。
*错误:错误消息通常用于记录意外问题,或本质上不重要且系统可以自动恢复的错误。
*警告:警告消息通常描述系统应该从中恢复的预期错误。但是,该级别用于记录此类错误或事件确实发生的事实。
*信息:此日志记录级别通常是正常级别。所有感兴趣的周期性事件都应该记录在这个级别,以便查看日志的人可以看到系统中发生的处理量和类型。
*详细信息:此类消息的详细程度适中,有助于调试系统中的典型问题。一般来说,这些信息并不太详细,以至于大局不复存在。
*跟踪:跟踪消息是最详细的日志记录级别,用于跟踪系统执行情况,以防出现严重问题。在这个级别上,日志记录将非常详细,可能会影响系统性能。
消息的上下文是任何应用程序指定的字符串。同样,只有那些与LogManager配置中的消息上下文相匹配的消息上下文才会被发送到目的地。

代码示例

代码示例来源:origin: org.jboss.teiid/teiid-engine

public static BlockedException block(Object... msg) {
  if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
    LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, msg); 
  }
  return INSTANCE;
}

代码示例来源:origin: teiid/teiid

private void freeDataBlock(int dataBlock) {
  if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.TRACE)) {
    LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, "freeing data block", dataBlock, "for", gid, oid); //$NON-NLS-1$ //$NON-NLS-2$
  }
  blocksInuse.clear(dataBlock);
}

代码示例来源:origin: org.teiid/teiid-engine

protected void logWaitMessage(long warnTime, int maximumPoolSize, String poolName, int highestQueueSize) {
  LogManager.logWarning(LogConstants.CTX_RUNTIME, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30009, maximumPoolSize, poolName, highestQueueSize, warnTime));
}

代码示例来源:origin: org.teiid/teiid-runtime

private void writeExceptionCaught(Channel channel,
    Throwable cause) {
  ChannelListener listener = this.listeners.get(channel);
  if (listener != null) {
    listener.exceptionOccurred(cause);
  } else {
    int level = SocketClientInstance.getLevel(cause);
    LogManager.log(level, LogConstants.CTX_TRANSPORT, LogManager.isMessageToBeRecorded(LogConstants.CTX_TRANSPORT, MessageLevel.DETAIL)||level<MessageLevel.WARNING?cause:null, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40114, cause.getMessage()));
    channel.close();
  }
}

代码示例来源:origin: org.teiid/teiid-runtime

private static void trace(Object... msg) {
    LogManager.logTrace(LogConstants.CTX_ODBC, msg);
  }
}

代码示例来源:origin: org.teiid/teiid-runtime

@Override
public boolean terminateSession(String terminatedSessionID, String adminSessionID) {
  Object[] params = {adminSessionID, terminatedSessionID};
  LogManager.logInfo(LogConstants.CTX_SECURITY, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40009, params));
  try {
    closeSession(terminatedSessionID);
    return true;
  } catch (InvalidSessionException e) {
    LogManager.logDetail(LogConstants.CTX_SECURITY,e,e.getMessage());
    return false;
  }
}

代码示例来源:origin: org.jboss.teiid/teiid-engine

public void addWarning(Exception warning) {
  if (warning == null) {
    return;
  }
  synchronized (this.globalState) {
    if (globalState.warnings == null) {
      globalState.warnings = new ArrayList<Exception>(1);
    }
    globalState.warnings.add(warning);
  }
  if (!this.getOptions().isSanitizeMessages() || LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
    LogManager.logInfo(LogConstants.CTX_DQP, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31105, warning.getMessage()));
  }
}

代码示例来源:origin: org.teiid/teiid-engine

/**
 * initialize this <code>ConnectorManager</code>.
 * @throws TranslatorException 
 */
public void start() {
  LogManager.logDetail(LogConstants.CTX_CONNECTOR, QueryPlugin.Util.getString("ConnectorManagerImpl.Initializing_connector", translatorName)); //$NON-NLS-1$
}

代码示例来源:origin: org.teiid/teiid-runtime

private void logProcessingException(Throwable e, String context) {
    Throwable cause = e;
    while (cause.getCause() != null && cause != cause.getCause()) {
      cause = cause.getCause();
    }
    StackTraceElement elem = cause.getStackTrace()[0];
    String msg = RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40011, e.getMessage(), this.socketClientInstance.getWorkContext().getSessionId(), e.getClass().getName(), elem);
    if (LogManager.isMessageToBeRecorded(context, MessageLevel.DETAIL)) {
      LogManager.logWarning(context, e, msg);
    } else {
      LogManager.logWarning(context, msg + QueryPlugin.Util.getString("stack_info")); ////$NON-NLS-1$
    }
  }
}

代码示例来源:origin: teiid/teiid

private String checkForDuplicate(String name, Function<String, Boolean> check, String type) {
  if (check.apply(name)) {
    int suffix = 1;
    String newName = name + "_" + suffix; //$NON-NLS-1$
    while (check.apply(newName)) {
      suffix++;
      newName = name + "_" + suffix; //$NON-NLS-1$
    }
    LogManager.logInfo(LogConstants.CTX_CONNECTOR, DataPlugin.Util.gs(DataPlugin.Event.TEIID60039, name, newName, type));
    name = newName;
  }
  return name;
}

代码示例来源:origin: org.jboss.teiid/teiid-engine

@Override
  public void run() {
    try {
      RequestWorkItem wi = workItemRef.get();
      if (wi != null) {
        LogManager.logInfo(LogConstants.CTX_DQP, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31096, wi.requestID, finalTimeout));
        wi.requestCancel();
      }
    } catch (TeiidComponentException e) {
      LogManager.logError(LogConstants.CTX_DQP, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30018));
    }
  }
}, timeout));

代码示例来源:origin: teiid/teiid

/**
 * Send a warning message to the log.  Warning messages generally described
 * expected errors from which the system should recover.  However, this level
 * is used to record the fact that such an error or event did occur.
 * <p>
 * Only if the log manager is configured to send such messages to the
 * destination will the message be recorded.
 * @param context the context for this log message (for example, the component
 * that is generating this message).
 * @param e the exception that is to be logged; the message is
 * not logged if this parameter is null
 * @param message the log message (may be null)
 */
public static void logWarning(String context, Throwable e, Object message) {
  log(MessageLevel.WARNING,context,e,message);
}

代码示例来源:origin: org.jboss.teiid/teiid-engine

public void closeAtomicRequest(AtomicRequestID atomicRequestId) {
  connectorInfo.remove(atomicRequestId);
  LogManager.logTrace(LogConstants.CTX_DQP, new Object[] {"closed atomic-request:", atomicRequestId});  //$NON-NLS-1$
}

代码示例来源:origin: org.teiid/teiid-runtime

private void monitorSessions() {
  long currentTime = System.currentTimeMillis();
  for (SessionMetadata info : sessionCache.values()) {
    try {
      if (CHECK_PING && !info.isEmbedded() && !info.isActive() && currentTime - info.getLastPingTime() > ServerConnection.PING_INTERVAL * 5) {
        LogManager.logInfo(LogConstants.CTX_SECURITY, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40007, info.getSessionId()));
        closeSession(info.getSessionId());
      } else if (sessionExpirationTimeLimit > 0 && currentTime - info.getCreatedTime() > sessionExpirationTimeLimit) {
        LogManager.logInfo(LogConstants.CTX_SECURITY,RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40008, info.getSessionId()));
        closeSession(info.getSessionId());
      }
    } catch (Exception e) {
      LogManager.logDetail(LogConstants.CTX_SECURITY, e, "error running session monitor, unable to monitor:", info.getSessionId()); //$NON-NLS-1$
    }
  }
}

代码示例来源:origin: teiid/teiid

public void addWarning(Exception warning) {
  if (warning == null) {
    return;
  }
  synchronized (this.globalState) {
    if (globalState.warnings == null) {
      globalState.warnings = new ArrayList<Exception>(1);
    }
    globalState.warnings.add(warning);
    if (globalState.warnings.size() > MAX_WARNINGS) {
      globalState.warnings.remove(0);
    }
  }
  if (!this.getOptions().isSanitizeMessages() || LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
    LogManager.logInfo(LogConstants.CTX_DQP, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31105, warning.getMessage()));
  }
}

代码示例来源:origin: org.jboss.teiid/teiid-engine

private void checkForLowMemory() {
  //proactively create freespace
  if (!cleanerRunning.get() && lowBlocks(false) && cleanerRunning.compareAndSet(false, true)) {
    LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Starting memory buffer cleaner"); //$NON-NLS-1$
    asynchPool.execute(cleaningTask);
  } 
  if (lowBlocks(true)) {
    //do a non-blocking removal before we're forced to block
    evictFromMemoryBuffer(false);
  }
}

代码示例来源:origin: org.teiid/teiid-runtime

private void notifyAdd(String name, String version, CompositeVDB vdb) {
  LogManager.logInfo(LIFECYCLE_CONTEXT, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40118,name, version));
  for(VDBLifeCycleListener l:this.listeners) {
    l.added(name, vdb);
  }
}

代码示例来源:origin: org.teiid/teiid-runtime

@Override
public void exceptionOccurred(Throwable t) {
  int level = SocketClientInstance.getLevel(t);
  LogManager.log(level, LogConstants.CTX_TRANSPORT, LogManager.isMessageToBeRecorded(LogConstants.CTX_TRANSPORT, MessageLevel.DETAIL)||level<MessageLevel.WARNING?t:null, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40114, t.getMessage()));
  server.terminate();
}

代码示例来源:origin: teiid/teiid

/**
 * Send a detail message to the log.  Such messages are moderately detailed,
 * and help to debug typical problems in the system.  Generally, these
 * messages are not so detailed that the big picture gets lost.
 * <p>
 * Only if the log manager is configured to send such messages to the
 * destination will the message be recorded.
 * @param context the context for this log message (for example, the component
 * that is generating this message).
 * @param e the exception that is to be logged; the message is
 * not logged if this parameter is null
 * @param message the log message (may be null)
 */
public static void logDetail(String context, Throwable e, Object ... message) {
  log(MessageLevel.DETAIL,context,e,message);
}

代码示例来源:origin: org.teiid/teiid-engine

public static BlockedException block(Object... msg) {
  if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
    LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, msg); 
  }
  return INSTANCE;
}

相关文章