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
16 changes: 8 additions & 8 deletions SilKit/ci/silkit_clang_tidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@


# Convenience
def log(fmt, *args):
print(fmt.format(*args))
def log(fmt, *args, **kwargs):
print(fmt.format(*args), **kwargs)


def info(fmt, *args):
log(INFO_PREFIX + fmt, *args)
def info(fmt, *args, **kwargs):
log(INFO_PREFIX + fmt, *args, **kwargs)


def warn(fmt, *args):
log(WARN_PREFIX + fmt, *args)
def warn(fmt, *args, **kwargs):
log(WARN_PREFIX + fmt, *args, **kwargs)


def die(status, fmt, *args):
log(ERROR_PREFIX + fmt, *args)
def die(status, fmt, *args, **kwargs):
log(ERROR_PREFIX + fmt, *args, **kwargs)
sys.exit(status)


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"
Comment thread
MariusBgm marked this conversation as resolved.

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
8 changes: 7 additions & 1 deletion 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,9 @@ struct Sink
Type type{Type::Remote};
Services::Logging::Level level{Services::Logging::Level::Info};
std::string logName;
// currenlty lives in Sink >> Experimental >>
std::vector<Services::Logging::Topic> disabledTopics{};
std::vector<Services::Logging::Topic> enabledTopics{};
};

//! \brief Logger service
Expand Down Expand Up @@ -225,7 +230,8 @@ auto to_string(NetworkType networkType) -> std::string

bool operator==(const Sink& lhs, const Sink& rhs)
{
return lhs.type == rhs.type && lhs.level == rhs.level && lhs.format == rhs.format && lhs.logName == rhs.logName;
return lhs.type == rhs.type && lhs.level == rhs.level && lhs.format == rhs.format && lhs.logName == rhs.logName
&& lhs.disabledTopics == rhs.disabledTopics && lhs.enabledTopics == rhs.enabledTopics;
}

bool operator<(const Sink& lhs, const Sink& rhs)
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": {
Comment thread
MariusBgm marked this conversation as resolved.
Comment thread
KonradBreitsprecherBkd marked this conversation as resolved.
"type": "array",
"items": {
"type": "string"
}
},
"EnabledTopics": {
Comment thread
KonradBreitsprecherBkd marked this conversation as resolved.
"type": "array",
"items": {
"type": "string"
}
},
"Level": {
"type": "string",
"enum": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
---
Description: Example include configuration for CAN Controllers
Logging:
Sinks:
- Type: Stdout
Level: Info
Experimental:
DisabledTopics: [MessageTracing, Flexray]
EnabledTopics: [Can]

CanControllers:
- Name: CAN1
Replay:
Expand Down
9 changes: 8 additions & 1 deletion SilKit/source/config/Test_ParticipantConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,13 @@ Description: Example include configuration for CAN Controllers
- Name: sink1
Type: Mdf4File
OutputPath: someFile.mf4

Logging:
Sinks:
- Type: Stdout
Level: Info
Experimental:
DisabledTopics: [MessageTracing, Flexray]
EnabledTopics: [Can]
)raw";

auto cfg = SilKit::Config::ParticipantConfigurationFromStringImpl(configString);
Expand All @@ -132,6 +138,7 @@ Description: Example include configuration for CAN Controllers
auto participantConfigRef = *std::dynamic_pointer_cast<ParticipantConfiguration>(ref_cfg);

ASSERT_EQ(participantConfig, participantConfigRef);
ASSERT_TRUE(participantConfig.logging.sinks.at(0).enabledTopics.at(0) == SilKit::Services::Logging::Topic::Can);
}
TEST_F(Test_ParticipantConfiguration, participant_config_from_string_includes)
{
Expand Down
Loading
Loading