How to change Log level of qpid-broker-core

232 Views Asked by At

We are starting qpid broker from java code. Library used is qpid-broker-core, qpid-broker-plugins-amqp-1-0-protocol, qpid-broker-plugins-management-http.

Map<String, Object> attributes = new HashMap<>();
        attributes.put("type", "Memory");
        attributes.put("qpid.broker.defaultPreferenceStoreAttributes", "{\"type\": \"Noop\"}");

        String resourcePath = findResourcePath("initial-config.json");
        attributes.put("initialConfigurationLocation", resourcePath);
        attributes.put("startupLoggedToSystemOut", "false");

        System.setProperty("qpid.tests.mms.messagestore.persistence", "true");
        System.setProperty("qpid.amqp_port", port);
        System.setProperty("qpid.http_port", hport);

        try {
            URL.setURLStreamHandlerFactory(protocol -> ("classpath".equals(protocol) ? new Handler() : null));
        } catch (final Error ignored) {
            // Java is ridiculous and doesn't allow setting the factory if it's already been set
        }

        try {
            LOGGER.info("*** Starting QPID Broker....");
            broker.startup(attributes);
            LOGGER.info("*** QPID Broker started.");
}

We can see debug log is enabled. All startup logs are getting printed in console. How to change log level to WARN.

Initial config json looks like

{
  "name": "EmbeddedBroker",
  "modelVersion": "8.0",
  "authenticationproviders": [
    {
      "name": "anonymous",
      "type": "Anonymous"
    }
  ],
  "ports": [
    {
      "name": "AMQP",
      "bindingAddress": "localhost",
      "port": "${qpid.amqp_port}",
      "protocols": [ "AMQP_1_0" ],
      "authenticationProvider": "anonymous",
      "virtualhostaliases" : [ {
        "name" : "nameAlias",
        "type" : "nameAlias"
      }, {
        "name" : "defaultAlias",
        "type" : "defaultAlias"
      }, {
        "name" : "hostnameAlias",
        "type" : "hostnameAlias"
      } ]
    },
    {
      "name" : "HTTP",
      "port" : "${qpid.http_port}",
      "protocols" : [ "HTTP" ],
      "authenticationProvider" : "anonymous"
    }
  ],
  "virtualhostnodes": [
    {
      "name": "default",
      "defaultVirtualHostNode": "true",
      "type": "Memory",
      "virtualHostInitialConfiguration": "{\"type\": \"Memory\" }"
    }
  ],
  "plugins" : [
    {
      "type" : "MANAGEMENT-HTTP",
      "name" : "httpManagement"
    }
  ]
}

Tried adding brokerloggers in initial config json. but not working.

1

There are 1 best solutions below

0
Daniil On

In config.json log level is defined by field "brokerloginclusionrules":

"brokerloggers" : [ {
    "name" : "logfile",
    "type" : "File",
    "fileName" : "${qpid.work_dir}${file.separator}log${file.separator}qpid.log",
    "brokerloginclusionrules" : [ {
      "name" : "Root",
      "type" : "NameAndLevel",
      "level" : "WARN",
      "loggerName" : "ROOT"
    }, {
      "name" : "Qpid",
      "type" : "NameAndLevel",
      "level" : "INFO",
      "loggerName" : "org.apache.qpid.*"
    }, {
      "name" : "Operational",
      "type" : "NameAndLevel",
      "level" : "INFO",
      "loggerName" : "qpid.message.*"
    }, {
      "name" : "Statistics",
      "type" : "NameAndLevel",
      "level" : "INFO",
      "loggerName" : "qpid.statistics.*"
    } ]
  }
]

See documentation for complete example.

You could also read and update log level in runtime using broker-j REST API.

E.g. this curl command will return the list of broker loggers:

curl http://<USERNAME>:<PASSWORD>@<HOSTNAME>:<PORT>/api/latest/brokerlogger

This curl command will return the list of broker log inclusion rules:

curl http://<USERNAME>:<PASSWORD>@<HOSTNAME>:<PORT>/api/latest/brokerinclusionrule

This curl command will change log level of a log inclusion rule specified:

curl --data '{"level": "INFO"}' http://<USERNAME>:<PASSWORD>@<HOSTNAME>:<PORT>/api/latest/brokerinclusionrule/<BROKER_LOGGER_NAME>/<BROKER_LOG_INCLUSION_RULE_NAME>