本文整理汇总了Java中org.apache.logging.log4j.core.LoggerContext.getConfiguration方法的典型用法代码示例。如果您正苦于以下问题:Java LoggerContext.getConfiguration方法的具体用法?Java LoggerContext.getConfiguration怎么用?Java LoggerContext.getConfiguration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.logging.log4j.core.LoggerContext
的用法示例。
在下文中一共展示了LoggerContext.getConfiguration方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: changeLogLevel
import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的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: toggleCleanLogging
import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
private void toggleCleanLogging() {
this.cleanLogging = !cleanLogging;
interactionHandler.sendText("clean logging: " + cleanLogging);
String appenderToAdd = cleanLogging ? "Clean" : "Console";
String appenderToRemove = cleanLogging ? "Console" : "Clean";
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
for (org.apache.logging.log4j.core.Logger logger : ctx.getLoggers()) {
logger.removeAppender(config.getAppender(appenderToRemove));
config.addLoggerAppender(logger, config.getAppender(appenderToAdd));
}
ctx.updateLoggers();
}
示例3: getOrCreateLoggerConfig
import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
public static LoggerConfig getOrCreateLoggerConfig(String name) {
LoggerContext context = (LoggerContext) LogManager.getContext(false);
Configuration config = context.getConfiguration();
LoggerConfig logConfig = config.getLoggerConfig(name);
boolean update = false;
if (!logConfig.getName().equals(name)) {
List<AppenderRef> appenderRefs = logConfig.getAppenderRefs();
Map<Property, Boolean> properties = logConfig.getProperties();
Set<Property> props = properties == null ? null : properties.keySet();
logConfig = LoggerConfig.createLogger(String.valueOf(logConfig.isAdditive()),
logConfig.getLevel(), name, String.valueOf(logConfig.isIncludeLocation()),
appenderRefs == null ? null : appenderRefs.toArray(new AppenderRef[appenderRefs.size()]),
props == null ? null : props.toArray(new Property[props.size()]), config, null);
config.addLogger(name, logConfig);
update = true;
}
if (update) {
context.updateLoggers();
}
return logConfig;
}
示例4: main
import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
public static void main(String[] args) {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
config.getLoggerConfig(strategy.Portfolio.class.getName()).setLevel(Level.WARN);
ctx.updateLoggers(config);
final CommonParam cp = ParamManager.getCommonParam("i", TIME_FRAME.MIN15, "20080101 000000", "20160101 170000");
StrategyOptimizer so = new StrategyOptimizer(tester.RealStrategyTester.class);
so.setInstrumentParam(cp.instrument, cp.tf);
so.setTestDateRange((int) DateTimeHelper.Ldt2Long(cp.start_date), (int) DateTimeHelper.Ldt2Long(cp.end_date));
int num = so.setStrategyParamRange(MaPsarStrategy.class, new Integer[]{12, 500, 2}, new String[]{MA.MODE_EMA, MA.MODE_SMMA}, new APPLIED_PRICE[] {APPLIED_PRICE.PRICE_CLOSE, APPLIED_PRICE.PRICE_TYPICAL}, new Float[]{0.01f, 0.02f, 0.01f}, new Float[]{0.1f, 0.2f, 0.02f});
System.out.println(num);
so.StartOptimization();
Set<Entry<Object[],Performances>> entryset = so.result_db.entrySet();
for (Entry<Object[],Performances> entry : entryset) {
for (Object obj : entry.getKey()) {
System.out.print(obj + ",\t");
}
System.out.println("ProfitRatio: " + String.format("%.5f", entry.getValue().ProfitRatio) + "\tMaxDrawDown: " + entry.getValue().MaxDrawDown);
}
}
示例5: main
import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
public static void main(String[] args) {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
config.getLoggerConfig(strategy.Portfolio.class.getName()).setLevel(Level.WARN);
ctx.updateLoggers(config);
final CommonParam cp = ParamManager.getCommonParam("m", TIME_FRAME.MIN60, "19980101 000000", "20160101 170000");
StrategyOptimizer so = new StrategyOptimizer(tester.RealStrategyTester.class);
so.setInstrumentParam(cp.instrument, cp.tf);
so.setTestDateRange((int) DateTimeHelper.Ldt2Long(cp.start_date), (int) DateTimeHelper.Ldt2Long(cp.end_date));
int num = so.setStrategyParamRange(DblMaPsarStrategy.class, new Integer[]{3, 5, 1}, new Integer[]{10, 100, 2}, MA.MA_MODES, new APPLIED_PRICE[] {APPLIED_PRICE.PRICE_CLOSE, APPLIED_PRICE.PRICE_TYPICAL}, new Float[]{0.01f, 0.02f, 0.01f}, new Float[]{0.12f, 0.2f, 0.02f});
System.out.println(num);
so.StartOptimization();
Set<Entry<Object[],Performances>> entryset = so.result_db.entrySet();
for (Entry<Object[],Performances> entry : entryset) {
for (Object obj : entry.getKey()) {
System.out.print(obj + ",\t");
}
System.out.println("ProfitRatio: " + String.format("%.5f", entry.getValue().ProfitRatio) + "\tMaxDrawDown: " + entry.getValue().MaxDrawDown);
}
}
示例6: main
import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
public static void main(String[] args) {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
config.getLoggerConfig(strategy.Portfolio.class.getName()).setLevel(Level.WARN);
ctx.updateLoggers(config);
final CommonParam cp = ParamManager.getCommonParam("cu", TIME_FRAME.MIN15, "20080101 000000", "20160101 170000");
StrategyOptimizer so = new StrategyOptimizer(tester.RealStrategyTester.class);
so.setInstrumentParam(cp.instrument, cp.tf);
so.setTestDateRange((int) DateTimeHelper.Ldt2Long(cp.start_date), (int) DateTimeHelper.Ldt2Long(cp.end_date));
int num = so.setStrategyParamRange(MABreakStrategy.class, new Integer[]{8, 800, 2}, MA.MA_MODES);
System.out.println(num);
so.StartOptimization();
Set<Entry<Object[],Performances>> entryset = so.result_db.entrySet();
for (Entry<Object[],Performances> entry : entryset) {
for (Object obj : entry.getKey()) {
System.out.print(obj + ",\t");
}
System.out.println("ProfitRatio: " + String.format("%.5f", entry.getValue().ProfitRatio) + "\tMaxDrawDown: " + entry.getValue().MaxDrawDown);
}
}
示例7: addFileAppender
import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
private static void addFileAppender() throws IOException {
final String tempDir = System.getProperty("java.io.tmpdir");
final File logFile = new File(tempDir, "meghanada_server.log");
final LoggerContext context = (LoggerContext) LogManager.getContext(false);
final Configuration configuration = context.getConfiguration();
final LoggerConfig loggerConfig = configuration.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
final FileAppender fileAppender =
FileAppender.newBuilder()
.withName("file")
.withLayout(
PatternLayout.newBuilder()
.withPattern("[%d][%-5.-5p][%-14.-14c{1}:%4L] %-22.-22M - %m%n")
.build())
.withFileName(logFile.getCanonicalPath())
.build();
configuration.addAppender(fileAppender);
loggerConfig.addAppender(fileAppender, Level.ERROR, null);
context.updateLoggers();
}
示例8: updateLogConfig
import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
/**
* Update the log configuration based on command line options
*
* @param cl
*/
protected final void updateLogConfig(CommandLine cl) {
String logFile = cl.getOptionValue(OPT_LOG_FILE.getLongOpt(), null);
String logLevel = cl.getOptionValue(OPT_LOG_LEVEL.getLongOpt(), null);
if (logFile != null || logLevel != null) {
logFile = logFile != null ? logFile : getDefaultLogFileName();
logLevel = logLevel != null ? logLevel : DEFAULT_LOG_LEVEL;
LoggerContext context = (LoggerContext) LogManager.getContext(false);
Configuration configuration = context.getConfiguration();
FileAppender appender = FileAppender.newBuilder()
.withName("File")
.withFileName(logFile)
.withLayout(PatternLayout.newBuilder().withPattern(PatternLayout.SIMPLE_CONVERSION_PATTERN).build())
.withAppend(false)
.build();
appender.start();
configuration.getRootLogger().addAppender(appender, Level.getLevel(logLevel), null);
configuration.getRootLogger().setLevel(Level.getLevel(logLevel));
context.updateLoggers();
}
}
示例9: bindLogger
import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
public static void bindLogger() {
LoggerContext context = (LoggerContext) LogManager.getContext(false);
Configuration config = context.getConfiguration();
Map<String, ESLogger> loggers = Maps.newConcurrentHashMap();
Appender appender = new AbstractAppender("", null, null) {
@Override
public void append(LogEvent event) {
String name = event.getLoggerName();
ESLogger logger = loggers.computeIfAbsent(name, key -> new ESLogger(key, null, (LoggerImpl) LoggerFactory.getLogger(key)));
logger.log(event.getLevel(), event.getMarker(), event.getMessage(), event.getThrown());
}
};
appender.start();
config.addAppender(appender);
LoggerConfig loggerConfig = new LoggerConfig("", Level.ALL, false);
loggerConfig.addAppender(appender, null, null);
config.addLogger("", loggerConfig);
context.updateLoggers();
}
示例10: setUpAppender
import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
@Before
public void setUpAppender() throws IOException {
file = folder.newFile();
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
final LoggerConfig root = ((AbstractConfiguration) config).getRootLogger();
PatternLayout layout = PatternLayout.createLayout("[%p] %m%n", config, null, null, true, false, null, null);
FileAppender appender = FileAppender.createAppender(file.getAbsolutePath(), "true", "false", "TestLogFile", "true", "false", "false", "8192", layout, null, "false", null, config);
appender.start();
config.addAppender(appender);
root.addAppender(appender, null, null);
ctx.updateLoggers();
}
示例11: testReadException
import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的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();
}
示例12: addLoggingWriterAppender
import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
@Override
public StringWriter addLoggingWriterAppender(String appenderName)
{
// Get the configuration
final LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
final Configuration configuration = loggerContext.getConfiguration();
// Create a string writer as part of the appender so logging will be written to it.
StringWriter stringWriter = new StringWriter();
// Create and start the appender with the string writer.
Appender appender = WriterAppender.createAppender(null, null, stringWriter, appenderName, false, true);
appender.start();
// Add the appender to the root logger.
configuration.getRootLogger().addAppender(appender, null, null);
// Return the string writer.
return stringWriter;
}
示例13: createFileAppender
import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
private void createFileAppender(DiagnosticContext ctx) {
String logDir = ctx.getTempDir() + SystemProperties.fileSeparator + "diagnostics.log";
final LoggerContext context = (LoggerContext) LogManager.getContext(false);
final Configuration config = context.getConfiguration();
Layout layout = PatternLayout.createLayout("%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n", null, config, null,
null,true, true, null, null );
Appender appender = FileAppender.createAppender(logDir, "false", "false", "File", "true",
"false", "false", "0", layout, null, "false", null, config);
appender.start();
config.addAppender(appender);
AppenderRef ref = AppenderRef.createAppenderRef("File", null, null);
AppenderRef[] refs = new AppenderRef[] {ref};
config.getRootLogger().addAppender(appender, null, null);
context.updateLoggers();
Logger testLog = LogManager.getLogger();
testLog.error("Testing");
}
示例14: setLevel
import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的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");
}
}
示例15: addFileAppender
import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的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();
}