Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ enable_testing()
if(MSVC)
#make sure Release is built with debug PDBs
add_compile_options(/Zi )
add_compile_options(/utf-8)
endif()

if(SILKIT_ENABLE_TRACING_INSTRUMENTATION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,7 @@ void SetCurrentWorkingDir(const std::string& cwd)

class StdoutLogger : public SilKit::Core::Tests::MockLogger
{
public:
void Info(const std::string& msg) override
{
std::cout << "SilKitExtensionTest: Info: " << msg << std::endl;
}
void Debug(const std::string& msg) override
{
std::cout << "SilKitExtensionTest: Debug: " << msg << std::endl;
}
void Warn(const std::string& msg) override
{
std::cout << "SilKitExtensionTest: Warn: " << msg << std::endl;
}
void Error(const std::string& msg) override
{
std::cout << "SilKitExtensionTest: Error: " << msg << std::endl;
}

};
} // namespace

Expand Down
1 change: 0 additions & 1 deletion SilKit/include/silkit/capi/Vendor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "silkit/capi/SilKitMacros.h"
#include "silkit/capi/Types.h"
#include "silkit/capi/InterfaceIdentifiers.h"
#include "silkit/capi/Logger.h"

SILKIT_BEGIN_DECLS

Expand Down
10 changes: 10 additions & 0 deletions SilKit/source/CreateParticipantImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,14 @@ auto CreateParticipantImpl(std::shared_ptr<SilKit::Config::IParticipantConfigura
return CreateParticipantImpl(participantConfig, participantName, uri);
}

auto GetLoggerInternal(SilKit::IParticipant* participant) -> SilKit::Services::Logging::ILoggerInternal*
{
auto participantImpl = dynamic_cast<Core::IParticipantInternal*>(participant);
if (participantImpl == nullptr)
{
throw SilKit::ConfigurationError("The provided participant is not a valid SilKit::Core::IParticipantInternal");
}
return participantImpl->GetLoggerInternal();
}

} //namespace SilKit
11 changes: 11 additions & 0 deletions SilKit/source/CreateParticipantImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ class IParticipantConfiguration;
} // namespace SilKit


// Function Declarations

namespace SilKit {
namespace Services {
namespace Logging {
struct ILoggerInternal; // todo check or remove, move to own file
} // namespace Logging
} // namespace Services
} // namespace SilKit

// Function Declarations

namespace SilKit {
Expand All @@ -34,4 +44,5 @@ auto CreateParticipantImpl(std::shared_ptr<SilKit::Config::IParticipantConfigura
auto CreateParticipantImpl(std::shared_ptr<SilKit::Config::IParticipantConfiguration> participantConfig,
const std::string& participantName) -> std::unique_ptr<IParticipant>;

auto GetLoggerInternal(SilKit::IParticipant* participant ) -> SilKit::Services::Logging::ILoggerInternal*;// todo check or remove, move to own file
} // namespace SilKit
10 changes: 10 additions & 0 deletions SilKit/source/CreateSilKitRegistryImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ auto CreateSilKitRegistryImpl(std::shared_ptr<SilKit::Config::IParticipantConfig
return std::make_unique<Core::VAsioRegistry>(config);
}

auto GetLoggerInternal(ISilKitRegistry* participant) -> SilKit::Services::Logging::ILoggerInternal*
{
auto participantImpl = dynamic_cast<Core::VAsioRegistry*>(participant);
if (participantImpl == nullptr)
{
throw SilKit::ConfigurationError("The provided participant is not a valid SilKit::Core::IParticipantInternal");
}
return participantImpl->GetLoggerInternal();
}

} // namespace Vector
} // namespace Vendor
} // namespace SilKit
10 changes: 10 additions & 0 deletions SilKit/source/CreateSilKitRegistryImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@

// Forward Declarations

namespace SilKit {
namespace Services {
namespace Logging {
struct ILoggerInternal; // todo check or remove, move to own file
} // namespace Logging
} // namespace Services
} // namespace SilKit

