Skip to content

Commit b12a025

Browse files
committed
fix: log
1 parent dc0d5ef commit b12a025

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

src/MQClientInstance.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ void MQClientInstance::Start() {
113113
service_state_ = ServiceState::kRunning;
114114
break;
115115
case ServiceState::kRunning:
116-
LOG_INFO_NEW("the client instance [{}] already running.", client_id_, service_state_);
116+
LOG_INFO_NEW("the client instance [{}] already running.", client_id_);
117117
break;
118118
case ServiceState::kShutdownAlready:
119119
case ServiceState::kStartFailed:
120-
LOG_INFO_NEW("the client instance [{}] start failed with fault state:{}", client_id_, service_state_);
120+
LOG_INFO_NEW("the client instance [{}] start failed with fault state:{}", client_id_, ToString(service_state_));
121121
break;
122122
default:
123123
break;

src/common/ServiceState.h

+15
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,25 @@
1717
#ifndef ROCKETMQ_COMMON_SERVICESTATE_H_
1818
#define ROCKETMQ_COMMON_SERVICESTATE_H_
1919

20+
#include <string>
21+
2022
namespace rocketmq {
2123

2224
enum class ServiceState { kCreateJust, kRunning, kShutdownAlready, kStartFailed };
2325

26+
inline std::string ToString(ServiceState service_state) {
27+
switch (service_state) {
28+
case ServiceState::kCreateJust:
29+
return "CREATED_JUST";
30+
case ServiceState::kRunning:
31+
return "RUNNING";
32+
case ServiceState::kShutdownAlready:
33+
return "SHUTDOWN_ALREADY";
34+
case ServiceState::kStartFailed:
35+
return "START_FAILED";
36+
}
37+
}
38+
2439
} // namespace rocketmq
2540

2641
#endif // ROCKETMQ_COMMON_SERVICESTATE_H_

src/producer/DefaultMQProducerImpl.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -642,8 +642,8 @@ std::unique_ptr<TransactionSendResult> DefaultMQProducerImpl::SendInTransactionI
642642
try {
643643
EndTransaction(*send_result, local_transaction_state, local_exception);
644644
} catch (MQException& e) {
645-
LOG_WARN_NEW("local transaction execute {}, but end broker transaction failed: {}", local_transaction_state,
646-
e.what());
645+
LOG_WARN_NEW("local transaction execute {}, but end broker transaction failed: {}",
646+
ToString(local_transaction_state), e.what());
647647
}
648648

649649
// FIXME: setTransactionId will cause OOM?

src/transport/TcpRemotingClient.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ bool TcpRemotingClient::CloseTransport(const std::string& address, const TcpTran
594594
transport_table_.erase(address);
595595
}
596596

597-
LOG_WARN_NEW("closeTransport: disconnect:{} with state:{}", address, channel->LoadStatus());
597+
LOG_WARN_NEW("closeTransport: disconnect:{} with state:{}", address, ToString(channel->LoadStatus()));
598598
if (channel->LoadStatus() != TcpConnectStatus::kClosed) {
599599
channel->Disconnect(address); // avoid coredump when connection with server was broken
600600
}

src/transport/TcpTransport.h

+15
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ namespace rocketmq {
2929

3030
enum class TcpConnectStatus { kCreated, kConnecting, kConnected, kFailed, kClosed };
3131

32+
inline std::string ToString(TcpConnectStatus tcp_connect_status) {
33+
switch (tcp_connect_status) {
34+
case TcpConnectStatus::kCreated:
35+
return "CREATED";
36+
case TcpConnectStatus::kConnecting:
37+
return "CONNECTING";
38+
case TcpConnectStatus::kConnected:
39+
return "CONNECTED";
40+
case TcpConnectStatus::kFailed:
41+
return "FAILED";
42+
case TcpConnectStatus::kClosed:
43+
return "CLOSED";
44+
}
45+
}
46+
3247
class TcpTransport;
3348
using TcpTransportPtr = std::shared_ptr<TcpTransport>;
3449

0 commit comments

Comments
 (0)