You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Remko Popma (JIRA)" <ji...@apache.org> on 2017/03/26 12:57:41 UTC
[jira] [Comment Edited] (LOG4J2-1857) Listing all Loggers via JMX
[ https://issues.apache.org/jira/browse/LOG4J2-1857?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15942265#comment-15942265 ]
Remko Popma edited comment on LOG4J2-1857 at 3/26/17 12:57 PM:
---------------------------------------------------------------
Does this work for you?
{code}
String serviceUrl = args[0]; // "host:port"
if (!serviceUrl.startsWith("service:jmx")) {
serviceUrl = "service:jmx:rmi:///jndi/rmi://" + args[0] + "/jmxrmi";
}
JMXServiceURL url = new JMXServiceURL(serviceUrl);
Properties props = System.getProperties();
Map<String, String> paramMap = new HashMap<>(props.size());
for (String key : props.stringPropertyNames()) {
paramMap.put(key, props.getProperty(key));
}
JMXConnector connector = JMXConnectorFactory.connect(url, paramMap);
Client client = new Client(connector);
MBeanServerConnection mbs = client.getConnection();
for (LoggerContextAdminMBean ctx : client.getLoggerContextAdmins()) {
String search = String.format(LoggerConfigAdminMBean.PATTERN, ctx.getName(), "*");
ObjectName pattern = new ObjectName(search);
Set<ObjectName> found = mbs.queryNames(pattern, null);
for (ObjectName objectName : found) {
LoggerConfigAdminMBean proxy = JMX.newMBeanProxy(connection, //
objectName, //
LoggerConfigAdminMBean.class, true); // notificationBroadcaster
// TODO your logic here
}
}
{code}
was (Author: remkop@yahoo.com):
Does this work for you?
{code}
String serviceUrl = args[0]; // "host:port"
if (!serviceUrl.startsWith("service:jmx")) {
serviceUrl = "service:jmx:rmi:///jndi/rmi://" + args[0] + "/jmxrmi";
}
final JMXServiceURL url = new JMXServiceURL(serviceUrl);
final Properties props = System.getProperties();
final Map<String, String> paramMap = new HashMap<>(props.size());
for (final String key : props.stringPropertyNames()) {
paramMap.put(key, props.getProperty(key));
}
final JMXConnector connector = JMXConnectorFactory.connect(url, paramMap);
final Client client = new Client(connector);
MBeanServerConnection mbs = client.getConnection();
for (final LoggerContextAdminMBean ctx : client.getLoggerContextAdmins()) {
String search = String.format(LoggerConfigAdminMBean.PATTERN, ctx.getName(), "*");
ObjectName pattern = new ObjectName(search);
Set<ObjectName> found = mbs.queryNames(pattern, null);
for (final ObjectName objectName : found) {
final LoggerConfigAdminMBean proxy = JMX.newMBeanProxy(connection, //
objectName, //
LoggerConfigAdminMBean.class, true); // notificationBroadcaster
// TODO your logic here
}
}
{code}
> Listing all Loggers via JMX
> ---------------------------
>
> Key: LOG4J2-1857
> URL: https://issues.apache.org/jira/browse/LOG4J2-1857
> Project: Log4j 2
> Issue Type: Question
> Components: JMX
> Affects Versions: 2.6.1
> Reporter: Izek Greenfield
>
> How can I list all loggers via JMX / jolokia?
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org