From 3d4cd0281284af43c4e0518cd29ce46b8ea97f28 Mon Sep 17 00:00:00 2001 From: Dennis Klein Date: Tue, 10 Mar 2020 14:05:23 +0100 Subject: [PATCH] Allow undefining LOG macro with FairLogger v1.6.2+ Resolves #244 --- fairmq/sdk/AsioAsyncOp.h | 10 +++++++--- fairmq/sdk/Topology.h | 43 +++++++++++++++++++++------------------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/fairmq/sdk/AsioAsyncOp.h b/fairmq/sdk/AsioAsyncOp.h index ff64976f..4195ed8e 100644 --- a/fairmq/sdk/AsioAsyncOp.h +++ b/fairmq/sdk/AsioAsyncOp.h @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -24,6 +23,11 @@ #include #include +#include +#ifndef FAIR_LOG +#define FAIR_LOG LOG +#endif /* ifndef FAIR_LOG */ + namespace fair { namespace mq { namespace sdk { @@ -70,9 +74,9 @@ struct AsioAsyncOpImpl : AsioAsyncOpImplBase try { handler(ec, args...); } catch (const std::exception& e) { - LOG(error) << "Uncaught exception in AsioAsyncOp completion handler: " << e.what(); + FAIR_LOG(error) << "Uncaught exception in AsioAsyncOp completion handler: " << e.what(); } catch (...) { - LOG(error) << "Unknown uncaught exception in AsioAsyncOp completion handler."; + FAIR_LOG(error) << "Unknown uncaught exception in AsioAsyncOp completion handler."; } }, GetAlloc2()); diff --git a/fairmq/sdk/Topology.h b/fairmq/sdk/Topology.h index 26705ce9..3f3a4d72 100644 --- a/fairmq/sdk/Topology.h +++ b/fairmq/sdk/Topology.h @@ -23,6 +23,9 @@ #include #include +#ifndef FAIR_LOG +#define FAIR_LOG LOG +#endif /* ifndef FAIR_LOG */ #include #include @@ -187,10 +190,10 @@ class BasicTopology : public AsioBase fDDSSession.SubscribeToCommands([&](const std::string& msg, const std::string& /* condition */, DDSChannel::Id senderId) { Cmds inCmds; inCmds.Deserialize(msg); - // LOG(debug) << "Received " << inCmds.Size() << " command(s) with total size of " << msg.length() << " bytes: "; + // FAIR_LOG(debug) << "Received " << inCmds.Size() << " command(s) with total size of " << msg.length() << " bytes: "; for (const auto& cmd : inCmds) { - // LOG(debug) << " > " << cmd->GetType(); + // FAIR_LOG(debug) << " > " << cmd->GetType(); switch (cmd->GetType()) { case Type::state_change: { auto _cmd = static_cast(*cmd); @@ -201,18 +204,18 @@ class BasicTopology : public AsioBase } break; case Type::state_change_subscription: if (static_cast(*cmd).GetResult() != Result::Ok) { - LOG(error) << "State change subscription failed for " << static_cast(*cmd).GetDeviceId(); + FAIR_LOG(error) << "State change subscription failed for " << static_cast(*cmd).GetDeviceId(); } break; case Type::state_change_unsubscription: if (static_cast(*cmd).GetResult() != Result::Ok) { - LOG(error) << "State change unsubscription failed for " << static_cast(*cmd).GetDeviceId(); + FAIR_LOG(error) << "State change unsubscription failed for " << static_cast(*cmd).GetDeviceId(); } break; case Type::transition_status: { auto _cmd = static_cast(*cmd); if (_cmd.GetResult() != Result::Ok) { - LOG(error) << _cmd.GetTransition() << " transition failed for " << _cmd.GetDeviceId(); + FAIR_LOG(error) << _cmd.GetTransition() << " transition failed for " << _cmd.GetDeviceId(); std::lock_guard lk(fMtx); if (!fChangeStateOp.IsCompleted() && fStateData.at(fStateIndex.at(_cmd.GetTaskId())).state != fChangeStateTarget) { fChangeStateOpTimer.cancel(); @@ -230,15 +233,15 @@ class BasicTopology : public AsioBase } break; default: - LOG(warn) << "Unexpected/unknown command received: " << cmd->GetType(); - LOG(warn) << "Origin: " << senderId; + FAIR_LOG(warn) << "Unexpected/unknown command received: " << cmd->GetType(); + FAIR_LOG(warn) << "Origin: " << senderId; break; } } }); fDDSSession.StartDDSService(); - // LOG(debug) << "Subscribing to state change"; + // FAIR_LOG(debug) << "Subscribing to state change"; Cmds cmds(make()); fDDSSession.SendCommand(cmds.Serialize()); } @@ -391,9 +394,9 @@ class BasicTopology : public AsioBase try { h(MakeErrorCode(ErrorCode::OperationInProgress), s); } catch (const std::exception& e) { - LOG(error) << "Uncaught exception in completion handler: " << e.what(); + FAIR_LOG(error) << "Uncaught exception in completion handler: " << e.what(); } catch (...) { - LOG(error) << "Unknown uncaught exception in completion handler."; + FAIR_LOG(error) << "Unknown uncaught exception in completion handler."; } }, alloc2); @@ -687,7 +690,7 @@ class BasicTopology : public AsioBase } }); } - // LOG(debug) << "GetProperties " << fId << " with expected count of " << fExpectedCount << " started."; + // FAIR_LOG(debug) << "GetProperties " << fId << " with expected count of " << fExpectedCount << " started."; } GetPropertiesOp() = delete; GetPropertiesOp(const GetPropertiesOp&) = delete; @@ -741,9 +744,9 @@ class BasicTopology : public AsioBase lk.unlock(); op.Update(cmd.GetDeviceId(), cmd.GetResult(), cmd.GetProps()); } catch (std::out_of_range& e) { - LOG(debug) << "GetProperties operation (request id: " << cmd.GetRequestId() - << ") not found (probably completed or timed out), " - << "discarding reply of device " << cmd.GetDeviceId(); + FAIR_LOG(debug) << "GetProperties operation (request id: " << cmd.GetRequestId() + << ") not found (probably completed or timed out), " + << "discarding reply of device " << cmd.GetDeviceId(); } } @@ -856,7 +859,7 @@ class BasicTopology : public AsioBase } }); } - // LOG(debug) << "SetProperties " << fId << " with expected count of " << fExpectedCount << " started."; + // FAIR_LOG(debug) << "SetProperties " << fId << " with expected count of " << fExpectedCount << " started."; } SetPropertiesOp() = delete; SetPropertiesOp(const SetPropertiesOp&) = delete; @@ -908,9 +911,9 @@ class BasicTopology : public AsioBase lk.unlock(); op.Update(cmd.GetDeviceId(), cmd.GetResult()); } catch (std::out_of_range& e) { - LOG(debug) << "SetProperties operation (request id: " << cmd.GetRequestId() - << ") not found (probably completed or timed out), " - << "discarding reply of device " << cmd.GetDeviceId(); + FAIR_LOG(debug) << "SetProperties operation (request id: " << cmd.GetRequestId() + << ") not found (probably completed or timed out), " + << "discarding reply of device " << cmd.GetDeviceId(); } } @@ -1033,10 +1036,10 @@ class BasicTopology : public AsioBase if (task.state == fChangeStateTarget) { ++fTransitionedCount; } - // LOG(debug) << "Updated state entry: taskId=" << taskId << ", state=" << state; + // FAIR_LOG(debug) << "Updated state entry: taskId=" << taskId << ", state=" << state; TryChangeStateCompletion(); } catch (const std::exception& e) { - LOG(error) << "Exception in UpdateStateEntry: " << e.what(); + FAIR_LOG(error) << "Exception in UpdateStateEntry: " << e.what(); } }