Skip to content

Instantly share code, notes, and snippets.

@gronono
Created May 12, 2016 10:01
Show Gist options
  • Save gronono/341cffa694642891d2f695a88a48e4f3 to your computer and use it in GitHub Desktop.
Save gronono/341cffa694642891d2f695a88a48e4f3 to your computer and use it in GitHub Desktop.
LogBack start JMXConfigurator without XML
@Configuration
public class LogbackConfig {
@Autowired
private MBeanServer mbeanServer;
@PostConstruct
public void registerJmxConfigurator() throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException, MalformedObjectNameException {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
ObjectName objectName = new ObjectName(MBeanUtil.getObjectNameFor(loggerContext.getName(), JMXConfigurator.class));
JMXConfigurator jc = new JMXConfigurator(loggerContext, mbeanServer, objectName);
mbeanServer.registerMBean(jc, objectName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment