Show Table of Contents
17.3. Change the logging level at runtime
The logging level of the broker can be changed at runtime, without restarting. This is useful to increase the level of logging detail while debugging, then return it to a lower level.
The Qpid Management Framework Broker object has a
setLogLevel method to control the logging level. The following C++ code demonstrates calling this method to set the logging level.
#include <qpid/messaging/Connection.h>
#include <qpid/messaging/Session.h>
#include <qpid/messaging/Sender.h>
#include <qpid/messaging/Receiver.h>
#include <qpid/messaging/Message.h>
#include <qpid/messaging/Address.h>
#include <iostream>
using namespace std;
using namespace qpid::messaging;
using namespace qpid::types;
int main(int argc, char** argv) {
if (argc < 2) {
cerr << "Invalid number of parameters, expecting log level (info, trace, warning or so)" << endl;
return 1;
}
string log_level = argv[1];
Connection connection(argc>2?argv[2]:"localhost:5672");
connection.open();
Session session = connection.createSession();
Sender sender = session.createSender("qmf.default.direct/broker");
Receiver receiver = session.createReceiver("#reply-queue; {create:always, node:{x-declare:{auto-delete:true}}}");
Address responseQueue = receiver.getAddress();
Message message;
Variant::Map content;
Variant::Map OID;
Variant::Map arguments;
OID["_object_name"] = "org.apache.qpid.broker:broker:amqp-broker";
arguments["level"] = log_level;
content["_object_id"] = OID;
content["_method_name"] = "setLogLevel";
content["_arguments"] = arguments;
message.setContentObject(content);
message.setReplyTo(responseQueue);
message.setProperty("x-amqp-0-10.app-id", "qmf2");
message.setProperty("qmf.opcode", "_method_request");
message.setContentType("amqp/map");
sender.send(message, true);
/* receive a response from the broker & check our request was successfully processed */
Message response;
if (receiver.fetch(response,qpid::messaging::Duration(30000)) == true) {
qpid::types::Variant::Map recv_props = response.getProperties();
if (recv_props["qmf.opcode"] == "_method_response")
std::cout << "Response: OK" << std::endl;
else if (recv_props["qmf.opcode"] == "_exception")
std::cerr << "Error: " << response.getContent() << std::endl;
else
std::cerr << "Invalid response received!" << std::endl;
}
else
std::cout << "Timeout: No response received within 30 seconds!" << std::endl;
receiver.close();
sender.close();
session.close();
connection.close();
return 0;
}- Save the example code to a file
set_log_level.cpp. - Modify the Connection URL in the code to resolve to your broker. At the moment it is set to connect to a broker running on port 5672 on the local machine.
- Compile the example code:
g++ -Wall -lqpidclient -lqpidcommon -lqpidmessaging -lqpidtypes -o set_log_level set_log_level.cpp
- Use the complied program to change the log level of the broker:
./set_log_level "trace+"
- To observe the change in the logging level, tail the server log as you run the program.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.