Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev: Usage of InternalLogger and key values #135

Merged
merged 24 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
dd17ab0
SILKit-1607: Usage of InternalLogger and key values
VLukasBecker Sep 27, 2024
ef21f30
fixup! SILKit-1607: Usage of InternalLogger and key values
VLukasBecker Oct 14, 2024
8e62d50
fixup! SILKit-1607: Usage of InternalLogger and key values
VLukasBecker Oct 14, 2024
6e6ceb2
fixup! SILKit-1607: Usage of InternalLogger and key values
VLukasBecker Oct 14, 2024
97591f8
SILKit-1607: Add virtual time to log message of send/receive events a…
VLukasBecker Oct 18, 2024
767ef07
fixup! SILKit-1607: Usage of InternalLogger and key values
VLukasBecker Oct 18, 2024
2a61bdd
fixup! SILKit-1607: Usage of InternalLogger and key values
VLukasBecker Oct 18, 2024
fbabadd
fixup! SILKit-1607: Usage of InternalLogger and key values
VLukasBecker Oct 18, 2024
3dc905d
fixup! SILKit-1607: Usage of InternalLogger and key values
VLukasBecker Oct 18, 2024
d1c35ac
fixup! SILKit-1607: Usage of InternalLogger and key values
VLukasBecker Oct 18, 2024
e6bb2ed
SILKit-1607: Fix PR requests
VLukasBecker Oct 28, 2024
07ef979
fixup! SILKit-1607: Fix PR requests
VLukasBecker Oct 28, 2024
7bb0ccb
fixup! SILKit-1607: Fix PR requests
VLukasBecker Oct 30, 2024
4492deb
fixup! SILKit-1607: Fix PR requests
VLukasBecker Oct 31, 2024
9cf33f2
SILKit-1607: Usage of key values for created participant and controll…
VLukasBecker Oct 31, 2024
fe96fbb
fixup! SILKit-1607: Usage of key values for created participant and c…
VLukasBecker Nov 6, 2024
53460c5
fixup! SILKit-1607: Usage of key values for created participant and c…
VLukasBecker Nov 6, 2024
a416b0c
fixup! SILKit-1607: Usage of key values for created participant and c…
VLukasBecker Nov 6, 2024
1ef8b75
SILKit-1607: Update Changelog file
VLukasBecker Nov 7, 2024
a38a80a
SILKit-1607: Fix performance
VLukasBecker Nov 7, 2024
a25dad0
fixup! SILKit-1607: Fix performance
VLukasBecker Nov 8, 2024
b2a9b35
fixup! fixup! SILKit-1607: Fix performance
MariusBgm Nov 8, 2024
0c735e4
fixup! fixup! fixup! SILKit-1607: Fix performance
VLukasBecker Nov 8, 2024
024a760
fixup! fixup! fixup! SILKit-1607: Fix performance
VLukasBecker Nov 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions SilKit/source/core/internal/LoggingDatatypesInternal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include <string>
#include <sstream>
#include <ostream>
#include <unordered_map>
#include <vector>

#include "silkit/services/logging/LoggingDatatypes.hpp"
#include "silkit/services/logging/string_utils.hpp"
Expand Down Expand Up @@ -54,7 +54,7 @@ struct LogMsg
log_clock::time_point time;
SourceLoc source;
std::string payload;
std::unordered_map<std::string, std::string> keyValues;
std::vector<std::pair<std::string, std::string>> keyValues;
KonradBkd marked this conversation as resolved.
Show resolved Hide resolved
};

inline bool operator==(const SourceLoc& lhs, const SourceLoc& rhs);
Expand All @@ -67,8 +67,8 @@ inline std::string to_string(const LogMsg& msg);
inline std::ostream& operator<<(std::ostream& out, const LogMsg& msg);


inline std::string to_string(const std::unordered_map<std::string, std::string>& kv);
inline std::ostream& operator<<(std::ostream& out, const std::unordered_map<std::string, std::string>& kv);
inline std::string to_string(const std::vector<std::pair<std::string, std::string>>& kv);
inline std::ostream& operator<<(std::ostream& out, const std::vector<std::pair<std::string, std::string>>& kv);

// ================================================================================
// Inline Implementations
Expand Down Expand Up @@ -98,15 +98,16 @@ std::ostream& operator<<(std::ostream& out, const SourceLoc& sourceLoc)
<< "line=" << sourceLoc.line << ", funcname={\"" << sourceLoc.funcname << "\"}";
}

inline std::string to_string(const std::unordered_map<std::string, std::string>& kv)

inline std::string to_string(const std::vector<std::pair<std::string, std::string>>& kv)
{
std::stringstream outStream;
outStream << kv;
return outStream.str();
}


