类org.slf4j.spi.LocationAwareLogger源码实例Demo

下面列出了怎么用org.slf4j.spi.LocationAwareLogger的API类实例代码及写法,或者点击链接到github查看源代码。

@Override
public Logger getLogger(String name) {
	final Logger logger = loggerFactory.getLogger(name);
	if (logger instanceof LocationAwareLogger) {
		return new LevelledLocationAwareLoggerWrapper(
				(LocationAwareLogger) logger) {
			@Override
			protected int getLevel() {
				return LevelledLoggerFactoryWrapper.this.getLevel();
			}
		};
	} else {
		return new LevelledLoggerWrapper(logger) {
			@Override
			protected int getLevel() {
				return LevelledLoggerFactoryWrapper.this.getLevel();
			}
		};
	}
}
 
源代码2 项目: mapper-generator-javafx   文件: Slf4jImpl.java
public Slf4jImpl(Class<?> clazz) {
    Logger logger = LoggerFactory.getLogger(clazz);

    if (logger instanceof LocationAwareLogger) {
        try {
            // check for slf4j >= 1.6 method signature
            logger.getClass().getMethod("log", Marker.class, String.class, int.class,
                    String.class, Object[].class, Throwable.class);
            log = new Slf4jLocationAwareLoggerImpl((LocationAwareLogger) logger);
            return;
        } catch (SecurityException | NoSuchMethodException e) {
            // fail-back to Slf4jLoggerImpl
        }
    }

    // Logger is not LocationAwareLogger or slf4j version < 1.6
    log = new Slf4jLoggerImpl(logger);
}
 
源代码3 项目: HttpSessionReplacer   文件: Log4jLoggerAdapter.java
@Override
public void log(Marker marker, String callerFQCN, int level, String msg, Object[] argArray, Throwable t) {
    Level log4jLevel;
    switch (level) {
    case LocationAwareLogger.TRACE_INT:
        log4jLevel = traceCapable ? Level.TRACE : Level.DEBUG;
        break;
    case LocationAwareLogger.DEBUG_INT:
        log4jLevel = Level.DEBUG;
        break;
    case LocationAwareLogger.INFO_INT:
        log4jLevel = Level.INFO;
        break;
    case LocationAwareLogger.WARN_INT:
        log4jLevel = Level.WARN;
        break;
    case LocationAwareLogger.ERROR_INT:
        log4jLevel = Level.ERROR;
        break;
    default:
        throw new IllegalStateException("Level number " + level + " is not recognized.");
    }
    logger.log(callerFQCN, log4jLevel, msg, t);
}
 
源代码4 项目: logging-log4j2   文件: SLF4JLogger.java
private int convertLevel(final Level level) {
    switch (level.getStandardLevel()) {
        case DEBUG :
            return LocationAwareLogger.DEBUG_INT;
        case TRACE :
            return LocationAwareLogger.TRACE_INT;
        case INFO :
            return LocationAwareLogger.INFO_INT;
        case WARN :
            return LocationAwareLogger.WARN_INT;
        case ERROR :
            return LocationAwareLogger.ERROR_INT;
        default :
            return LocationAwareLogger.ERROR_INT;
    }
}
 
源代码5 项目: dubbo-2.6.5   文件: Slf4jLogger.java
public Slf4jLogger(org.slf4j.Logger logger) {
    if (logger instanceof LocationAwareLogger) {
        locationAwareLogger = (LocationAwareLogger) logger;
    } else {
        locationAwareLogger = null;
    }
    this.logger = logger;
}
 
源代码6 项目: jboot   文件: Slf4jLogger.java
@Override
public void info(String format, Object... args) {
    if (isInfoEnabled()) {
        FormattingTuple ft = MessageFormatter.arrayFormat(format, args);
        log.log(null, callerFQCN, LocationAwareLogger.INFO_INT, ft.getMessage(), NULL_ARGS, ft.getThrowable());
    }
}
 
源代码7 项目: dubbo-2.6.5   文件: Slf4jLogger.java
@Override
public void debug(Throwable e) {
    if (locationAwareLogger != null) {
        locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, e.getMessage(), null, e);
        return;
    }
    logger.debug(e.getMessage(), e);
}
 
源代码8 项目: dubbo-2.6.5   文件: Slf4jLogger.java
@Override
public void info(String msg) {
    if (locationAwareLogger != null) {
        locationAwareLogger.log(null, FQCN, LocationAwareLogger.INFO_INT, msg, null, null);
        return;
    }
    logger.info(msg);
}
 
源代码9 项目: dubbo-2.6.5   文件: Slf4jLogger.java
@Override
public void warn(String msg, Throwable e) {
    if (locationAwareLogger != null) {
        locationAwareLogger.log(null, FQCN, LocationAwareLogger.WARN_INT, msg, null, e);
        return;
    }
    logger.warn(msg, e);
}
 
源代码10 项目: dubbo-2.6.5   文件: Slf4jLogger.java
@Override
public void error(Throwable e) {
    if (locationAwareLogger != null) {
        locationAwareLogger.log(null, FQCN, LocationAwareLogger.ERROR_INT, e.getMessage(), null, e);
        return;
    }
    logger.error(e.getMessage(), e);
}
 
