0

I am using the following code to programatically configure my logging config:

 public static void configureLoggers() {
  ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder();

  builder.setStatusLevel(Level.DEBUG);
  builder.setConfigurationName("ConfigName");

  AppenderComponentBuilder consoleAppenderBuilder = builder.newAppender("Stdout", "CONSOLE");
  consoleAppenderBuilder.add(builder.newLayout("PatternLayout").addAttribute("pattern", "%m%n"));

  builder.add(consoleAppenderBuilder);

  RootLoggerComponentBuilder rootLoggerBuilder = builder.newRootLogger(LEVEL.DEBUG);
  rootLoggerBuilder.add(builder.newAppenderRef("Stdout")).addAttribute("additivity", true);
  builder.add(rootLoggerBuilder);

  LoggerContext.getContext(false).start(builder.build());
 }

I need to turn off logging for specific java packages in my projects; like org.glassfish. How do I do that?

Swaranga Sarma
  • 13,055
  • 19
  • 60
  • 93

2 Answers2

2

Assuming the org.glassfish loggers are obtaining their loggers using the class name as the logger name then you just need to add another logger to your configuration with "org.glassfish" as the logger name and then set it to whatever level you want it to filter at. If you don't specify an AppenderRef and it is set to additivity "true" (the default) then the events will automatically go to the root logger's appender.

rgoers
  • 8,696
  • 1
  • 22
  • 24
0

Found it:

builder.add(builder.newLogger("org.glassfish", Level.OFF));
Swaranga Sarma
  • 13,055
  • 19
  • 60
  • 93