inline std::ostream& operator<<(std::ostream& out, const std::unordered_map<std::string, std::string>& kv)
inline std::ostream& operator<<(std::ostream& out, const std::vector<std::pair<std::string, std::string>>& kv)
{
std::string result;
result.reserve(kv.size() * 2);
Expand All @@ -115,7 +116,7 @@ inline std::ostream& operator<<(std::ostream& out, const std::unordered_map<std:
{
result.append(", kv: ");

std::unordered_map<std::string, std::string>::const_iterator it = kv.begin();
std::vector<std::pair<std::string, std::string>>::const_iterator it = kv.begin();
result.append("{");
while (it != kv.end())
{
Expand Down
21 changes: 21 additions & 0 deletions SilKit/source/core/internal/MessageBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ class MessageBuffer
template <typename ValueT, size_t SIZE>
inline MessageBuffer& operator>>(std::array<ValueT, SIZE>& array);
// --------------------------------------------------------------------------------
// std::pair<T, U>
template <typename T, typename U>
inline MessageBuffer& operator<<(const std::pair<T, U>& pair);
template <typename T, typename U>
inline MessageBuffer& operator>>(std::pair<T, U>& pair);
// --------------------------------------------------------------------------------
// std::chrono::duration<Rep, Period> and system_clock::time_point
template <class Rep, class Period>
inline MessageBuffer& operator<<(std::chrono::duration<Rep, Period> duration);
Expand Down Expand Up @@ -632,6 +638,21 @@ inline MessageBuffer& MessageBuffer::operator>>(std::unordered_map<std::string,
return *this;
}

template <typename T, typename U>
inline MessageBuffer& MessageBuffer::operator<<(const std::pair<T, U>& pair)
{
*this << pair.first << pair.second;
return *this;
}

template <typename T, typename U>
inline MessageBuffer& MessageBuffer::operator>>(std::pair<T, U>& pair)
{
*this >> pair.first >> pair.second;
return *this;
}


// --------------------------------------------------------------------------------
// Uuid

Expand Down
44 changes: 44 additions & 0 deletions SilKit/source/core/internal/ServiceDescriptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include <sstream>
#include <map>

#include "StructuredLoggingKeys.hpp"
#include "ServiceConfigKeys.hpp"
#include "Configuration.hpp"
#include "EndpointAddress.hpp"
Expand Down Expand Up @@ -70,6 +71,8 @@ class ServiceDescriptor
inline bool operator==(const ServiceDescriptor& rhs) const;
inline bool operator!=(const ServiceDescriptor& rhs) const;
inline std::string to_string() const;
inline std::vector<std::pair<std::string, std::string>> to_keyValues() const;

inline Core::EndpointAddress to_endpointAddress() const;

public:
Expand Down Expand Up @@ -304,6 +307,47 @@ std::string ServiceDescriptor::to_string() const
return ss.str();
}


std::vector<std::pair<std::string, std::string>> ServiceDescriptor::to_keyValues() const
{
namespace Keys = SilKit::Services::Logging::Keys;

std::vector<std::pair<std::string, std::string>> kv;
std::string controllerTypeName;
std::stringstream ss;

kv.push_back({Keys::participantName, GetParticipantName()});

switch (GetServiceType())
{
case ServiceType::Link:
kv.push_back({Keys::networkType, Config::to_string(GetNetworkType())});
kv.push_back({Keys::networkName, GetNetworkName()});
break;
case ServiceType::Controller:
case ServiceType::SimulatedController:
if (!GetSupplementalDataItem(SilKit::Core::Discovery::controllerType, controllerTypeName))
{
throw LogicError(
"ServiceDescriptor::to_keyValues() failed: No controller type defined in supplemental data.");
}
kv.push_back({Keys::controllerTypeName, controllerTypeName});
kv.push_back({Keys::networkName, GetNetworkName()});
kv.push_back({Keys::serviceName, GetServiceName()});
break;
case ServiceType::InternalController:
kv.push_back({Keys::serviceName, GetServiceName()});
break;
case ServiceType::Undefined:
kv.push_back({Keys::networkName, GetNetworkName()});
kv.push_back({Keys::serviceName, GetServiceName()});
break;
}

kv.push_back({Keys::serviceType, SilKit::Core::to_string(GetServiceType())});
return kv;
}

EndpointAddress ServiceDescriptor::to_endpointAddress() const
{
return {GetParticipantId(), GetServiceId()};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct NullConnection
}

void SetLogger(Services::Logging::ILogger* /*logger*/) {}
void SetLoggerInternal(Services::Logging::ILoggerInternal* /*logger*/) {}
void SetTimeSyncService(Orchestration::TimeSyncService* /*timeSyncService*/) {}
void JoinSimulation(std::string /*registryUri*/) {}

Expand Down
Loading
Loading