源代码11 项目: Elasticsearch   文件: Slf4jESLogger.java
@Override
protected void internalDebug(String msg) {
    if (lALogger != null) {
        lALogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, null);
    } else {
        logger.debug(msg);
    }
}
 
源代码12 项目: uima-uimaj   文件: Slf4jLogger_impl.java
@Override
public void log(Marker m, String aFqcn, Level level, String msg_with_params, Throwable thrown) {
  m = (m == null) 
      ? getMarkerForLevel(level) 
      : m;
      
if (isLocationCapable) {  // slf4j simple logger is not
  ((org.slf4j.spi.LocationAwareLogger)logger).log(m, aFqcn, getSlf4jLevel(level), msg_with_params, null, thrown);
} else {
  switch(level.toInteger()) {
  case Level.SEVERE_INT: 
    // all of these calls to MessageFormat are to the java.text.MessageFormat
    // to do {n} style format substitution
    logger.error(m, msg_with_params, thrown); 
    break;
  case Level.WARNING_INT: 
    logger.warn(m, msg_with_params, thrown); 
    break;
  case Level.INFO_INT: 
    logger.info(m, msg_with_params, thrown); 
    break;
  case Level.CONFIG_INT: 
    logger.info(m, msg_with_params, thrown); 
    break;
  case Level.FINE_INT: 
    logger.debug(m, msg_with_params, thrown); 
    break;
  case Level.FINER_INT: 
    logger.trace(m, msg_with_params, thrown); 
    break;
  case Level.FINEST_INT: 
    logger.trace(m, msg_with_params, thrown); 
    break;
  default: Misc.internalError();
  }
}
  
}
 
源代码13 项目: snowflake-jdbc   文件: SLF4JLogger.java
public void error(String msg, Throwable t)
{
  msg = SecretDetector.maskSecrets(msg);
  if (isLocationAwareLogger)
  {
    ((LocationAwareLogger) slf4jLogger).log(null, FQCN, LocationAwareLogger.ERROR_INT, msg, null, t);
  }
  else
  {
    slf4jLogger.error(msg, t);
  }
}
 
源代码14 项目: tomee   文件: Slf4jLogger.java
public Slf4jLogger(final String name, final String resourceBundleName) {
    super(name, resourceBundleName);
    logger = org.slf4j.LoggerFactory.getLogger(name);
    if (logger instanceof LocationAwareLogger) {
        locationAwareLogger = (LocationAwareLogger) logger;
    }
}
 
源代码15 项目: uima-uimaj   文件: Slf4jLogger_impl.java
public static int getSlf4jLevel(Level level) {
  switch(level.toInteger()) {
  case Level.SEVERE_INT: return LocationAwareLogger.ERROR_INT;
  case Level.WARNING_INT: return LocationAwareLogger.WARN_INT;
  case Level.INFO_INT: return LocationAwareLogger.INFO_INT;
  case Level.CONFIG_INT: return LocationAwareLogger.INFO_INT;
  case Level.FINE_INT: return LocationAwareLogger.DEBUG_INT;
  case Level.FINER_INT: return LocationAwareLogger.TRACE_INT;
  case Level.FINEST_INT: return LocationAwareLogger.TRACE_INT;
  }
  Misc.internalError();
  return LocationAwareLogger.ERROR_INT; //ignored, just here for compile error avoidance
}
 
源代码16 项目: jboot   文件: Slf4jLogger.java
@Override
public void debug(String format, Object... args) {
    if (isDebugEnabled()) {
        FormattingTuple ft = MessageFormatter.arrayFormat(format, args);
        log.log(null, callerFQCN, LocationAwareLogger.DEBUG_INT, ft.getMessage(), NULL_ARGS, ft.getThrowable());
    }
}
 
源代码17 项目: Elasticsearch   文件: Slf4jESLogger.java
@Override
protected void internalWarn(String msg, Throwable cause) {
    if (lALogger != null) {
        lALogger.log(null, FQCN, LocationAwareLogger.WARN_INT, msg, null, cause);
    } else {
        logger.warn(msg);
    }
}
 
源代码18 项目: jboot   文件: Slf4jLogger.java
@Override
public void warn(String format, Object... args) {
    if (isWarnEnabled()) {
        FormattingTuple ft = MessageFormatter.arrayFormat(format, args);
        log.log(null, callerFQCN, LocationAwareLogger.WARN_INT, ft.getMessage(), NULL_ARGS, ft.getThrowable());
    }
}
 
源代码19 项目: snowflake-jdbc   文件: SLF4JLogger.java
public void debug(String msg)
{
  msg = SecretDetector.maskSecrets(msg);
  if (isLocationAwareLogger)
  {
    ((LocationAwareLogger) slf4jLogger).log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, null);
  }
  else
  {
    slf4jLogger.debug(msg);
  }
}
 
