org.slf4j.Logger类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(531)

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

Logger介绍

[英]The org.slf4j.Logger interface is the main user entry point of SLF4J API. It is expected that logging takes place through concrete implementations of this interface.

Typical usage pattern:

  1. import org.slf4j.Logger;
  2. import org.slf4j.LoggerFactory;
  3. public class Wombat {
  4. final static Logger logger = LoggerFactory.getLogger(Wombat.class);
  5. Integer t;
  6. Integer oldT;
  7. public void setTemperature(Integer temperature) {
  8. oldT = t;
  9. t = temperature;
  10. logger.debug("Temperature set to {}. Old temperature was {}.", t, oldT);
  11. if(temperature.intValue() > 50) {
  12. logger.info("Temperature has risen above 50 degrees.");
  13. }
  14. }
  15. }

[中]组织。slf4j。Logger接口是SLF4J API的主要用户入口点。预期通过该接口的具体实现进行日志记录。
####典型的使用模式:

  1. import org.slf4j.Logger;
  2. import org.slf4j.LoggerFactory;
  3. public class Wombat {
  4. final static Logger logger = LoggerFactory.getLogger(Wombat.class);
  5. Integer t;
  6. Integer oldT;
  7. public void setTemperature(Integer temperature) {
  8. oldT = t;
  9. t = temperature;
  10. logger.debug("Temperature set to {}. Old temperature was {}.", t, oldT);
  11. if(temperature.intValue() > 50) {
  12. logger.info("Temperature has risen above 50 degrees.");
  13. }
  14. }
  15. }

代码示例

代码示例来源:origin: iluwatar/java-design-patterns

  1. /**
  2. * Simulate the read operation
  3. *
  4. */
  5. public void read() throws InterruptedException {
  6. LOGGER.info("{} begin", name);
  7. Thread.sleep(readingTime);
  8. LOGGER.info("{} finish after reading {}ms", name, readingTime);
  9. }
  10. }

代码示例来源:origin: iluwatar/java-design-patterns

  1. /**
  2. * Starts the reactor event loop in a new thread.
  3. */
  4. public void start() {
  5. reactorMain.execute(() -> {
  6. try {
  7. LOGGER.info("Reactor started, waiting for events...");
  8. eventLoop();
  9. } catch (IOException e) {
  10. LOGGER.error("exception in event loop", e);
  11. }
  12. });
  13. }

代码示例来源:origin: spring-projects/spring-framework

  1. public void debug(Object message) {
  2. if (message instanceof String || this.logger.isDebugEnabled()) {
  3. this.logger.debug(String.valueOf(message));
  4. }
  5. }

代码示例来源:origin: spring-projects/spring-framework

  1. public void warn(Object message) {
  2. if (message instanceof String || this.logger.isWarnEnabled()) {
  3. this.logger.warn(String.valueOf(message));
  4. }
  5. }

代码示例来源:origin: spring-projects/spring-framework

  1. public void error(Object message, Throwable exception) {
  2. if (message instanceof String || this.logger.isErrorEnabled()) {
  3. this.logger.error(String.valueOf(message), exception);
  4. }
  5. }

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

  1. @Override
  2. public void warn(String msg) {
  3. logger.warn(msg);
  4. }

代码示例来源:origin: apache/incubator-dubbo

  1. @Override
  2. public void debug(Throwable e) {
  3. if (locationAwareLogger != null) {
  4. locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, e.getMessage(), null, e);
  5. return;
  6. }
  7. logger.debug(e.getMessage(), e);
  8. }

代码示例来源:origin: apache/kafka

  1. private boolean threadShouldExit(long now, long curHardShutdownTimeMs) {
  2. if (!hasActiveExternalCalls()) {
  3. log.trace("All work has been completed, and the I/O thread is now exiting.");
  4. return true;
  5. }
  6. if (now >= curHardShutdownTimeMs) {
  7. log.info("Forcing a hard I/O thread shutdown. Requests in progress will be aborted.");
  8. return true;
  9. }
  10. log.debug("Hard shutdown in {} ms.", curHardShutdownTimeMs - now);
  11. return false;
  12. }

代码示例来源:origin: iluwatar/java-design-patterns

  1. private static void artificialDelayOf(long millis) {
  2. try {
  3. Thread.sleep(millis);
  4. } catch (InterruptedException e) {
  5. LOGGER.error("sleep interrupted", e);
  6. }
  7. }

代码示例来源:origin: skylot/jadx

  1. public static void setClipboardString(String text) {
  2. try {
  3. Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
  4. Transferable transferable = new StringSelection(text);
  5. clipboard.setContents(transferable, null);
  6. LOG.debug("String '{}' copied to clipboard", text);
  7. } catch (Exception e) {
  8. LOG.error("Failed copy string '{}' to clipboard", text, e);
  9. }
  10. }
  11. }

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

  1. @Override
  2. public void trace(String msg) {
  3. logger.trace(msg);
  4. }

代码示例来源:origin: apache/incubator-dubbo

  1. @Override
  2. public boolean isDebugEnabled() {
  3. return logger.isDebugEnabled();
  4. }

代码示例来源:origin: spring-projects/spring-framework

  1. public void trace(Object message) {
  2. if (message instanceof String || this.logger.isTraceEnabled()) {
  3. this.logger.trace(String.valueOf(message));
  4. }
  5. }

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

  1. @Override
  2. public void warn(String format, Object arg) {
  3. logger.warn(format, arg);
  4. }

代码示例来源:origin: apache/incubator-dubbo

  1. @Override
  2. public void debug(String msg) {
  3. if (locationAwareLogger != null) {
  4. locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, null);
  5. return;
  6. }
  7. logger.debug(msg);
  8. }

代码示例来源:origin: iluwatar/java-design-patterns

  1. private static long ap(long i) {
  2. try {
  3. Thread.sleep(i);
  4. } catch (InterruptedException e) {
  5. LOGGER.error("Exception caught.", e);
  6. }
  7. return i * (i + 1) / 2;
  8. }
  9. }

代码示例来源:origin: skylot/jadx

  1. public static void store(JadxSettings settings) {
  2. try {
  3. String jsonSettings = makeString(settings);
  4. LOG.debug("Saving settings: {}", jsonSettings);
  5. PREFS.put(JADX_GUI_KEY, jsonSettings);
  6. PREFS.sync();
  7. } catch (Exception e) {
  8. LOG.error("Error store settings", e);
  9. }
  10. }

代码示例来源:origin: spring-projects/spring-framework

  1. public void error(Object message) {
  2. if (message instanceof String || this.logger.isErrorEnabled()) {
  3. this.logger.error(String.valueOf(message));
  4. }
  5. }

代码示例来源:origin: spring-projects/spring-framework

  1. public void warn(Object message, Throwable exception) {
  2. if (message instanceof String || this.logger.isWarnEnabled()) {
  3. this.logger.warn(String.valueOf(message), exception);
  4. }
  5. }

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

  1. @Override
  2. public void trace(String format, Object... argArray) {
  3. logger.trace(format, argArray);
  4. }

相关文章