Here are the examples of the java api org.springframework.boot.logging.LogLevel taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
55 Examples
19
Source : ConditionEvaluationReportLoggingListener.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
private boolean isInfoOrDebug(LogLevel logLevelForReport) {
return LogLevel.INFO.equals(logLevelForReport) || LogLevel.DEBUG.equals(logLevelForReport);
}
19
Source : LogbackLoggingSystem.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
private LoggerConfiguration getLoggerConfiguration(ch.qos.logback.clreplacedic.Logger logger) {
if (logger == null) {
return null;
}
LogLevel level = LEVELS.convertNativeToSystem(logger.getLevel());
LogLevel effectiveLevel = LEVELS.convertNativeToSystem(logger.getEffectiveLevel());
String name = logger.getName();
if (!StringUtils.hasLength(name) || Logger.ROOT_LOGGER_NAME.equals(name)) {
name = ROOT_LOGGER_NAME;
}
return new LoggerConfiguration(name, level, effectiveLevel);
}
19
Source : JavaLoggingSystem.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
@Override
public void setLogLevel(String loggerName, LogLevel level) {
if (loggerName == null || ROOT_LOGGER_NAME.equals(loggerName)) {
loggerName = "";
}
Logger logger = Logger.getLogger(loggerName);
if (logger != null) {
logger.setLevel(LEVELS.convertSystemToNative(level));
}
}
19
Source : LoggingApplicationListener.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
/**
* Sets a custom logging level to be used for Spring Boot and related libraries.
* @param springBootLogging the logging level
*/
public void setSpringBootLogging(LogLevel springBootLogging) {
this.springBootLogging = springBootLogging;
}
19
Source : ExampleTest.java
with Apache License 2.0
from TinkoffCreditSystems
with Apache License 2.0
from TinkoffCreditSystems
private void invoke(Runnable runnable, LogLevel level) {
loggingSystem.setLogLevel(ROOT_LOGGER_NAME, level);
exampleAppender.setLevel(level);
try {
runnable.run();
} catch (Throwable e) {
// do nothing
}
}
19
Source : ExampleAppender.java
with Apache License 2.0
from TinkoffCreditSystems
with Apache License 2.0
from TinkoffCreditSystems
void setLevel(LogLevel level) {
this.level = level;
}
19
Source : ParameterLog.java
with Apache License 2.0
from TinkoffCreditSystems
with Apache License 2.0
from TinkoffCreditSystems
/**
* Simple DTO matches to @Log annotation defined on {@link Parameter}.
*
* @author Vyacheslav Klapatnyuk
* @see Log
*/
public clreplaced ParameterLog implements LogDefinition {
private final LogLevel level;
private final LogLevel ifEnabledLevel;
private final LogLevel verboseLevel;
private final Printer printer;
public ParameterLog(LogLevel level, LogLevel ifEnabledLevel, LogLevel verboseLevel, Printer printer) {
this.level = level;
this.ifEnabledLevel = ifEnabledLevel;
this.verboseLevel = verboseLevel;
this.printer = printer;
}
@Override
public LogLevel getLevel() {
return level;
}
@Override
public LogLevel getIfEnabledLevel() {
return ifEnabledLevel;
}
@Override
public LogLevel getVerboseLevel() {
return verboseLevel;
}
public Printer getPrinter() {
return printer;
}
}
19
Source : OutLog.java
with Apache License 2.0
from TinkoffCreditSystems
with Apache License 2.0
from TinkoffCreditSystems
/**
* Simple DTO matches to @Log.out annotation.
*
* @author Vyacheslav Klapatnyuk
* @see ru.tinkoff.eclair.annotation.Log.out
*/
public clreplaced OutLog implements LogDefinition {
private final LogLevel level;
private final LogLevel ifEnabledLevel;
private final LogLevel verboseLevel;
private final Printer printer;
public OutLog(LogLevel level, LogLevel ifEnabledLevel, LogLevel verboseLevel, Printer printer) {
this.level = level;
this.ifEnabledLevel = ifEnabledLevel;
this.verboseLevel = verboseLevel;
this.printer = printer;
}
@Override
public LogLevel getLevel() {
return level;
}
@Override
public LogLevel getIfEnabledLevel() {
return ifEnabledLevel;
}
@Override
public LogLevel getVerboseLevel() {
return verboseLevel;
}
public Printer getPrinter() {
return printer;
}
}
19
Source : ErrorLog.java
with Apache License 2.0
from TinkoffCreditSystems
with Apache License 2.0
from TinkoffCreditSystems
/**
* Simple DTO matches to @Log.error annotation.
*
* @author Vyacheslav Klapatnyuk
* @see ru.tinkoff.eclair.annotation.Log.error
*/
public clreplaced ErrorLog implements LogDefinition {
private final LogLevel level;
private final LogLevel ifEnabledLevel;
private final LogLevel verboseLevel;
private final Filter filter;
public ErrorLog(LogLevel level, LogLevel ifEnabledLevel, LogLevel verboseLevel, Filter filter) {
this.level = level;
this.ifEnabledLevel = ifEnabledLevel;
this.verboseLevel = verboseLevel;
this.filter = filter;
}
@Override
public LogLevel getLevel() {
return level;
}
@Override
public LogLevel getIfEnabledLevel() {
return ifEnabledLevel;
}
@Override
public LogLevel getVerboseLevel() {
return verboseLevel;
}
public Set<Clreplaced<? extends Throwable>> getIncludes() {
return filter.getIncludes();
}
public Set<Clreplaced<? extends Throwable>> getExcludes() {
return filter.getExcludes();
}
public static clreplaced Filter {
private static final Comparator<Clreplaced> clreplacedComparator = comparing((Function<Clreplaced, Integer>) clazz -> RelationResolver.calculateInheritanceDistance(Throwable.clreplaced, clazz)).thenComparing(Clreplaced::getName);
private final Set<Clreplaced<? extends Throwable>> includes;
private final Set<Clreplaced<? extends Throwable>> excludes;
public Filter(Set<Clreplaced<? extends Throwable>> includes, Set<Clreplaced<? extends Throwable>> excludes) {
this.includes = constructSortedUnmodifiableSet(includes);
this.excludes = constructSortedUnmodifiableSet(excludes);
}
public Set<Clreplaced<? extends Throwable>> getIncludes() {
return includes;
}
public Set<Clreplaced<? extends Throwable>> getExcludes() {
return excludes;
}
private Set<Clreplaced<? extends Throwable>> constructSortedUnmodifiableSet(Set<Clreplaced<? extends Throwable>> input) {
Set<Clreplaced<? extends Throwable>> result = new TreeSet<>(clreplacedComparator);
result.addAll(input);
return unmodifiableSet(result);
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClreplaced() != o.getClreplaced()) {
return false;
}
Filter filter = (Filter) o;
return includes.equals(filter.includes) && excludes.equals(filter.excludes);
}
@Override
public int hashCode() {
return 31 * includes.hashCode() + excludes.hashCode();
}
}
}
19
Source : ExpectedLevelResolver.java
with Apache License 2.0
from TinkoffCreditSystems
with Apache License 2.0
from TinkoffCreditSystems
private LogLevel min(LogLevel level1, LogLevel level2) {
return level1.ordinal() <= level2.ordinal() ? level1 : level2;
}
19
Source : LoggingDsl.java
with Apache License 2.0
from spring-projects-experimental
with Apache License 2.0
from spring-projects-experimental
/**
* Set the default ROOT log level
*/
public LoggingDsl level(LogLevel level) {
loggingSystem.setLogLevel("ROOT", level);
return this;
}
19
Source : LoggingDsl.java
with Apache License 2.0
from spring-projects-experimental
with Apache License 2.0
from spring-projects-experimental
/**
* Customize the log level for a given clreplaced
* @param clazz the clreplaced for which the log level should be customized
* @param level the log level to use
*/
public <T> LoggingDsl level(Clreplaced<T> clazz, LogLevel level) {
loggingSystem.setLogLevel(clazz.getName(), level);
return this;
}
19
Source : LoggingDsl.java
with Apache License 2.0
from spring-projects-experimental
with Apache License 2.0
from spring-projects-experimental
/**
* Customize the log level for a given package
* @param packageName the package for which the log level should be customized
* @param level the log level to use
*/
public LoggingDsl level(String packageName, LogLevel level) {
loggingSystem.setLogLevel(packageName, level);
return this;
}
19
Source : OnlyMessageLogExceptionWrapper.java
with Mozilla Public License 2.0
from SafeExamBrowser
with Mozilla Public License 2.0
from SafeExamBrowser
public clreplaced OnlyMessageLogExceptionWrapper extends RuntimeException {
private static final long serialVersionUID = 4177915563660228494L;
public final LogLevel logLevel;
public OnlyMessageLogExceptionWrapper(final Exception cause) {
super(cause);
this.logLevel = LogLevel.WARN;
}
public OnlyMessageLogExceptionWrapper(final Exception cause, final LogLevel logLevel) {
super(cause);
this.logLevel = logLevel;
}
public final void log(final Logger logger) {
final String message = this.getCause().getMessage();
switch(this.logLevel) {
case ERROR:
case FATAL:
logger.error(message);
break;
case INFO:
logger.info(message);
break;
case TRACE:
logger.trace(message);
break;
case WARN:
logger.warn(message);
break;
default:
logger.debug(message);
break;
}
}
}
19
Source : LoggerInterceptor.java
with Apache License 2.0
from rozidan
with Apache License 2.0
from rozidan
private void log(LogLevel level, String message, ProceedingJoinPoint joinPoint, Loggable loggable, Object... args) {
if (loggable.name().isEmpty()) {
logger.log(level, ((MethodSignature) joinPoint.getSignature()).getMethod().getDeclaringClreplaced(), message, args);
} else {
logger.log(level, loggable.name(), message, args);
}
}
19
Source : Logger.java
with Apache License 2.0
from rozidan
with Apache License 2.0
from rozidan
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.");
}
}
19
Source : Logger.java
with Apache License 2.0
from rozidan
with Apache License 2.0
from rozidan
private void log(org.slf4j.Logger logger, LogLevel level, String message, Object... args) {
Objects.requireNonNull(level, "LogLevel must not be null.");
switch(level) {
case TRACE:
logger.trace(message, args);
break;
case DEBUG:
logger.debug(message, args);
break;
case INFO:
logger.info(message, args);
break;
case WARN:
logger.warn(message, args);
break;
case ERROR:
case FATAL:
logger.error(message, args);
break;
default:
break;
}
}
19
Source : LogLevelConfig.java
with Apache License 2.0
from ppdaicorp
with Apache License 2.0
from ppdaicorp
public void changeLogLevel(String loggerName, LogLevel level) {
try {
loggingSystem.setLogLevel(loggerName, level);
} catch (Exception e) {
// TODO: handle exception
}
}
19
Source : PrintLogger.java
with Apache License 2.0
from nacos-group
with Apache License 2.0
from nacos-group
@NacosConfigListener(dataId = "${nacos.example.listener.data-id}", timeout = 5000)
public void onChange(String newLog) throws Exception {
Map<String, Object> properties = new DefaultPropertiesConfigParse().parse(newLog);
for (Object t : properties.keySet()) {
String key = String.valueOf(t);
if (key.startsWith(LOGGER_TAG)) {
String strLevel = (String) properties.getOrDefault(key, "info");
LogLevel level = LogLevel.valueOf(strLevel.toUpperCase());
loggingSystem.setLogLevel(key.replace(LOGGER_TAG, ""), level);
logger.info("{}:{}", key, strLevel);
}
}
}
19
Source : LoggingApplicationListener.java
with Apache License 2.0
from hello-shf
with Apache License 2.0
from hello-shf
/**
* Sets a custom logging level to be used for Spring Boot and related libraries.
*
* @param springBootLogging the logging level
*/
public void setSpringBootLogging(LogLevel springBootLogging) {
this.springBootLogging = springBootLogging;
}
18
Source : LogbackLoggingSystem.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
@Override
public void setLogLevel(String loggerName, LogLevel level) {
ch.qos.logback.clreplacedic.Logger logger = getLogger(loggerName);
if (logger != null) {
logger.setLevel(LEVELS.convertSystemToNative(level));
}
}
18
Source : Log4J2LoggingSystem.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
private LoggerConfiguration convertLoggerConfiguration(LoggerConfig loggerConfig) {
if (loggerConfig == null) {
return null;
}
LogLevel level = LEVELS.convertNativeToSystem(loggerConfig.getLevel());
String name = loggerConfig.getName();
if (!StringUtils.hasLength(name) || LogManager.ROOT_LOGGER_NAME.equals(name)) {
name = ROOT_LOGGER_NAME;
}
return new LoggerConfiguration(name, level, level);
}
18
Source : JavaLoggingSystem.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
@Override
public LoggerConfiguration getLoggerConfiguration(String loggerName) {
Logger logger = Logger.getLogger(loggerName);
if (logger == null) {
return null;
}
LogLevel level = LEVELS.convertNativeToSystem(logger.getLevel());
LogLevel effectiveLevel = LEVELS.convertNativeToSystem(getEffectiveLevel(logger));
String name = (StringUtils.hasLength(logger.getName()) ? logger.getName() : ROOT_LOGGER_NAME);
return new LoggerConfiguration(name, level, effectiveLevel);
}
18
Source : ExampleAppender.java
with Apache License 2.0
from TinkoffCreditSystems
with Apache License 2.0
from TinkoffCreditSystems
/**
* @author Vyacheslav Klapatnyuk
*/
clreplaced ExampleAppender extends AppenderBase<ILoggingEvent> {
private final Map<String, Map<LogLevel, List<ILoggingEvent>>> events = new LinkedHashMap<>();
private LogLevel level = OFF;
@Override
protected void append(ILoggingEvent event) {
events.computeIfAbsent(event.getLoggerName(), name -> initLoggerEvents()).get(level).add(event);
}
private Map<LogLevel, List<ILoggingEvent>> initLoggerEvents() {
Map<LogLevel, List<ILoggingEvent>> events = new LinkedHashMap<>();
Stream.of(values()).forEach(level -> events.put(level, new ArrayList<>()));
return events;
}
void setLevel(LogLevel level) {
this.level = level;
}
Map<LogLevel, List<ILoggingEvent>> getLoggerEvents(String loggerName) {
return events.get(loggerName);
}
}
18
Source : SimpleLogger.java
with Apache License 2.0
from TinkoffCreditSystems
with Apache License 2.0
from TinkoffCreditSystems
/**
* Determines if log level is enabled for logger specified by name.
*
* @param loggerName checkable logger name
* @param level checkable level
* @return {@code true} if enabled, {@code false} otherwise
*/
@Override
protected boolean isLogEnabled(String loggerName, LogLevel level) {
return level != OFF && level.ordinal() >= loggingSystem.getLoggerConfiguration(loggerName).getEffectiveLevel().ordinal();
}
18
Source : SimpleLogger.java
with Apache License 2.0
from TinkoffCreditSystems
with Apache License 2.0
from TinkoffCreditSystems
/**
* Determines if specified log level is enabled for logger by current invocation context.
* Note: Uses information about current {@link StackTraceElement}, so not recommended if high execution speed is important.
*
* @param level checkable level
* @return {@code true} if enabled, {@code false} otherwise
*/
@Override
public boolean isLogEnabled(LogLevel level) {
return level != OFF && isLogEnabled(loggerNameBuilder.buildByInvoker(), level);
}
18
Source : InLog.java
with Apache License 2.0
from TinkoffCreditSystems
with Apache License 2.0
from TinkoffCreditSystems
/**
* Simple DTO matches to @Log.in annotation.
*
* @author Vyacheslav Klapatnyuk
* @see ru.tinkoff.eclair.annotation.Log.in
*/
public clreplaced InLog implements LogDefinition {
private final LogLevel level;
private final LogLevel ifEnabledLevel;
private final LogLevel verboseLevel;
private final List<Printer> printers;
public InLog(LogLevel level, LogLevel ifEnabledLevel, LogLevel verboseLevel, List<Printer> printers) {
this.level = level;
this.ifEnabledLevel = ifEnabledLevel;
this.verboseLevel = verboseLevel;
this.printers = unmodifiableList(printers);
}
@Override
public LogLevel getLevel() {
return level;
}
@Override
public LogLevel getIfEnabledLevel() {
return ifEnabledLevel;
}
@Override
public LogLevel getVerboseLevel() {
return verboseLevel;
}
public List<Printer> getPrinters() {
return printers;
}
}
18
Source : Logger.java
with Apache License 2.0
from rozidan
with Apache License 2.0
from rozidan
public boolean isEnabled(LogLevel level, String name) {
return isEnabled(LoggerFactory.getLogger(name), level);
}
18
Source : Logger.java
with Apache License 2.0
from rozidan
with Apache License 2.0
from rozidan
public void log(LogLevel level, String name, String message, Object... args) {
log(LoggerFactory.getLogger(name), level, message, args);
}
18
Source : Logger.java
with Apache License 2.0
from rozidan
with Apache License 2.0
from rozidan
public void log(LogLevel level, Clreplaced<?> clazz, String message, Object... args) {
log(LoggerFactory.getLogger(clazz), level, message, args);
}
18
Source : Logger.java
with Apache License 2.0
from rozidan
with Apache License 2.0
from rozidan
public boolean isEnabled(LogLevel level, Clreplaced<?> clazz) {
return isEnabled(LoggerFactory.getLogger(clazz), level);
}
17
Source : LoggersEndpoint.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
@WriteOperation
public void configureLogLevel(@Selector String name, @Nullable LogLevel configuredLevel) {
replacedert.notNull(name, "Name must not be empty");
this.loggingSystem.setLogLevel(name, configuredLevel);
}
17
Source : LoggingApplicationListener.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
protected void initializeLogLevel(LoggingSystem system, LogLevel level) {
List<String> loggers = LOG_LEVEL_LOGGERS.get(level);
if (loggers != null) {
for (String logger : loggers) {
system.setLogLevel(logger, level);
}
}
}
17
Source : ExpectedLevelResolverTest.java
with Apache License 2.0
from TinkoffCreditSystems
with Apache License 2.0
from TinkoffCreditSystems
@Test
public void applyTraceDebug() {
// given
LogDefinition definition = givenLogDefinition(TRACE, DEBUG);
// when
LogLevel level = expectedLevelResolver.apply(definition);
// then
replacedertThat(level, is(TRACE));
}
17
Source : ExpectedLevelResolverTest.java
with Apache License 2.0
from TinkoffCreditSystems
with Apache License 2.0
from TinkoffCreditSystems
@Test
public void applyErrorWarn() {
// given
LogDefinition definition = givenLogDefinition(ERROR, WARN);
// when
LogLevel level = expectedLevelResolver.apply(definition);
// then
replacedertThat(level, is(WARN));
}
17
Source : ExpectedLevelResolverTest.java
with Apache License 2.0
from TinkoffCreditSystems
with Apache License 2.0
from TinkoffCreditSystems
private LogDefinition givenLogDefinition(LogLevel level, LogLevel ifEnabled) {
Map<String, Object> attributes = new HashMap<>();
attributes.put("level", level);
attributes.put("ifEnabled", ifEnabled);
return OutLogFactory.newInstance(synthesizeAnnotation(attributes, Log.out.clreplaced, null), new ToStringPrinter());
}
17
Source : ExpectedLevelResolverTest.java
with Apache License 2.0
from TinkoffCreditSystems
with Apache License 2.0
from TinkoffCreditSystems
@Test
public void applyInfoInfo() {
// given
LogDefinition definition = givenLogDefinition(INFO, INFO);
// when
LogLevel level = expectedLevelResolver.apply(definition);
// then
replacedertThat(level, is(INFO));
}
17
Source : SimpleLogger.java
with Apache License 2.0
from TinkoffCreditSystems
with Apache License 2.0
from TinkoffCreditSystems
/**
* Manual logging method.
*
* @param level expected log level
* @param ifEnabledLevel lowest enabled level that allows logging
* @param format format string with Slf4J syntax
* @param arguments arguments for subsreplaceduting into the format string
*/
@Override
public void log(LogLevel level, LogLevel ifEnabledLevel, String format, Object... arguments) {
String loggerName = loggerNameBuilder.buildByInvoker();
if (isLogEnabled(loggerName, level) && isLogEnabled(loggerName, ifEnabledLevel)) {
String message = MANUAL + " " + format;
Object[] unwrappedArguments = unwrapArguments(arguments);
loggerFacadeFactory.getLoggerFacade(loggerName).log(level, message, unwrappedArguments);
}
}
16
Source : ConditionEvaluationReportLoggingListener.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
/**
* {@link ApplicationContextInitializer} that writes the {@link ConditionEvaluationReport}
* to the log. Reports are logged at the {@link LogLevel#DEBUG DEBUG} level. A crash
* report triggers an info output suggesting the user runs again with debug enabled to
* display the report.
* <p>
* This initializer is not intended to be shared across multiple application context
* instances.
*
* @author Greg Turnquist
* @author Dave Syer
* @author Phillip Webb
* @author Andy Wilkinson
* @author Madhura Bhave
*/
public clreplaced ConditionEvaluationReportLoggingListener implements ApplicationContextInitializer<ConfigurableApplicationContext> {
private final Log logger = LogFactory.getLog(getClreplaced());
private ConfigurableApplicationContext applicationContext;
private ConditionEvaluationReport report;
private final LogLevel logLevelForReport;
public ConditionEvaluationReportLoggingListener() {
this(LogLevel.DEBUG);
}
public ConditionEvaluationReportLoggingListener(LogLevel logLevelForReport) {
replacedert.isTrue(isInfoOrDebug(logLevelForReport), "LogLevel must be INFO or DEBUG");
this.logLevelForReport = logLevelForReport;
}
private boolean isInfoOrDebug(LogLevel logLevelForReport) {
return LogLevel.INFO.equals(logLevelForReport) || LogLevel.DEBUG.equals(logLevelForReport);
}
public LogLevel getLogLevelForReport() {
return this.logLevelForReport;
}
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
this.applicationContext = applicationContext;
applicationContext.addApplicationListener(new ConditionEvaluationReportListener());
if (applicationContext instanceof GenericApplicationContext) {
// Get the report early in case the context fails to load
this.report = ConditionEvaluationReport.get(this.applicationContext.getBeanFactory());
}
}
protected void onApplicationEvent(ApplicationEvent event) {
ConfigurableApplicationContext initializerApplicationContext = this.applicationContext;
if (event instanceof ContextRefreshedEvent) {
if (((ApplicationContextEvent) event).getApplicationContext() == initializerApplicationContext) {
logAutoConfigurationReport();
}
} else if (event instanceof ApplicationFailedEvent && ((ApplicationFailedEvent) event).getApplicationContext() == initializerApplicationContext) {
logAutoConfigurationReport(true);
}
}
private void logAutoConfigurationReport() {
logAutoConfigurationReport(!this.applicationContext.isActive());
}
public void logAutoConfigurationReport(boolean isCrashReport) {
if (this.report == null) {
if (this.applicationContext == null) {
this.logger.info("Unable to provide the conditions report " + "due to missing ApplicationContext");
return;
}
this.report = ConditionEvaluationReport.get(this.applicationContext.getBeanFactory());
}
if (!this.report.getConditionAndOutcomesBySource().isEmpty()) {
if (this.getLogLevelForReport().equals(LogLevel.INFO)) {
if (this.logger.isInfoEnabled()) {
this.logger.info(new ConditionEvaluationReportMessage(this.report));
} else if (isCrashReport) {
logMessage("info");
}
} else {
if (this.logger.isDebugEnabled()) {
this.logger.debug(new ConditionEvaluationReportMessage(this.report));
} else if (isCrashReport) {
logMessage("debug");
}
}
}
}
private void logMessage(String logLevel) {
this.logger.info(String.format("%n%nError starting ApplicationContext. To display the " + "conditions report re-run your application with '" + logLevel + "' enabled."));
}
private clreplaced ConditionEvaluationReportListener implements GenericApplicationListener {
@Override
public int getOrder() {
return Ordered.LOWEST_PRECEDENCE;
}
@Override
public boolean supportsEventType(ResolvableType resolvableType) {
Clreplaced<?> type = resolvableType.getRawClreplaced();
if (type == null) {
return false;
}
return ContextRefreshedEvent.clreplaced.isreplacedignableFrom(type) || ApplicationFailedEvent.clreplaced.isreplacedignableFrom(type);
}
@Override
public boolean supportsSourceType(Clreplaced<?> sourceType) {
return true;
}
@Override
public void onApplicationEvent(ApplicationEvent event) {
ConditionEvaluationReportLoggingListener.this.onApplicationEvent(event);
}
}
}
16
Source : ApolloLoggerConfig.java
with Apache License 2.0
from weizhiqiang1995
with Apache License 2.0
from weizhiqiang1995
@PostConstruct
private void refreshLoggingLevels() {
Set<String> keyNames = config.getPropertyNames();
for (String key : keyNames) {
if (StringUtils.containsIgnoreCase(key, LOGGER_TAG)) {
String strLevel = config.getProperty(key, "info");
LogLevel level = LogLevel.valueOf(strLevel.toUpperCase());
loggingSystem.setLogLevel(key.replace(LOGGER_TAG, ""), level);
logger.info("{}:{}", key, strLevel);
}
}
}
16
Source : LogLevelConfig.java
with Apache License 2.0
from ppdaicorp
with Apache License 2.0
from ppdaicorp
@Component
public clreplaced LogLevelConfig {
@Autowired
private SoaConfig soaConfig;
private LoggingSystem loggingSystem = LoggingSystem.get(this.getClreplaced().getClreplacedLoader());
private String logLevel = "";
private Map<String, String> logMap = new ConcurrentHashMap<>();
private LogLevel rootLevel = LogLevel.INFO;
@PostConstruct
private void init() {
soaConfig.registerChanged(new Runnable() {
@Override
public void run() {
setLogLevel();
}
});
rootLevel = loggingSystem.getLoggerConfiguration("root").getEffectiveLevel();
setLogLevel();
}
private void setLogLevel() {
if (!(logLevel + "").equals(soaConfig.getSoaLogLevel())) {
logLevel = soaConfig.getSoaLogLevel();
try {
Map<String, String> map = JsonUtil.parseJson(logLevel, new TypeReference<Map<String, String>>() {
});
if (map != null) {
// loggingSystem.
map.entrySet().forEach(t1 -> {
changeLogLevel(t1.getKey(), t1.getValue());
});
for (String key : logMap.keySet()) {
if (!map.containsKey(key)) {
// 因为默认没有删除loger接口,所以只能将级别设置成跟logger级别
changeLogLevel(key, rootLevel);
}
}
logMap = map;
}
} catch (Exception e) {
// TODO: handle exception
}
}
}
public void changeLogLevel(String loggerName, String level) {
try {
loggingSystem.setLogLevel(loggerName, coerceLogLevel(level));
} catch (Exception e) {
// TODO: handle exception
}
}
public void changeLogLevel(String loggerName, LogLevel level) {
try {
loggingSystem.setLogLevel(loggerName, level);
} catch (Exception e) {
// TODO: handle exception
}
}
private LogLevel coerceLogLevel(String level) {
if ("false".equalsIgnoreCase(level)) {
return LogLevel.OFF;
}
return LogLevel.valueOf(level.toUpperCase());
}
}
16
Source : DynamicLogChangeEventListener.java
with MIT License
from KevinClair
with MIT License
from KevinClair
@PostConstruct
private void refreshLoggingLevels() {
Set<String> keyNames = config.getPropertyNames();
for (String key : keyNames) {
if (containsIgnoreCase(key, LOGGER_TAG)) {
String strLevel = config.getProperty(key, "info");
LogLevel level = LogLevel.valueOf(strLevel.toUpperCase());
loggingSystem.setLogLevel(key.replace(LOGGER_TAG, ""), level);
log.info("{}:{}", key, strLevel);
}
}
}
16
Source : LoggerConfiguration.java
with Apache License 2.0
from ctripcorp
with Apache License 2.0
from ctripcorp
@PostConstruct
private void refreshLoggingLevels() {
Set<String> keyNames = config.getPropertyNames();
for (String key : keyNames) {
if (containsIgnoreCase(key, LOGGER_TAG)) {
String strLevel = config.getProperty(key, "info");
LogLevel level = LogLevel.valueOf(strLevel.toUpperCase());
loggingSystem.setLogLevel(key.replace(LOGGER_TAG, ""), level);
logger.info("{}:{}", key, strLevel);
}
}
}
15
Source : Log4J2LoggingSystem.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
@Override
public void setLogLevel(String loggerName, LogLevel logLevel) {
Level level = LEVELS.convertSystemToNative(logLevel);
LoggerConfig loggerConfig = getLoggerConfig(loggerName);
if (loggerConfig == null) {
loggerConfig = new LoggerConfig(loggerName, level, true);
getLoggerContext().getConfiguration().addLogger(loggerName, loggerConfig);
} else {
loggerConfig.setLevel(level);
}
getLoggerContext().updateLoggers();
}
15
Source : Slf4JLoggerFacade.java
with Apache License 2.0
from TinkoffCreditSystems
with Apache License 2.0
from TinkoffCreditSystems
@Override
public void log(LogLevel level, String format, Object... arguments) {
switch(level) {
case OFF:
break;
case FATAL:
case ERROR:
logger.error(format, arguments);
break;
case WARN:
logger.warn(format, arguments);
break;
case INFO:
logger.info(format, arguments);
break;
case DEBUG:
logger.debug(format, arguments);
break;
case TRACE:
logger.trace(format, arguments);
break;
default:
throw new IllegalArgumentException("Unexpected logging level: " + level);
}
}
15
Source : JavaLoggerFacade.java
with Apache License 2.0
from TinkoffCreditSystems
with Apache License 2.0
from TinkoffCreditSystems
@Override
public void log(LogLevel level, String format, Object... arguments) {
FormattingTuple formattingTuple = MessageFormatter.arrayFormat(format, arguments);
String message = formattingTuple.getMessage();
Throwable throwable = formattingTuple.getThrowable();
logger.log(LEVELS.get(level), message, throwable);
}
15
Source : ActuatorCommand.java
with Apache License 2.0
from fonimus
with Apache License 2.0
from fonimus
/**
* Loggers method
*
* @param action action to make
* @param loggerName logger name for get or configure
* @param loggerLevel logger level for configure
* @return loggers
*/
@ShellMethod(key = "loggers", value = "Display or configure loggers.")
@ShellMethodAvailability("loggersAvailability")
public Object loggers(@ShellOption(value = { "-a", "--action" }, help = "Action to perform", defaultValue = "list") LoggerAction action, @ShellOption(value = { "-n", "--name" }, help = "Logger name for configuration or display", defaultValue = ShellOption.NULL) String loggerName, @ShellOption(value = { "-l", "--level" }, help = "Logger level for configuration", defaultValue = ShellOption.NULL) LogLevel loggerLevel) {
if ((action == LoggerAction.get || action == LoggerAction.conf) && loggerName == null) {
throw new IllegalArgumentException("Logger name is mandatory for '" + action + "' action");
}
switch(action) {
case get:
LoggersEndpoint.LoggerLevels levels = loggers.loggerLevels(loggerName);
return "Logger named [" + loggerName + "] : [configured: " + levels.getConfiguredLevel() + "]";
case conf:
if (loggerLevel == null) {
throw new IllegalArgumentException("Logger level is mandatory for '" + action + "' action");
}
loggers.configureLogLevel(loggerName, loggerLevel);
return "Logger named [" + loggerName + "] now configured to level [" + loggerLevel + "]";
default:
// list
return loggers.loggers();
}
}
14
Source : AbstractLogModel.java
with GNU Lesser General Public License v3.0
from xkcoding
with GNU Lesser General Public License v3.0
from xkcoding
/**
* <p>
* 日志实体基类
* </p>
*
* @author yangkai.shen
* @date Created in 2019/9/24 15:00
*/
@Data
@RequiredArgsConstructor
public abstract clreplaced AbstractLogModel {
/**
* 日志类型
*/
private final LogType type;
/**
* 日志级别
*/
private final LogLevel level;
/**
* 操作IP
*/
private String remoteIp;
/**
* 操作IP对应解析出来的地址
*/
private String ipAddress;
/**
* User-Agent
*/
private String userAgent;
/**
* 请求URI
*/
private String requestUri;
/**
* 请求方式
*/
private String httpMethod;
/**
* 执行类名
*/
private String clreplacedName;
/**
* 执行方法名
*/
private String methodName;
/**
* 操作提交的数据
*/
private String params;
/**
* 操作人
*/
private String operator;
/**
* 操作时间
*/
@DateTimeFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
@JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
private LocalDateTime operateTime;
/**
* 包装日志
*
* @param t 日志
* @param request 请求
* @param operator 操作人
* @param <T> 具体日志
* @return 日志对象
*/
public <T extends AbstractLogModel> T wrapperLog(T t, HttpServletRequest request, String operator) {
t.setRemoteIp(WebUtil.getIP(request));
t.setIpAddress(IpUtil.getAddress(WebUtil.getIP(request)));
t.setUserAgent(request.getHeader(WebUtil.USER_AGENT_HEADER));
t.setRequestUri(UrlUtil.getPath(request.getRequestURI()));
t.setHttpMethod(request.getMethod());
t.setParams(WebUtil.getRequestParamString(request));
t.setOperator(operator);
t.setOperateTime(LocalDateTime.now());
return t;
}
}
14
Source : LogValidator.java
with Apache License 2.0
from TinkoffCreditSystems
with Apache License 2.0
from TinkoffCreditSystems
@Override
public void validate(Method method, T target) throws AnnotationUsageException {
LogLevel expectedLevel = AnnotationAttribute.LEVEL.extract(target);
LogLevel ifEnabledLevel = AnnotationAttribute.IF_ENABLED.extract(target);
if (ifEnabledLevel.ordinal() >= expectedLevel.ordinal() && ifEnabledLevel != OFF) {
throw new AnnotationUsageException(method, format("'ifEnabled = %s' should be more strict than 'level = %s'", ifEnabledLevel, expectedLevel), "Correct specified levels relation or replace 'ifEnabled' by default value 'OFF'", target);
}
String printerName = AnnotationAttribute.PRINTER.extract(target);
if (StringUtils.hasText(printerName)) {
Printer printer = printerResolver.resolve(printerName);
if (isNull(printer)) {
throw new AnnotationUsageException(method, format("Unknown printer '%s'", printerName), "Use correct bean name or alias to specify 'printer'", target);
}
}
}
14
Source : LoggingApplicationListener.java
with Apache License 2.0
from hello-shf
with Apache License 2.0
from hello-shf
/**
* An {@link ApplicationListener} that configures the {@link LoggingSystem}. If the
* environment contains a {@code logging.config} property it will be used to bootstrap the
* logging system, otherwise a default configuration is used. Regardless, logging levels
* will be customized if the environment contains {@code logging.level.*} entries.
* <p>
* Debug and trace logging for Spring, Tomcat, Jetty and Hibernate will be enabled when
* the environment contains {@code debug} or {@code trace} properties that aren't set to
* {@code "false"} (i.e. if you start your application using
* {@literal java -jar myapp.jar [--debug | --trace]}). If you prefer to ignore these
* properties you can set {@link #setParseArgs(boolean) parseArgs} to {@code false}.
* <p>
* By default, log output is only written to the console. If a log file is required the
* {@code logging.path} and {@code logging.file} properties can be used.
* <p>
* Some system properties may be set as side effects, and these can be useful if the
* logging configuration supports placeholders (i.e. log4j or logback):
* <ul>
* <li>{@code LOG_FILE} is set to the value of path of the log file that should be written
* (if any).</li>
* <li>{@code PID} is set to the value of the current process ID if it can be determined.
* </li>
* </ul>
*
* @author Dave Syer
* @author Phillip Webb
* @author Andy Wilkinson
* @author Madhura Bhave
* @see LoggingSystem#get(ClreplacedLoader)
* @since 2.0.0
*/
public clreplaced LoggingApplicationListener implements GenericApplicationListener {
private static final Bindable<Map<String, String>> STRING_STRING_MAP = Bindable.mapOf(String.clreplaced, String.clreplaced);
/**
* The default order for the LoggingApplicationListener.
*/
public static final int DEFAULT_ORDER = Ordered.HIGHEST_PRECEDENCE + 20;
/**
* The name of the Spring property that contains a reference to the logging
* configuration to load.
*/
public static final String CONFIG_PROPERTY = "logging.config";
/**
* The name of the Spring property that controls the registration of a shutdown hook
* to shut down the logging system when the JVM exits.
*
* @see LoggingSystem#getShutdownHandler
*/
public static final String REGISTER_SHUTDOWN_HOOK_PROPERTY = "logging.register-shutdown-hook";
/**
* The name of the {@link LoggingSystem} bean.
*/
public static final String LOGGING_SYSTEM_BEAN_NAME = "springBootLoggingSystem";
private static final MultiValueMap<LogLevel, String> LOG_LEVEL_LOGGERS;
private static AtomicBoolean shutdownHookRegistered = new AtomicBoolean(false);
static {
LOG_LEVEL_LOGGERS = new LinkedMultiValueMap<>();
LOG_LEVEL_LOGGERS.add(LogLevel.DEBUG, "org.springframework.boot");
LOG_LEVEL_LOGGERS.add(LogLevel.TRACE, "org.springframework");
LOG_LEVEL_LOGGERS.add(LogLevel.TRACE, "org.apache.tomcat");
LOG_LEVEL_LOGGERS.add(LogLevel.TRACE, "org.apache.catalina");
LOG_LEVEL_LOGGERS.add(LogLevel.TRACE, "org.eclipse.jetty");
LOG_LEVEL_LOGGERS.add(LogLevel.TRACE, "org.hibernate.tool.hbm2ddl");
LOG_LEVEL_LOGGERS.add(LogLevel.DEBUG, "org.hibernate.SQL");
}
private static final Clreplaced<?>[] EVENT_TYPES = { ApplicationStartingEvent.clreplaced, ApplicationEnvironmentPreparedEvent.clreplaced, ApplicationPreparedEvent.clreplaced, ContextClosedEvent.clreplaced, ApplicationFailedEvent.clreplaced };
private static final Clreplaced<?>[] SOURCE_TYPES = { SpringApplication.clreplaced, ApplicationContext.clreplaced };
private final Log logger = LogFactory.getLog(getClreplaced());
private LoggingSystem loggingSystem;
private int order = DEFAULT_ORDER;
private boolean parseArgs = true;
private LogLevel springBootLogging = null;
@Override
public boolean supportsEventType(ResolvableType resolvableType) {
return isreplacedignableFrom(resolvableType.getRawClreplaced(), EVENT_TYPES);
}
@Override
public boolean supportsSourceType(Clreplaced<?> sourceType) {
return isreplacedignableFrom(sourceType, SOURCE_TYPES);
}
private boolean isreplacedignableFrom(Clreplaced<?> type, Clreplaced<?>... supportedTypes) {
if (type != null) {
for (Clreplaced<?> supportedType : supportedTypes) {
if (supportedType.isreplacedignableFrom(type)) {
return true;
}
}
}
return false;
}
@Override
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof ApplicationStartingEvent) {
onApplicationStartingEvent((ApplicationStartingEvent) event);
} else if (event instanceof ApplicationEnvironmentPreparedEvent) {
onApplicationEnvironmentPreparedEvent((ApplicationEnvironmentPreparedEvent) event);
} else if (event instanceof ApplicationPreparedEvent) {
onApplicationPreparedEvent((ApplicationPreparedEvent) event);
} else if (event instanceof ContextClosedEvent && ((ContextClosedEvent) event).getApplicationContext().getParent() == null) {
onContextClosedEvent();
} else if (event instanceof ApplicationFailedEvent) {
onApplicationFailedEvent();
}
}
private void onApplicationStartingEvent(ApplicationStartingEvent event) {
this.loggingSystem = LoggingSystem.get(event.getSpringApplication().getClreplacedLoader());
this.loggingSystem.beforeInitialize();
}
private void onApplicationEnvironmentPreparedEvent(ApplicationEnvironmentPreparedEvent event) {
if (this.loggingSystem == null) {
this.loggingSystem = LoggingSystem.get(event.getSpringApplication().getClreplacedLoader());
}
initialize(event.getEnvironment(), event.getSpringApplication().getClreplacedLoader());
}
private void onApplicationPreparedEvent(ApplicationPreparedEvent event) {
ConfigurableListableBeanFactory beanFactory = event.getApplicationContext().getBeanFactory();
if (!beanFactory.containsBean(LOGGING_SYSTEM_BEAN_NAME)) {
beanFactory.registerSingleton(LOGGING_SYSTEM_BEAN_NAME, this.loggingSystem);
}
}
private void onContextClosedEvent() {
if (this.loggingSystem != null) {
this.loggingSystem.cleanUp();
}
}
private void onApplicationFailedEvent() {
if (this.loggingSystem != null) {
this.loggingSystem.cleanUp();
}
}
/**
* Initialize the logging system according to preferences expressed through the
* {@link Environment} and the clreplacedpath.
*
* @param environment the environment
* @param clreplacedLoader the clreplacedloader
*/
protected void initialize(ConfigurableEnvironment environment, ClreplacedLoader clreplacedLoader) {
new LoggingSystemProperties(environment).apply();
LogFile logFile = LogFile.get(environment);
if (logFile != null) {
logFile.applyToSystemProperties();
}
initializeEarlyLoggingLevel(environment);
initializeSystem(environment, this.loggingSystem, logFile);
initializeFinalLoggingLevels(environment, this.loggingSystem);
registerShutdownHookIfNecessary(environment, this.loggingSystem);
}
private void initializeEarlyLoggingLevel(ConfigurableEnvironment environment) {
if (this.parseArgs && this.springBootLogging == null) {
if (isSet(environment, "debug")) {
this.springBootLogging = LogLevel.DEBUG;
}
if (isSet(environment, "trace")) {
this.springBootLogging = LogLevel.TRACE;
}
}
}
private boolean isSet(ConfigurableEnvironment environment, String property) {
String value = environment.getProperty(property);
return (value != null && !value.equals("false"));
}
private void initializeSystem(ConfigurableEnvironment environment, LoggingSystem system, LogFile logFile) {
LoggingInitializationContext initializationContext = new LoggingInitializationContext(environment);
String logConfig = environment.getProperty(CONFIG_PROPERTY);
if (ignoreLogConfig(logConfig)) {
system.initialize(initializationContext, null, logFile);
} else {
try {
ResourceUtils.getURL(logConfig).openStream().close();
system.initialize(initializationContext, logConfig, logFile);
} catch (Exception ex) {
// NOTE: We can't use the logger here to report the problem
System.err.println("Logging system failed to initialize " + "using configuration from '" + logConfig + "'");
ex.printStackTrace(System.err);
throw new IllegalStateException(ex);
}
}
}
private boolean ignoreLogConfig(String logConfig) {
return !StringUtils.hasLength(logConfig) || logConfig.startsWith("-D");
}
private void initializeFinalLoggingLevels(ConfigurableEnvironment environment, LoggingSystem system) {
if (this.springBootLogging != null) {
initializeLogLevel(system, this.springBootLogging);
}
setLogLevels(system, environment);
}
protected void initializeLogLevel(LoggingSystem system, LogLevel level) {
List<String> loggers = LOG_LEVEL_LOGGERS.get(level);
if (loggers != null) {
for (String logger : loggers) {
system.setLogLevel(logger, level);
}
}
}
protected void setLogLevels(LoggingSystem system, Environment environment) {
if (!(environment instanceof ConfigurableEnvironment)) {
return;
}
Binder binder = Binder.get(environment);
binder.bind("logging.level", STRING_STRING_MAP).orElseGet(Collections::emptyMap).forEach((name, level) -> setLogLevel(system, name, level));
}
private void setLogLevel(LoggingSystem system, String name, String level) {
try {
name = name.equalsIgnoreCase(LoggingSystem.ROOT_LOGGER_NAME) ? null : name;
system.setLogLevel(name, coerceLogLevel(level));
} catch (RuntimeException ex) {
this.logger.error("Cannot set level: " + level + " for '" + name + "'");
}
}
private LogLevel coerceLogLevel(String level) {
if ("false".equalsIgnoreCase(level)) {
return LogLevel.OFF;
}
return LogLevel.valueOf(level.toUpperCase(Locale.ENGLISH));
}
private void registerShutdownHookIfNecessary(Environment environment, LoggingSystem loggingSystem) {
boolean registerShutdownHook = environment.getProperty(REGISTER_SHUTDOWN_HOOK_PROPERTY, Boolean.clreplaced, false);
if (registerShutdownHook) {
Runnable shutdownHandler = loggingSystem.getShutdownHandler();
if (shutdownHandler != null && shutdownHookRegistered.compareAndSet(false, true)) {
registerShutdownHook(new Thread(shutdownHandler));
}
}
}
void registerShutdownHook(Thread shutdownHook) {
Runtime.getRuntime().addShutdownHook(shutdownHook);
}
public void setOrder(int order) {
this.order = order;
}
@Override
public int getOrder() {
return this.order;
}
/**
* Sets a custom logging level to be used for Spring Boot and related libraries.
*
* @param springBootLogging the logging level
*/
public void setSpringBootLogging(LogLevel springBootLogging) {
this.springBootLogging = springBootLogging;
}
/**
* Sets if initialization arguments should be parsed for {@literal --debug} and
* {@literal --trace} options. Defaults to {@code true}.
*
* @param parseArgs if arguments should be parsed
*/
public void setParseArgs(boolean parseArgs) {
this.parseArgs = parseArgs;
}
}
See More Examples