源代码20 项目: jboot   文件: Slf4jLogger.java
@Override
public void error(String format, Object... args) {
    if (isErrorEnabled()) {
        FormattingTuple ft = MessageFormatter.arrayFormat(format, args);
        JbootExceptionHolder.hold(ft.getMessage(), ft.getThrowable());
        log.log(null, callerFQCN, LocationAwareLogger.ERROR_INT, ft.getMessage(), NULL_ARGS, ft.getThrowable());
    }
}
 
源代码21 项目: jboot   文件: Slf4jLogFactory.java
@Override
public Log getLog(String name) {
    if (useJdkLogger) {
        return new JdkLogger(name);
    }

    Logger log = LoggerFactory.getLogger(name);
    return log instanceof LocationAwareLogger ? new Slf4jLogger((LocationAwareLogger) log) : new Slf4jSimpleLogger(log);
}
 
@Override
public void trace(String s) {
    logger.log(MARKER, FQCN, LocationAwareLogger.TRACE_INT, s, null, null);
}
 
源代码23 项目: jeesuite-libs   文件: SLF4JImpl.java
public SLF4JImpl(String loggerName){
    this.log = (LocationAwareLogger) LoggerFactory.getLogger(loggerName);
}
 
public void warn(Marker marker, String format, Object arg1, Object arg2) {
	if (getLevel() <= LocationAwareLogger.WARN_INT) {
		delegate.warn(marker, format, arg1, arg2);
	}
}
 
源代码25 项目: logging-log4j2   文件: SLF4JLogger.java
public SLF4JLogger(final String name, final org.slf4j.Logger logger) {
    super(name);
    this.logger = logger;
    this.locationAwareLogger = logger instanceof LocationAwareLogger ? (LocationAwareLogger) logger : null;
}
 
public void error(Marker marker, String msg) {
	if (getLevel() <= LocationAwareLogger.ERROR_INT) {
		delegate.error(marker, msg);
	}
}
 
LevelledLocationAwareLoggerWrapper(LocationAwareLogger logger) {
	super(logger);
	this.locationAwareDelegate = logger;
}
 
源代码28 项目: nano-framework   文件: SLF4JImpl.java
@Override
public void error(final String message) {
    logger.log(null, FQNC, LocationAwareLogger.ERROR_INT, message, null, null);
    incrementError();
}
 
源代码29 项目: tomee   文件: Slf4jLogger.java
@Override
protected void internalLogFormatted(final String msg, final LogRecord record) {

    final Level level = record.getLevel();
    final Throwable t = record.getThrown();

    final Handler[] targets = getHandlers();
    if (targets != null) {
        for (final Handler h : targets) {
            h.publish(record);
        }
    }
    if (!getUseParentHandlers()) {
        return;
    }

    /*
    * As we can not use a "switch ... case" block but only a "if ... else if ..." block, the order of the
    * comparisons is important. We first try log level FINE then INFO, WARN, FINER, etc
    */
    if (Level.FINE.equals(level)) {
        if (locationAwareLogger == null) {
            logger.debug(msg, t);
        } else {
            locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, t);
        }
    } else if (Level.INFO.equals(level)) {
        if (locationAwareLogger == null) {
            logger.info(msg, t);
        } else {
            locationAwareLogger.log(null, FQCN, LocationAwareLogger.INFO_INT, msg, null, t);
        }
    } else if (Level.WARNING.equals(level)) {
        if (locationAwareLogger == null) {
            logger.warn(msg, t);
        } else {
            locationAwareLogger.log(null, FQCN, LocationAwareLogger.WARN_INT, msg, null, t);
        }
    } else if (Level.FINER.equals(level)) {
        if (locationAwareLogger == null) {
            logger.trace(msg, t);
        } else {
            locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, t);
        }
    } else if (Level.FINEST.equals(level)) {
        if (locationAwareLogger == null) {
            logger.trace(msg, t);
        } else {
            locationAwareLogger.log(null, FQCN, LocationAwareLogger.TRACE_INT, msg, null, t);
        }
    } else if (Level.ALL.equals(level)) {
        // should never occur, all is used to configure java.util.logging
        // but not accessible by the API Logger.xxx() API
        if (locationAwareLogger == null) {
            logger.error(msg, t);
        } else {
            locationAwareLogger.log(null, FQCN, LocationAwareLogger.ERROR_INT, msg, null, t);
        }
    } else if (Level.SEVERE.equals(level)) {
        if (locationAwareLogger == null) {
            logger.error(msg, t);
        } else {
            locationAwareLogger.log(null, FQCN, LocationAwareLogger.ERROR_INT, msg, null, t);
        }
    } else if (Level.CONFIG.equals(level)) {
        if (locationAwareLogger == null) {
            logger.debug(msg, t);
        } else {
            locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, t);
        }
    }
    // don't log if Level.OFF
}
 
源代码30 项目: nano-framework   文件: SLF4JImpl.java
@Override
public void trace(final String message, final Object... args) {
    logger.log(null, FQNC, LocationAwareLogger.TRACE_INT, message, args, null);
    incrementWarn();
}