apache / rocketmq-client-cpp

Apache RocketMQ cpp client
https://rocketmq.apache.org/
Apache License 2.0
364 stars 158 forks source link

How to export the debug information of the consumer? #391

Closed fengxiao2019 closed 2 years ago

fengxiao2019 commented 2 years ago

I set the log level to DEBUG via the function SetPushConsumerLogLevel, i can see the produced logs. but I don't see the debug log of the relevant consumer in the log file.

I use the rocketmq-client-python to set the log level. the code like this:

class PushConsumerPro(PushConsumer):
    def set_log_level(self, log_level: ffi._CLogLevel) -> None:
        ans = ffi_check(ffi.dll.SetPushConsumerLogLevel(self._handle, log_level))
        print(f"set__log__level result: {ans}")

os: centos 7.5 branch: master

ifplusor commented 2 years ago

@fengxiao2019 You need call set_log_level() before do anything.

fengxiao2019 commented 2 years ago

here is the source code :

    def create_consumer(self):
        self.consumer = PushConsumerPro(self.consumer_group_id)
        self.consumer.set_log_level(ffi._CLogLevel.LEVEL_NUM)

PushConsumerPro source code:

class PushConsumerPro(PushConsumer):
    def set_log_level(self, log_level: ffi._CLogLevel) -> None:
        ans = ffi_check(ffi.dll.SetPushConsumerLogLevel(self._handle, log_level))
        print(f"set__log__level result: {ans}")

PushConsumer's source code: the code come from rocketmq-client-python:

class PushConsumer(object):
    def __init__(self, group_id, orderly=False, message_model=MessageModel.CLUSTERING):
        self._handle = dll.CreatePushConsumer(_to_bytes(group_id))
        if self._handle is None:
            raise NullPointerException('Returned null pointer when create PushConsumer')
        self._orderly = orderly
        self.set_message_model(message_model)
        self._callback_refs = []

you mean I should call set_log_level before self.set_message_model(message_model) ?

ifplusor commented 2 years ago

@fengxiao2019 IMO, you need call SetPushConsumerLogLevel first, then call CreatePushConsumer and others.

fengxiao2019 commented 2 years ago
int SetPushConsumerLogLevel(CPushConsumer* consumer, CLogLevel level) {
  if (consumer == NULL) {
    return NULL_POINTER;
  }
  ((DefaultMQPushConsumer*)consumer)->setLogLevel((elogLevel)level);
  return OK;
}

SetPushConsumerLogLevel need the pointer of a consumer instance

ifplusor commented 2 years ago
int SetPushConsumerLogLevel(CPushConsumer* consumer, CLogLevel level) {
  if (consumer == NULL) {
    return NULL_POINTER;
  }
  ((DefaultMQPushConsumer*)consumer)->setLogLevel((elogLevel)level);
  return OK;
}

SetPushConsumerLogLevel need the pointer of a consumer instance

It's so crazy. I think you need disable this log to make it work. https://github.com/apache/rocketmq-client-cpp/blob/6523dcc3b309a1065375e40657f68f66bfeca38d/src/consumer/DefaultMQPushConsumerImpl.cpp#L226

ifplusor commented 2 years ago

At this moment, the logger in rocketmq is GLOBAL, and config the level of it is separate from consumer.

fengxiao2019 commented 2 years ago

Okay, I'll try this afternoon, thanks.