本文整理汇总了Java中org.springframework.boot.logging.LogLevel类的典型用法代码示例。如果您正苦于以下问题:Java LogLevel类的具体用法?Java LogLevel怎么用?Java LogLevel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LogLevel类属于org.springframework.boot.logging包,在下文中一共展示了LogLevel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: logError
import org.springframework.boot.logging.LogLevel; //导入依赖的package包/类
public void logError(Exception ex, HttpServletRequest request, LogLevel logLevel) {
Map<String, String> map = Maps.newHashMap();
map.put("message", ex.getMessage());
map.put("from", request.getRemoteAddr());
final String queryString = request.getQueryString();
map.put("path", queryString != null ? (request.getRequestURI() + "?" + queryString) : request.getRequestURI());
switch (logLevel) {
case ERROR:
logger.error(JSON.toJSONString(map), ex);
break;
case WARN:
logger.warn(JSON.toJSONString(map));
break;
}
}
示例2: log
import org.springframework.boot.logging.LogLevel; //导入依赖的package包/类
private void log(org.slf4j.Logger logger, LogLevel level, String message) {
Objects.requireNonNull(level, "LogLevel must not be null.");
switch (level) {
case TRACE:
logger.trace(message);
break;
case DEBUG:
logger.debug(message);
break;
case INFO:
logger.info(message);
break;
case WARN:
logger.warn(message);
break;
case ERROR:
case FATAL:
logger.error(message);
break;
default:
break;
}
}
示例3: isEnabled
import org.springframework.boot.logging.LogLevel; //导入依赖的package包/类
private boolean isEnabled(org.slf4j.Logger logger, LogLevel level) {
Objects.requireNonNull(level, "LogLevel must not be null.");
switch (level) {
case TRACE:
return logger.isTraceEnabled();
case DEBUG:
return logger.isDebugEnabled();
case INFO:
return logger.isInfoEnabled();
case WARN:
return logger.isWarnEnabled();
case ERROR:
case FATAL:
return logger.isErrorEnabled();
default:
throw new IllegalArgumentException("LogLevel must be one of the enabled levels.");
}
}
示例4: convert
import org.springframework.boot.logging.LogLevel; //导入依赖的package包/类
private static Level convert(final LogLevel logLevel) {
switch (logLevel) {
case FATAL:
return Level.FATAL;
case ERROR:
return Level.ERROR;
case WARN:
return Level.WARN;
case INFO:
return Level.INFO;
case DEBUG:
return Level.DEBUG;
case TRACE:
return Level.TRACE;
case OFF:
return Level.OFF;
default:
return Level.toLevel(logLevel.name());
}
}
示例5: post
import org.springframework.boot.logging.LogLevel; //导入依赖的package包/类
@RequestMapping(
value = "${edison.application.management.base-path:/internal}/loggers/{name:.*}",
consumes = {
ActuatorMediaType.V2_JSON,
APPLICATION_JSON_VALUE},
produces = {
ActuatorMediaType.V2_JSON,
APPLICATION_JSON_VALUE},
method = POST)
@ResponseBody
public Object post(@PathVariable String name,
@RequestBody Map<String, String> configuration) {
final String level = configuration.get("configuredLevel");
final LogLevel logLevel = level == null ? null : LogLevel.valueOf(level.toUpperCase());
loggersEndpoint.configureLogLevel(name, logLevel);
return HttpEntity.EMPTY;
}
示例6: construct
import org.springframework.boot.logging.LogLevel; //导入依赖的package包/类
@PostConstruct
protected void construct() {
warnPoints = new ConcurrentSkipListSet<>();
warnService = Executors.newSingleThreadScheduledExecutor();
warnService.scheduleAtFixedRate(() -> {
for (WarnPoint wp : warnPoints) {
long duration = System.nanoTime() - wp.getStart();
if (isOver(duration, wp.getLoggable())) {
log(LogLevel.WARN, formatter.warnBefore(wp.getPoint(), wp.getLoggable(), duration), wp.getPoint(),
wp.getLoggable());
warnPoints.remove(wp);
}
}
}, 1L, 1L, TimeUnit.SECONDS);
}
示例7: logMethod
import org.springframework.boot.logging.LogLevel; //导入依赖的package包/类
public Object logMethod(ProceedingJoinPoint joinPoint, Loggable loggable) throws Throwable {
long start = System.nanoTime();
WarnPoint warnPoint = null;
Object returnVal = null;
if (isLevelEnabled(joinPoint, loggable) && loggable.warnOver() >= 0) {
warnPoint = new WarnPoint(joinPoint, loggable, start);
warnPoints.add(warnPoint);
}
if (loggable.entered()) {
log(loggable.value(), formatter.enter(joinPoint, loggable), joinPoint, loggable);
}
try {
returnVal = joinPoint.proceed();
long nano = System.nanoTime() - start;
if (isOver(nano, loggable)) {
log(LogLevel.WARN, formatter.warnAfter(joinPoint, loggable, returnVal, nano), joinPoint, loggable);
} else {
log(loggable.value(), formatter.after(joinPoint, loggable, returnVal, nano), joinPoint, loggable);
}
return returnVal;
} catch (Throwable ex) {
if (contains(loggable.ignore(), ex)) {
log(LogLevel.ERROR, formatter.error(joinPoint, loggable, returnVal, System.nanoTime() - start, ex),
joinPoint, loggable);
} else {
log(formatter.error(joinPoint, loggable, returnVal, System.nanoTime() - start, ex),
joinPoint, loggable, ex);
}
throw ex;
} finally {
if (warnPoint != null) {
warnPoints.remove(warnPoint);
}
}
}
示例8: log
import org.springframework.boot.logging.LogLevel; //导入依赖的package包/类
private void log(LogLevel level, String message, ProceedingJoinPoint joinPoint, Loggable loggable) {
if (loggable.name().isEmpty()) {
logger.log(level,
MethodSignature.class.cast(joinPoint.getSignature()).getMethod().getDeclaringClass(), message);
} else {
logger.log(level, loggable.name(), message);
}
}
示例9: logTrace
import org.springframework.boot.logging.LogLevel; //导入依赖的package包/类
@Test
public void logTrace() {
LoggingSystem.get(ClassLoader.getSystemClassLoader())
.setLogLevel(org.slf4j.Logger.ROOT_LOGGER_NAME, LogLevel.TRACE);
logger.log(LogLevel.TRACE, "logger name", "trace message");
assertThat(capture.toString(), containsString("TRACE logger name - trace message"));
}
示例10: logTraceError
import org.springframework.boot.logging.LogLevel; //导入依赖的package包/类
@Test
public void logTraceError() {
LoggingSystem.get(ClassLoader.getSystemClassLoader())
.setLogLevel(org.slf4j.Logger.ROOT_LOGGER_NAME, LogLevel.TRACE);
logger.log(LogLevel.TRACE, "logger name", "trace message", new Exception("error message"));
Pattern pattern = Pattern.compile("TRACE logger name - trace message.*java.lang.Exception: error message",
Pattern.DOTALL | Pattern.MULTILINE);
assertTrue(pattern.matcher(capture.toString()).find());
}
示例11: logDebug
import org.springframework.boot.logging.LogLevel; //导入依赖的package包/类
@Test
public void logDebug() {
LoggingSystem.get(ClassLoader.getSystemClassLoader())
.setLogLevel(org.slf4j.Logger.ROOT_LOGGER_NAME, LogLevel.DEBUG);
logger.log(LogLevel.DEBUG, "logger name", "debug message");
assertThat(capture.toString(), containsString("DEBUG logger name - debug message"));
}
示例12: logDebugError
import org.springframework.boot.logging.LogLevel; //导入依赖的package包/类
@Test
public void logDebugError() {
LoggingSystem.get(ClassLoader.getSystemClassLoader())
.setLogLevel(org.slf4j.Logger.ROOT_LOGGER_NAME, LogLevel.DEBUG);
logger.log(LogLevel.DEBUG, "logger name", "debug message", new Exception("error message"));
Pattern pattern = Pattern.compile("DEBUG logger name - debug message.*java.lang.Exception: error message",
Pattern.DOTALL | Pattern.MULTILINE);
assertTrue(pattern.matcher(capture.toString()).find());
}
示例13: logInfo
import org.springframework.boot.logging.LogLevel; //导入依赖的package包/类
@Test
public void logInfo() {
LoggingSystem.get(ClassLoader.getSystemClassLoader())
.setLogLevel(org.slf4j.Logger.ROOT_LOGGER_NAME, LogLevel.INFO);
logger.log(LogLevel.INFO, "logger name", "info message");
assertThat(capture.toString(), containsString("INFO logger name - info message"));
}
示例14: logInfoError
import org.springframework.boot.logging.LogLevel; //导入依赖的package包/类
@Test
public void logInfoError() {
LoggingSystem.get(ClassLoader.getSystemClassLoader())
.setLogLevel(org.slf4j.Logger.ROOT_LOGGER_NAME, LogLevel.INFO);
logger.log(LogLevel.INFO, "logger name", "info message", new Exception("error message"));
Pattern pattern = Pattern.compile("INFO logger name - info message.*java.lang.Exception: error message",
Pattern.DOTALL | Pattern.MULTILINE);
assertTrue(pattern.matcher(capture.toString()).find());
}
示例15: logWarning
import org.springframework.boot.logging.LogLevel; //导入依赖的package包/类
@Test
public void logWarning() {
LoggingSystem.get(ClassLoader.getSystemClassLoader())
.setLogLevel(org.slf4j.Logger.ROOT_LOGGER_NAME, LogLevel.WARN);
logger.log(LogLevel.WARN, "logger name", "warn message");
assertThat(capture.toString(), containsString("WARN logger name - warn message"));
}