本文整理汇总了Java中org.apache.logging.log4j.core.config.LoggerConfig.setLevel方法的典型用法代码示例。如果您正苦于以下问题:Java LoggerConfig.setLevel方法的具体用法?Java LoggerConfig.setLevel怎么用?Java LoggerConfig.setLevel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.logging.log4j.core.config.LoggerConfig
的用法示例。
在下文中一共展示了LoggerConfig.setLevel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: changeLogLevel
import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
@PUT
@Path("/log/change-level/{loggerName}/{newLevel}")
public Response changeLogLevel(@PathParam("loggerName") String loggerName,
@PathParam("newLevel") String newLevel) {
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(loggerName);
if (loggerConfig.getName().equals(LogManager.ROOT_LOGGER_NAME)) {
return Response.ok("Not found", MediaType.TEXT_PLAIN).build();
}
loggerConfig.setLevel(Level.valueOf(newLevel));
ctx.updateLoggers(); // This causes all Loggers to refetch information from their LoggerConfig.
return Response.ok("Done", MediaType.TEXT_PLAIN).build();
}
示例2: watch
import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
public void watch(Class<?> loggerClass, Level level) {
this.loggerClass = loggerClass;
Appender appender = new AbstractAppender(APPENDER_NAME, null, PatternLayout.createDefaultLayout()) {
@Override
public void append(LogEvent event) {
logEvents.add(event);
}
};
appender.start();
final LoggerContext ctx = getLoggerContext();
LoggerConfig loggerConfig = ctx.getConfiguration().getLoggerConfig(loggerClass.getName());
oldLevel = loggerConfig.getLevel();
loggerConfig.setLevel(level);
loggerConfig.addAppender(appender, level, null);
ctx.updateLoggers();
}
示例3: applyDelegate
import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
@Override
public void applyDelegate(Config config) {
Security.addProvider(new BouncyCastleProvider());
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration ctxConfig = ctx.getConfiguration();
LoggerConfig loggerConfig = ctxConfig.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
if (isDebug()) {
loggerConfig.setLevel(Level.DEBUG);
} else if (isQuiet()) {
loggerConfig.setLevel(Level.OFF);
} else if (getLogLevel() != null) {
loggerConfig.setLevel(getLogLevel());
}
ctx.updateLoggers();
LOGGER.debug("Using the following security providers");
for (Provider p : Security.getProviders()) {
LOGGER.debug("Provider {}, version, {}", p.getName(), p.getVersion());
}
// remove stupid Oracle JDK security restriction (otherwise, it is not
// possible to use strong crypto with Oracle JDK)
UnlimitedStrengthEnabler.enable();
}
示例4: StandaloneLoggerConfiguration
import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
/**
* Constructor to create the default configuration.
*/
public StandaloneLoggerConfiguration(ConfigurationSource source) {
super(source);
setName(CONFIG_NAME);
final Appender appender = StandaloneLogEventAppender.createAppender("StandaloneLogAppender", 1000);
appender.start();
addAppender(appender);
final LoggerConfig root = getRootLogger();
root.addAppender(appender, null, null);
final String levelName = PropertiesUtil.getProperties().getStringProperty(DEFAULT_LEVEL);
final Level level = levelName != null && Level.valueOf(levelName) != null ?
Level.valueOf(levelName) : Level.ALL;
root.setLevel(level);
}
示例5: testReadException
import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
/**
* Tests that {@link oc.io.base.DecoupledInputStream#read()} terminates
* normally when IOException is thrown in wrapped InputStream
*
* @throws IOException
*/
@Test
public void testReadException() throws IOException {
final byte b[] = new byte[1];
// Temporary disable logging for avoiding annoying Exception trace
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
final LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
final Level currentLevel = loggerConfig.getLevel();
loggerConfig.setLevel(Level.FATAL);
ctx.updateLoggers();
final TestInputStream testInputStream = new TestInputStream(new IOException(
"This exception is thrown due to a test scenario. This is expected behaviour"));
final DecoupledInputStream decInputStream = new DecoupledInputStream(testInputStream);
assertEquals(-1, decInputStream.read(b));
decInputStream.close();
loggerConfig.setLevel(currentLevel);
ctx.updateLoggers();
}
示例6: setLogLevel
import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
@Override
public void setLogLevel(String category, String level) {
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
LoggerConfig loggerConfig = getLoggerConfig(ctx, category);
if (loggerConfig != null) {
boolean madeChanges = false;
if (level == null || "unset".equals(level) || "null".equals(level)) {
level = Level.OFF.toString();
loggerConfig.setLevel(Level.OFF);
madeChanges = true;
} else {
try {
loggerConfig.setLevel(Level.valueOf(level));
madeChanges = true;
} catch (IllegalArgumentException iae) {
watcherLog.error(level+" is not a valid log level! Valid values are: "+getAllLevels());
}
}
if (madeChanges) {
ctx.updateLoggers();
watcherLog.info("Set log level to '" + level + "' for category: " + category);
}
} else {
watcherLog.warn("Cannot set level to '" + level + "' for category: " + category + "; no LoggerConfig found!");
}
}
示例7: setupLogging
import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
private void setupLogging() {
Level level = Level.getLevel(logLevel.name());
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
// Setup the root logger to the requested log level
LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
loggerConfig.setLevel(level);
// Dump the requests/responses when requested
if (logRequests) {
loggerConfig = config.getLoggerConfig("org.apache.cxf.services");
if (level.isLessSpecificThan(Level.INFO)) {
loggerConfig.setLevel(level);
} else {
loggerConfig.setLevel(Level.INFO);
}
}
ctx.updateLoggers();
}
示例8: setLevel
import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
public static void setLevel(Level level) {
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
loggerConfig.setLevel(level);
ctx.updateLoggers();
if (level == Level.ERROR) {
logger.error("<- This level is successfully initialized");
}
if (level == Level.WARN) {
logger.warn("<- This level is successfully initialized");
}
if (level == Level.DEBUG) {
logger.debug("<- This level is successfully initialized");
}
if (level == Level.INFO) {
logger.info("<- This level is successfully initialized");
}
}
示例9: addFileAppender
import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
public static void addFileAppender(final String loggerPath, final File logFile, final AppConfig appConfig)
throws IOException
{
// retrieve the logger context
LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
Configuration configuration = loggerContext.getConfiguration();
// retrieve the root logger config
LoggerConfig loggerConfig = configuration.getLoggerConfig(loggerPath);
loggerConfig.setLevel(Level.toLevel(appConfig.getTcLogLevel()));
// Define log pattern layout
PatternLayout layout = PatternLayout.createLayout(DEFAULT_LOGGER_PATTERN, null, null, null,
Charset.defaultCharset(), false, false, null, null);
// create the appenders
FileAppender fileAppender =
FileAppender.createAppender(logFile.getAbsolutePath(), "true", "false", "fileAppender",
"true", "true", "true", "8192", layout, null, "false", null, null);
fileAppender.start();
// add the appenders
loggerConfig.addAppender(fileAppender, Level.toLevel(appConfig.getTcLogLevel()), null);
loggerContext.updateLoggers();
}
示例10: addServerAppender
import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
public static void addServerAppender(final String loggerPath, final AppConfig appConfig)
throws IOException
{
// retrieve the logger context
LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
Configuration configuration = loggerContext.getConfiguration();
// retrieve the root logger config
LoggerConfig loggerConfig = configuration.getLoggerConfig(loggerPath);
loggerConfig.setLevel(Level.toLevel(appConfig.getTcLogLevel()));
// create the appenders
ServerLoggerAppender serverLoggerAppender = ServerLoggerAppender.createAppender("serverLoggerAppender");
serverLoggerAppender.start();
// add the appenders
loggerConfig.addAppender(serverLoggerAppender, Level.toLevel(appConfig.getTcLogLevel()), null);
loggerContext.updateLoggers();
}
示例11: main
import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception{
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
loggerConfig.setLevel(Level.DEBUG);
ctx.updateLoggers();
MultiLabelClfDataSet dataSet = TRECFormat.loadMultiLabelClfDataSet(new File(DATASETS, "scene/train"),
DataSetType.ML_CLF_DENSE, true);
MultiLabelClfDataSet testSet = TRECFormat.loadMultiLabelClfDataSet(new File(DATASETS, "scene/test"),
DataSetType.ML_CLF_DENSE, true);
AugmentedLR augmentedLR = new AugmentedLR(dataSet.getNumFeatures(), 1);
double[][] gammas = new double[dataSet.getNumDataPoints()][1];
for (int i=0;i<dataSet.getNumDataPoints();i++){
gammas[i][0]=1;
}
AugmentedLRLoss loss = new AugmentedLRLoss(dataSet, 0, gammas, augmentedLR, 1, 1);
LBFGS lbfgs = new LBFGS(loss);
for (int i=0;i<100;i++){
lbfgs.iterate();
System.out.println(loss.getValue());
}
}
示例12: resetLevel
import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
@Test
public void resetLevel() {
logger.entry();
List<LogEvent> events = app.getEvents();
assertTrue("Incorrect number of events. Expected 1, actual " + events.size(), events.size() == 1);
app.clear();
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
final LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
/* You could also specify the actual logger name as below and it will return the LoggerConfig used by the Logger.
LoggerConfig loggerConfig = getLoggerConfig("com.apache.test");
*/
loggerConfig.setLevel(Level.DEBUG);
ctx.updateLoggers(); // This causes all Loggers to refetch information from their LoggerConfig.
logger.entry();
events = app.getEvents();
assertTrue("Incorrect number of events. Expected 0, actual " + events.size(), events.size() == 0);
app.clear();
}
示例13: CustomConfiguration
import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
/**
* Constructor to create the default configuration.
*/
public CustomConfiguration(final LoggerContext loggerContext, final ConfigurationSource source) {
super(loggerContext, source);
setName(CONFIG_NAME);
final Layout<? extends Serializable> layout = PatternLayout.newBuilder()
.withPattern(DEFAULT_PATTERN)
.withConfiguration(this)
.build();
final Appender appender = ConsoleAppender.createDefaultAppenderForLayout(layout);
appender.start();
addAppender(appender);
final LoggerConfig root = getRootLogger();
root.addAppender(appender, null, null);
final String levelName = PropertiesUtil.getProperties().getStringProperty(DEFAULT_LEVEL);
final Level level = levelName != null && Level.valueOf(levelName) != null ?
Level.valueOf(levelName) : Level.ERROR;
root.setLevel(level);
}
示例14: resetLevel
import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
@Test
public void resetLevel() {
final org.apache.logging.log4j.Logger logger = context.getLogger("com.apache.test");
logger.traceEntry();
List<LogEvent> events = app.getEvents();
assertEquals("Incorrect number of events. Expected 1, actual " + events.size(), 1, events.size());
app.clear();
final LoggerContext ctx = LoggerContext.getContext(false);
final Configuration config = ctx.getConfiguration();
final LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
/* You could also specify the actual logger name as below and it will return the LoggerConfig used by the Logger.
LoggerConfig loggerConfig = getLoggerConfig("com.apache.test");
*/
loggerConfig.setLevel(Level.DEBUG);
ctx.updateLoggers(); // This causes all Loggers to refetch information from their LoggerConfig.
logger.traceEntry();
events = app.getEvents();
assertEquals("Incorrect number of events. Expected 0, actual " + events.size(), 0, events.size());
}
示例15: initLogging
import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
public static void initLogging(final Level level) {
loglevel = level;
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
final LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
loggerConfig.setLevel(level);
ctx.updateLoggers();
}