本文整理汇总了Java中org.apache.logging.log4j.core.config.LoggerConfig类的典型用法代码示例。如果您正苦于以下问题:Java LoggerConfig类的具体用法?Java LoggerConfig怎么用?Java LoggerConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LoggerConfig类属于org.apache.logging.log4j.core.config包,在下文中一共展示了LoggerConfig类的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: updateLoggerLevel
import org.apache.logging.log4j.core.config.LoggerConfig; //导入依赖的package包/类
/**
* Looks up the logger in the logger factory,
* and attempts to find the real logger instance
* based on the underlying logging framework
* and retrieve the logger object. Then, updates the level.
* This functionality at this point is heavily dependant
* on the log4j API.
*
* @param loggerName the logger name
* @param loggerLevel the logger level
* @param additive the additive nature of the logger
* @param request the request
* @param response the response
* @throws Exception the exception
*/
@PostMapping(value = "/updateLoggerLevel")
@ResponseBody
public void updateLoggerLevel(@RequestParam final String loggerName,
@RequestParam final String loggerLevel,
@RequestParam(defaultValue = "false") final boolean additive,
final HttpServletRequest request,
final HttpServletResponse response) throws Exception {
ensureEndpointAccessIsAuthorized(request, response);
Assert.notNull(this.loggerContext);
final Collection<LoggerConfig> loggerConfigs = getLoggerConfigurations();
loggerConfigs.stream().
filter(cfg -> cfg.getName().equals(loggerName))
.forEachOrdered(cfg -> {
cfg.setLevel(Level.getLevel(loggerLevel));
cfg.setAdditive(additive);
});
this.loggerContext.updateLoggers();
}
示例3: registerParent
import org.apache.logging.log4j.core.config.LoggerConfig; //导入依赖的package包/类
protected final void registerParent(Class<? extends BaseLog4j2Configuration> clazz){
BaseLog4j2Configuration configuration;
try{
configuration = clazz.newInstance();
}catch(InstantiationException | IllegalAccessException e){
throw new RuntimeException(e);
}
for(Appender appender : configuration.getAppenders()){
addAppender(appender);
}
for(LoggerConfig loggerConfig : configuration.getLoggerConfigs()){
addLoggerConfig(loggerConfig.getName(), loggerConfig.getLevel(), loggerConfig.isAdditive(), loggerConfig
.getAppenders().values());
}
for(Filter filter : configuration.getFilters()){
addFilter(filter);
}
}
示例4: 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();
}
示例5: removeAlertListener
import org.apache.logging.log4j.core.config.LoggerConfig; //导入依赖的package包/类
public synchronized boolean removeAlertListener(final DistributedMember member) {
final boolean memberWasFound = this.listeners.remove(new Listener(null, member));
if (memberWasFound) {
if (this.listeners.size() == 0) {
this.appenderContext.getLoggerContext().removePropertyChangeListener(this);
this.appenderContext.getLoggerConfig().removeAppender(APPENDER_NAME);
} else {
LoggerConfig loggerConfig = this.appenderContext.getLoggerConfig();
loggerConfig.addAppender(this, this.listeners.get(0).getLevel(), null);
}
if (logger.isDebugEnabled()) {
logger.debug("Removed alert listener for member {}", member);
}
}
return memberWasFound;
}
示例6: getOrCreateLoggerConfig
import org.apache.logging.log4j.core.config.LoggerConfig; //导入依赖的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;
}
示例7: hasLoggerFilter
import org.apache.logging.log4j.core.config.LoggerConfig; //导入依赖的package包/类
public static boolean hasLoggerFilter(final Configuration config) {
for (LoggerConfig loggerConfig : config.getLoggers().values()) {
boolean isRoot = loggerConfig.getName().equals("");
boolean isGemFire = loggerConfig.getName().startsWith(LogService.BASE_LOGGER_NAME);
boolean hasFilter = loggerConfig.hasFilter();
boolean isGemFireVerboseFilter =
hasFilter && (LogService.GEODE_VERBOSE_FILTER.equals(loggerConfig.getFilter().toString())
|| LogService.GEMFIRE_VERBOSE_FILTER.equals(loggerConfig.getFilter().toString()));
if (isRoot || isGemFire) {
// check for Logger Filter
if (hasFilter && !isGemFireVerboseFilter) {
return true;
}
}
}
return false;
}
示例8: hasAppenderRefFilter
import org.apache.logging.log4j.core.config.LoggerConfig; //导入依赖的package包/类
public static boolean hasAppenderRefFilter(final Configuration config) {
for (LoggerConfig loggerConfig : config.getLoggers().values()) {
boolean isRoot = loggerConfig.getName().equals("");
boolean isGemFire = loggerConfig.getName().startsWith(LogService.BASE_LOGGER_NAME);
if (isRoot || isGemFire) {
// check for AppenderRef Filter
for (AppenderRef appenderRef : loggerConfig.getAppenderRefs()) {
if (appenderRef.getFilter() != null) {
return true;
}
}
}
}
return false;
}
示例9: addSuspectFileAppender
import org.apache.logging.log4j.core.config.LoggerConfig; //导入依赖的package包/类
/**
* Add an appender to Log4j which sends all INFO+ messages to a separate file which will be used
* later to scan for suspect strings. The pattern of the messages conforms to the original log
* format so that hydra will be able to parse them.
*/
private static void addSuspectFileAppender(final String workspaceDir) {
final String suspectFilename = new File(workspaceDir, SUSPECT_FILENAME).getAbsolutePath();
final LoggerContext appenderContext =
((org.apache.logging.log4j.core.Logger) LogManager.getLogger(LogService.BASE_LOGGER_NAME))
.getContext();
final PatternLayout layout = PatternLayout.createLayout(
"[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} <%thread> tid=%tid] %message%n%throwable%n",
null, null, null, Charset.defaultCharset(), true, false, "", "");
final FileAppender fileAppender = FileAppender.createAppender(suspectFilename, "true", "false",
DUnitLauncher.class.getName(), "true", "false", "false", "0", layout, null, null, null,
appenderContext.getConfiguration());
fileAppender.start();
LoggerConfig loggerConfig =
appenderContext.getConfiguration().getLoggerConfig(LogService.BASE_LOGGER_NAME);
loggerConfig.addAppender(fileAppender, Level.INFO, null);
}
示例10: 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();
}
示例11: addFileAppender
import org.apache.logging.log4j.core.config.LoggerConfig; //导入依赖的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();
}
示例12: 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);
}
示例13: configureLogging
import org.apache.logging.log4j.core.config.LoggerConfig; //导入依赖的package包/类
protected void configureLogging() {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
Layout layout = PatternLayout.createLayout(PatternLayout.SIMPLE_CONVERSION_PATTERN, null, config, null, null,
true, false, null, null);
Appender appender = FileAppender.createAppender(workDir + "/logs/camel-standalone.log", "false", "false", "File", "true",
"false", "false", "4000", layout, null, "false", null, config);
appender.start();
config.addAppender(appender);
AppenderRef ref = AppenderRef.createAppenderRef("File", null, null);
AppenderRef[] refs = new AppenderRef[] {ref};
LoggerConfig loggerConfig = LoggerConfig.createLogger("false", Level.INFO, "StandaloneFileLoggerConfig",
"true", refs, null, config, null );
loggerConfig.addAppender(appender, null, null);
config.addLogger("StandaloneFileLoggerConfig", loggerConfig);
ctx.updateLoggers();
}
示例14: configureLog4j
import org.apache.logging.log4j.core.config.LoggerConfig; //导入依赖的package包/类
private static Logger configureLog4j() {
LoggerContext context = (LoggerContext) LogManager.getContext();
Configuration config = context.getConfiguration();
PatternLayout layout = PatternLayout.createLayout("%m%n", null, null, Charset.defaultCharset(), false, false, null, null);
Appender appender = ConsoleAppender.createAppender(layout, null, null, "CONSOLE_APPENDER", null, null);
appender.start();
AppenderRef ref = AppenderRef.createAppenderRef("CONSOLE_APPENDER", null, null);
AppenderRef[] refs = new AppenderRef[]{ref};
LoggerConfig loggerConfig = LoggerConfig.createLogger("false", Level.INFO, "CONSOLE_LOGGER", "com", refs, null, null, null);
loggerConfig.addAppender(appender, null, null);
config.addAppender(appender);
config.addLogger("Main.class", loggerConfig);
context.updateLoggers(config);
return LogManager.getContext().getLogger("Main.class");
}
示例15: 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();
}