namespace SilKit {
namespace Config {
class IParticipantConfiguration;
Expand All @@ -39,6 +47,8 @@ namespace Vector {
auto CreateSilKitRegistryImpl(std::shared_ptr<SilKit::Config::IParticipantConfiguration> config)
-> std::unique_ptr<ISilKitRegistry>;

auto GetLoggerInternal(ISilKitRegistry* participant)
-> SilKit::Services::Logging::ILoggerInternal*; // todo check or remove, move to own file
} // namespace Vector
} // namespace Vendor
} // namespace SilKit
15 changes: 10 additions & 5 deletions SilKit/source/capi/CapiLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#include "silkit/capi/SilKit.h"
#include "silkit/SilKit.hpp"
#include "silkit/services/logging/ILogger.hpp"

#include "ILoggerInternal.hpp"
#include "LoggerMessage.hpp"
#include "CapiImpl.hpp"

#include <string>
Expand All @@ -17,10 +17,15 @@ try
ASSERT_VALID_POINTER_PARAMETER(self);
ASSERT_VALID_POINTER_PARAMETER(message);

auto logger = reinterpret_cast<SilKit::Services::Logging::ILogger*>(self);
auto logger = reinterpret_cast<SilKit::Services::Logging::ILoggerInternal*>(self);
auto enumLevel = static_cast<SilKit::Services::Logging::Level>(level);

std::string useString{message}; //ensure we do not trigger the FMT template overload for const char*
logger->Log(enumLevel, useString);

logger->MakeMessage(enumLevel, SilKit::Services::Logging::Topic::User)
.SetMessage(useString)
.Dispatch();

return SilKit_ReturnCode_SUCCESS;
}
CAPI_CATCH_EXCEPTIONS
Expand All @@ -32,7 +37,7 @@ try
ASSERT_VALID_POINTER_PARAMETER(self);
ASSERT_VALID_POINTER_PARAMETER(outLevel);

auto logger = reinterpret_cast<SilKit::Services::Logging::ILogger*>(self);
auto logger = reinterpret_cast<SilKit::Services::Logging::ILoggerInternal*>(self);
auto enumLevel = static_cast<SilKit_LoggingLevel>(logger->GetLogLevel());
*outLevel = enumLevel;
return SilKit_ReturnCode_SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion SilKit/source/capi/CapiParticipant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ try
ASSERT_VALID_POINTER_PARAMETER(participant);

auto cppParticipant = reinterpret_cast<SilKit::IParticipant*>(participant);
auto logger = cppParticipant->GetLogger();
auto logger = GetLoggerInternal(cppParticipant);
*outLogger = reinterpret_cast<SilKit_Logger*>(logger);
return SilKit_ReturnCode_SUCCESS;
}
Expand Down
30 changes: 7 additions & 23 deletions SilKit/source/capi/Test_CapiLogger.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
// SPDX-FileCopyrightText: 2022 Vector Informatik GmbH
// SPDX-FileCopyrightText: 2022 Vector Informatik GmbH
//
// SPDX-License-Identifier: MIT

#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "silkit/capi/SilKit.h"
#include "silkit/services/logging/all.hpp"
#include "LoggingTopics.hpp"
#include "MockLogger.hpp"

