mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
change log level at runtime
This commit is contained in:
@@ -72,10 +72,12 @@ public class StartupBean {
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
|
||||
startupTime = Calendar.getInstance().getTimeInMillis();
|
||||
if (userDAO.getCount() == 0) {
|
||||
initialData();
|
||||
}
|
||||
applicationSettingsService.applyLogLevel();
|
||||
|
||||
initSupportedLanguages();
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
|
||||
@Entity
|
||||
@Table(name = "APPLICATIONSETTINGS")
|
||||
@SuppressWarnings("serial")
|
||||
@@ -29,6 +31,7 @@ public class ApplicationSettings extends AbstractModel {
|
||||
private boolean heavyLoad;
|
||||
private boolean pubsubhubbub;
|
||||
private boolean feedbackButton = true;
|
||||
private String logLevel = Level.INFO.toString();
|
||||
|
||||
@Column(length = 255)
|
||||
private String announcement;
|
||||
@@ -162,4 +165,12 @@ public class ApplicationSettings extends AbstractModel {
|
||||
this.databaseUpdateThreads = databaseUpdateThreads;
|
||||
}
|
||||
|
||||
public String getLogLevel() {
|
||||
return logLevel;
|
||||
}
|
||||
|
||||
public void setLogLevel(String logLevel) {
|
||||
this.logLevel = logLevel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
package com.commafeed.backend.services;
|
||||
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javax.ejb.Singleton;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.commafeed.backend.dao.ApplicationSettingsDAO;
|
||||
import com.commafeed.backend.model.ApplicationSettings;
|
||||
import com.google.common.collect.Iterables;
|
||||
@@ -18,6 +24,7 @@ public class ApplicationSettingsService {
|
||||
public void save(ApplicationSettings settings) {
|
||||
this.settings = settings;
|
||||
applicationSettingsDAO.saveOrUpdate(settings);
|
||||
applyLogLevel();
|
||||
}
|
||||
|
||||
public ApplicationSettings get() {
|
||||
@@ -28,4 +35,17 @@ public class ApplicationSettingsService {
|
||||
return settings;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void applyLogLevel() {
|
||||
String logLevel = get().getLogLevel();
|
||||
Level level = Level.toLevel(logLevel);
|
||||
|
||||
Enumeration<Logger> loggers = LogManager.getCurrentLoggers();
|
||||
while (loggers.hasMoreElements()) {
|
||||
Logger logger = loggers.nextElement();
|
||||
if (logger.getName().startsWith("com.commafeed")) {
|
||||
logger.setLevel(level);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user