org.slf4j.spi.LocationAwareLogger Java Examples

The following examples show how to use org.slf4j.spi.LocationAwareLogger. 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: SLF4JLogger.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
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;
    }
}
 
Example #2
Source File: LevelledLoggerFactoryWrapper.java    From jsonix-schema-compiler with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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();
			}
		};
	}
}
 
Example #3
Source File: Log4jLoggerAdapter.java    From HttpSessionReplacer with MIT License 6 votes vote down vote up
@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);
}
 
Example #4
Source File: Slf4jImpl.java    From mapper-generator-javafx with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #5
Source File: SLF4JLogger.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
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);
  }
}
 
Example #6
Source File: Slf4jLogger_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@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();
  }
}
  
}
 
Example #7
Source File: Slf4jLogger_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
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
}
 
Example #8
Source File: Slf4jLogger.java    From jboot with Apache License 2.0 5 votes vote down vote up
@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());
    }
}
 
Example #9
Source File: Slf4jESLogger.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example #10
Source File: Slf4jLogger.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
public Slf4jLogger(org.slf4j.Logger logger) {
    if (logger instanceof LocationAwareLogger) {
        locationAwareLogger = (LocationAwareLogger) logger;
    } else {
        locationAwareLogger = null;
    }
    this.logger = logger;
}
 
Example #11
Source File: Slf4jESLogger.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected void internalDebug(String msg) {
    if (lALogger != null) {
        lALogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, null);
    } else {
        logger.debug(msg);
    }
}
 
Example #12
Source File: Slf4jLogger.java    From tomee with Apache License 2.0 5 votes vote down vote up
public Slf4jLogger(final String name, final String resourceBundleName) {
    super(name, resourceBundleName);
    logger = org.slf4j.LoggerFactory.getLogger(name);
    if (logger instanceof LocationAwareLogger) {
        locationAwareLogger = (LocationAwareLogger) logger;
    }
}
 
Example #13
Source File: Slf4jLogger.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #14
Source File: Slf4jLogger.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #15
Source File: Slf4jLogger.java    From jboot with Apache License 2.0 5 votes vote down vote up
@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());
    }
}
 
Example #16
Source File: SLF4JLogger.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
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);
  }
}
 
Example #17
Source File: Slf4jLogger.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Override
public void info(String msg) {
    if (locationAwareLogger != null) {
        locationAwareLogger.log(null, FQCN, LocationAwareLogger.INFO_INT, msg, null, null);
        return;
    }
    logger.info(msg);
}
 
Example #18
Source File: Slf4jLogger.java    From jboot with Apache License 2.0 5 votes vote down vote up
@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());
    }
}
 
Example #19
Source File: Slf4jLogger.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #20
Source File: Slf4jLogger.java    From jboot with Apache License 2.0 5 votes vote down vote up
@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());
    }
}
 
Example #21
Source File: Slf4jLogFactory.java    From jboot with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #22
Source File: LevelledLoggerWrapper.java    From jsonix-schema-compiler with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void warn(String format, Object arg1, Object arg2) {
	if (getLevel() <= LocationAwareLogger.WARN_INT) {
		delegate.warn(format, arg1, arg2);
	}
}
 
Example #23
Source File: LevelledLoggerWrapper.java    From jsonix-schema-compiler with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void debug(String msg) {
	if (getLevel() <= LocationAwareLogger.DEBUG_INT) {
		delegate.debug(msg);
	}
}
 
Example #24
Source File: LogAdapter.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public void trace(Object message, Throwable exception) {
	if (message instanceof String || this.logger.isTraceEnabled()) {
		this.logger.log(null, FQCN, LocationAwareLogger.TRACE_INT, String.valueOf(message), null, exception);
	}
}
 
Example #25
Source File: SLF4JImpl.java    From jeesuite-libs with Apache License 2.0 4 votes vote down vote up
@Override
public void debug(String msg) {
    debugCount++;
    log.log(null, callerFQCN, LocationAwareLogger.DEBUG_INT, msg, null, null);
}
 
Example #26
Source File: ProxyConnectionLogger.java    From g4proxy with Apache License 2.0 4 votes vote down vote up
protected void debug(String message, Throwable t) {
    if (logger.isDebugEnabled()) {
        dispatch.doLog(LocationAwareLogger.DEBUG_INT, message, null, t);
    }
}
 
Example #27
Source File: ProxyConnectionLogger.java    From g4proxy with Apache License 2.0 4 votes vote down vote up
protected void error(String message, Object... params) {
    if (logger.isErrorEnabled()) {
        dispatch.doLog(LocationAwareLogger.ERROR_INT, message, params, null);
    }
}
 
Example #28
Source File: SLF4JImpl.java    From nano-framework with Apache License 2.0 4 votes vote down vote up
@Override
public void debug(final String message, final Throwable cause) {
    logger.log(null, FQNC, LocationAwareLogger.ERROR_INT, message, null, cause);
    incrementDebug();
}
 
Example #29
Source File: ProxyConnectionLogger.java    From g4proxy with Apache License 2.0 4 votes vote down vote up
protected void debug(String message, Object... params) {
    if (logger.isDebugEnabled()) {
        dispatch.doLog(LocationAwareLogger.DEBUG_INT, message, params, null);
    }
}
 
Example #30
Source File: Slf4jLocationAwareLoggerImpl.java    From mybatis with Apache License 2.0 4 votes vote down vote up
@Override
public void error(String s) {
  logger.log(MARKER, FQCN, LocationAwareLogger.ERROR_INT, s, null, null);
}