namespace {
using namespace SilKit::Services::Logging;

class MockLogger : public SilKit::Services::Logging::ILogger
{
public:
MOCK_METHOD2(Log, void(Level, const std::string&));
MOCK_METHOD1(Trace, void(const std::string&));
MOCK_METHOD1(Debug, void(const std::string&));
MOCK_METHOD1(Info, void(const std::string&));
MOCK_METHOD1(Warn, void(const std::string&));
MOCK_METHOD1(Error, void(const std::string&));
MOCK_METHOD1(Critical, void(const std::string&));

MOCK_CONST_METHOD0(GetLogLevel, Level());
};

class Test_CapiLogger : public testing::Test
{
public:
Expand All @@ -35,7 +23,7 @@ TEST_F(Test_CapiLogger, logger_function_mapping)
{
SilKit_ReturnCode returnCode;

EXPECT_CALL(mockLogger, Log(Level::Off, "Test message")).Times(testing::Exactly(1));
EXPECT_CALL(mockLogger, ProcessLoggerMessage(testing::_)).Times(testing::Exactly(1));
returnCode = SilKit_Logger_Log((SilKit_Logger*)&mockLogger, SilKit_LoggingLevel_Off, "Test message");
EXPECT_EQ(returnCode, SilKit_ReturnCode_SUCCESS);
}
Expand All @@ -55,31 +43,27 @@ TEST_F(Test_CapiLogger, logger_enum_mappings)
{
SilKit_ReturnCode returnCode;

EXPECT_CALL(mockLogger, Log(Level::Off, "Test message")).Times(testing::Exactly(1));
// SilKit_Logger_Log dispatches via MakeMessage → ProcessLoggerMessage
EXPECT_CALL(mockLogger, ProcessLoggerMessage(testing::_)).Times(testing::Exactly(7));

returnCode = SilKit_Logger_Log((SilKit_Logger*)&mockLogger, SilKit_LoggingLevel_Off, "Test message");
EXPECT_EQ(returnCode, SilKit_ReturnCode_SUCCESS);

EXPECT_CALL(mockLogger, Log(Level::Trace, "Trace message")).Times(testing::Exactly(1));
returnCode = SilKit_Logger_Log((SilKit_Logger*)&mockLogger, SilKit_LoggingLevel_Trace, "Trace message");
EXPECT_EQ(returnCode, SilKit_ReturnCode_SUCCESS);

EXPECT_CALL(mockLogger, Log(Level::Debug, "Debug message")).Times(testing::Exactly(1));
returnCode = SilKit_Logger_Log((SilKit_Logger*)&mockLogger, SilKit_LoggingLevel_Debug, "Debug message");
EXPECT_EQ(returnCode, SilKit_ReturnCode_SUCCESS);

EXPECT_CALL(mockLogger, Log(Level::Info, "Info message")).Times(testing::Exactly(1));
returnCode = SilKit_Logger_Log((SilKit_Logger*)&mockLogger, SilKit_LoggingLevel_Info, "Info message");
EXPECT_EQ(returnCode, SilKit_ReturnCode_SUCCESS);

EXPECT_CALL(mockLogger, Log(Level::Warn, "Warn message")).Times(testing::Exactly(1));
returnCode = SilKit_Logger_Log((SilKit_Logger*)&mockLogger, SilKit_LoggingLevel_Warn, "Warn message");
EXPECT_EQ(returnCode, SilKit_ReturnCode_SUCCESS);

EXPECT_CALL(mockLogger, Log(Level::Error, "Error message")).Times(testing::Exactly(1));
returnCode = SilKit_Logger_Log((SilKit_Logger*)&mockLogger, SilKit_LoggingLevel_Error, "Error message");
EXPECT_EQ(returnCode, SilKit_ReturnCode_SUCCESS);

EXPECT_CALL(mockLogger, Log(Level::Critical, "Critical message")).Times(testing::Exactly(1));
returnCode = SilKit_Logger_Log((SilKit_Logger*)&mockLogger, SilKit_LoggingLevel_Critical, "Critical message");
EXPECT_EQ(returnCode, SilKit_ReturnCode_SUCCESS);

Expand Down
4 changes: 4 additions & 0 deletions SilKit/source/config/Configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

#include "silkit/participant/exception.hpp"
#include "silkit/SilKitMacros.hpp"

#include "silkit/services/logging/LoggingDatatypes.hpp"
#include "LoggingTopics.hpp"

#include "StringHelpers.hpp"

Expand Down Expand Up @@ -81,6 +83,8 @@ struct Sink
Type type{Type::Remote};
Services::Logging::Level level{Services::Logging::Level::Info};
std::string logName;
std::vector<Services::Logging::Topic> disabledTopics{};
std::vector<Services::Logging::Topic> enabledTopics{};
};

//! \brief Logger service
Expand Down
1 change: 1 addition & 0 deletions SilKit/source/config/ParticipantConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: MIT

#include "ParticipantConfiguration.hpp"
#include "LoggerMessage.hpp"

#include <string>
#include <type_traits>
Expand Down
12 changes: 12 additions & 0 deletions SilKit/source/config/ParticipantConfiguration.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,18 @@
"type": "string",
"enum": [ "Simple", "Json" ]
},
"DisabledTopics": {
"type": "array",
"items": {
"type": "string"
}
},
"EnabledTopics": {
"type": "array",
"items": {
"type": "string"
}
},
"Level": {
"type": "string",
"enum": [
Expand Down
23 changes: 23 additions & 0 deletions SilKit/source/config/YamlReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//
// SPDX-License-Identifier: MIT
#include "YamlReader.hpp"
#include "silkit/services/logging/string_utils.hpp"
#include "string_utils_internal.hpp"

namespace VSilKit {

Expand Down Expand Up @@ -47,6 +49,25 @@ void YamlReader::Read(SilKit::Services::Logging::Level& obj)
}
}

void YamlReader::Read(SilKit::Services::Logging::Topic& obj)
{
if (!IsScalar() )
{
throw MakeConfigurationError("Topic should be a string.");
}

std::string value;
Read(value);

const auto topic = SilKit::Services::Logging::from_topic_string(value);

if (topic == SilKit::Services::Logging::Topic::Invalid)
{
throw MakeConfigurationError("Unknown SilKit::Services::Logging::Topic");
}
obj = topic;
}

void YamlReader::Read(SilKit::Services::Flexray::FlexrayClusterParameters& obj)
{
// Parse parameters as an int value; uint8_t would be interpreted as a character
Expand Down Expand Up @@ -195,6 +216,8 @@ void YamlReader::Read(SilKit::Config::Sink& obj)
OptionalRead(obj.type, "Type");
OptionalRead(obj.level, "Level");
OptionalRead(obj.format, "Format");
OptionalRead(obj.disabledTopics, "DisabledTopics");
OptionalRead(obj.enabledTopics, "EnabledTopics");

if (obj.type == SilKit::Config::Sink::Type::File)
{
Expand Down
1 change: 1 addition & 0 deletions SilKit/source/config/YamlReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ struct YamlReader : BasicYamlReader<YamlReader>
void Read(SilKit::Services::MatchingLabel& value);
void Read(SilKit::Services::MatchingLabel::Kind& value);
void Read(SilKit::Services::Logging::Level& obj);
void Read(SilKit::Services::Logging::Topic& obj);
void Read(SilKit::Services::Flexray::FlexrayClusterParameters& obj);
void Read(SilKit::Services::Flexray::FlexrayNodeParameters& obj);
void Read(SilKit::Services::Flexray::FlexrayTxBufferConfig& obj);
Expand Down
2 changes: 2 additions & 0 deletions SilKit/source/config/YamlValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ const std::set<std::string> schemaPaths_v1 = {
"/Logging/Sinks/Level",
"/Logging/Sinks/LogName",
"/Logging/Sinks/Type",
"/Logging/Sinks/EnabledTopics",
"/Logging/Sinks/DisabledTopics",
"/Middleware",
"/Middleware/AcceptorUris",
"/Middleware/ConnectAttempts",
Expand Down
7 changes: 5 additions & 2 deletions SilKit/source/core/internal/LoggingDatatypesInternal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "silkit/services/logging/LoggingDatatypes.hpp"
#include "silkit/services/logging/string_utils.hpp"
#include "string_utils_internal.hpp"

namespace SilKit {
namespace Services {
Expand All @@ -34,6 +35,7 @@ struct LogMsg
{
std::string loggerName;
Level level{Level::Off};
Topic topic{Topic::None};
log_clock::time_point time;
SourceLoc source;
std::string payload;
Expand All @@ -49,7 +51,6 @@ inline std::ostream& operator<<(std::ostream& out, const SourceLoc& sourceLoc);
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::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);

Expand All @@ -64,7 +65,8 @@ bool operator==(const SourceLoc& lhs, const SourceLoc& rhs)

inline bool operator==(const LogMsg& lhs, const LogMsg& rhs)
{
return lhs.loggerName == rhs.loggerName && lhs.level == rhs.level && lhs.time == rhs.time
return lhs.loggerName == rhs.loggerName && lhs.level == rhs.level && lhs.topic == rhs.topic
&& lhs.time == rhs.time
&& lhs.source == rhs.source && lhs.payload == rhs.payload && lhs.keyValues == rhs.keyValues;
}

Expand Down Expand Up @@ -127,6 +129,7 @@ std::string to_string(const LogMsg& msg)
std::ostream& operator<<(std::ostream& out, const LogMsg& msg)
{
out << "LogMsg{logger=" << msg.loggerName << ", level=" << msg.level
<< ", topic=" << msg.topic
<< ", time=" << std::chrono::duration_cast<std::chrono::microseconds>(msg.time.time_since_epoch()).count()
<< ", source=" << msg.source << ", payload=\"" << msg.payload << "\"" << msg.keyValues << "}";
return out;
Expand Down
Loading
Loading