Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
22 changes: 22 additions & 0 deletions compendium/ConfigurationAdmin/src/CMLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,27 @@ namespace cppmicroservices
currLogger->Log(sr, level, message, ex);
}
}

std::shared_ptr<cppmicroservices::logservice::Logger>
CMLogger::getLogger(const std::string& name) const
{
auto currLogger = std::atomic_load(&logService);
if (currLogger)
{
return currLogger->getLogger(name);
}
return nullptr;
}

std::shared_ptr<cppmicroservices::logservice::Logger>
CMLogger::getLogger(cppmicroservices::Bundle bundle, std::string const& name) const
{
auto currLogger = std::atomic_load(&logService);
if (currLogger)
{
return currLogger->getLogger(bundle, name);
}
return nullptr;
}
} // namespace cmimpl
} // namespace cppmicroservices
2 changes: 2 additions & 0 deletions compendium/ConfigurationAdmin/src/CMLogger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ namespace cppmicroservices
logservice::SeverityLevel level,
std::string const& message,
const std::exception_ptr ex) override;
[[nodiscard]] std::shared_ptr<cppmicroservices::logservice::Logger> getLogger(const std::string& name) const override;
[[nodiscard]] std::shared_ptr<cppmicroservices::logservice::Logger> getLogger(cppmicroservices::Bundle bundle, std::string const& name) const override;

// methods from the cppmicroservices::ServiceTrackerCustomizer interface
std::shared_ptr<TrackedParamType> AddingService(
Expand Down
14 changes: 14 additions & 0 deletions compendium/ConfigurationAdmin/test/Mocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ namespace cppmicroservices
cppmicroservices::logservice::SeverityLevel,
std::string const&,
const std::exception_ptr));
MOCK_CONST_METHOD1(getLogger,
std::shared_ptr<cppmicroservices::logservice::Logger>(const std::string&));
MOCK_CONST_METHOD2(getLogger,
std::shared_ptr<cppmicroservices::logservice::Logger>(cppmicroservices::Bundle, const std::string&));
};

/**
Expand Down Expand Up @@ -86,6 +90,16 @@ namespace cppmicroservices
const std::exception_ptr) override
{
}
[[nodiscard]] std::shared_ptr<cppmicroservices::logservice::Logger>
getLogger(const std::string&) const override
{
return nullptr;
}
[[nodiscard]] std::shared_ptr<cppmicroservices::logservice::Logger>
getLogger(cppmicroservices::Bundle, const std::string&) const override
{
return nullptr;
}
};

/**
Expand Down
15 changes: 15 additions & 0 deletions compendium/DeclarativeServices/src/SCRLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,20 @@ namespace cppmicroservices
currLogger->Log(sr, level, message, ex);
}
}

std::shared_ptr<cppmicroservices::logservice::Logger>
SCRLogger::getLogger(const std::string& name) const
{
auto currLogger = std::atomic_load(&logService);
return currLogger->getLogger(name);
}

std::shared_ptr<cppmicroservices::logservice::Logger>
SCRLogger::getLogger(cppmicroservices::Bundle bundle, const std::string& name) const
{
auto currLogger = std::atomic_load(&logService);
return currLogger->getLogger(bundle, name);
}

} // namespace scrimpl
} // namespace cppmicroservices
2 changes: 2 additions & 0 deletions compendium/DeclarativeServices/src/SCRLogger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ namespace cppmicroservices
logservice::SeverityLevel level,
std::string const& message,
const std::exception_ptr ex) override;
[[nodiscard]] std::shared_ptr<cppmicroservices::logservice::Logger> getLogger(const std::string& name) const override;
[[nodiscard]] std::shared_ptr<cppmicroservices::logservice::Logger> getLogger(cppmicroservices::Bundle bundle, const std::string& name) const override;

// methods from the cppmicroservices::ServiceTrackerCustomizer interface
std::shared_ptr<TrackedParamType> AddingService(
Expand Down
15 changes: 15 additions & 0 deletions compendium/DeclarativeServices/test/gtest/Mocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ namespace cppmicroservices
cppmicroservices::logservice::SeverityLevel,
std::string const&,
std::exception_ptr const));
MOCK_CONST_METHOD1(getLogger,
std::shared_ptr<cppmicroservices::logservice::Logger>(const std::string&));
MOCK_CONST_METHOD2(getLogger,
std::shared_ptr<cppmicroservices::logservice::Logger>(cppmicroservices::Bundle, const std::string&));

};

#ifdef _MSC_VER
Expand Down Expand Up @@ -175,6 +180,16 @@ namespace cppmicroservices
std::exception_ptr const) override
{
}
[[nodiscard]] std::shared_ptr<cppmicroservices::logservice::Logger>
getLogger(const std::string&) const override
{
return nullptr;
}
[[nodiscard]] std::shared_ptr<cppmicroservices::logservice::Logger>
getLogger(cppmicroservices::Bundle, const std::string&) const override
{
return nullptr;
}
};

class MockComponentManager : public ComponentManager
Expand Down
2 changes: 2 additions & 0 deletions compendium/LogService/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
set(_public_headers
include/cppmicroservices/logservice/LogService.hpp
include/cppmicroservices/logservice/LoggerFactory.hpp
include/cppmicroservices/logservice/Logger.hpp
)

set(_version "1.0.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define CPPMICROSERVICES_LOG_SERVICE_H__

#include "cppmicroservices/ServiceReferenceBase.h"
#include "cppmicroservices/logservice/LoggerFactory.hpp"

#include <cstdint>
#include <exception>
Expand Down Expand Up @@ -69,7 +70,7 @@ namespace cppmicroservices
*
* @remarks This class is thread safe.
*/
class LogService
class LogService : public LoggerFactory
{
public:
virtual ~LogService() = default;
Expand Down Expand Up @@ -115,6 +116,7 @@ namespace cppmicroservices
std::string const& message,
const std::exception_ptr ex)
= 0;

};

} // namespace logservice
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#ifndef CPPMICROSERVICES_LOGGER_H_
#define CPPMICROSERVICES_LOGGER_H_

#include "cppmicroservices/ServiceReferenceBase.h"

#include <cstdint>
#include <exception>
#include <string>
#include <functional>


namespace cppmicroservices::logservice
{
/** @}*/

/**
* \ingroup MicroService
* \ingroup gr_logservice
*
* Provides methods for bundles to write messages to the log.
* Logger interface defines several methods for each of the defined LogLevels.
*
*/

class Logger
{
public:

virtual ~Logger() = default;

virtual void audit(const std::string& message) = 0;
virtual void audit(const std::string& format, const std::string& arg) = 0;
virtual void audit(const std::string& format, const std::string& arg1, const std::string& arg2) = 0;
virtual void audit(const std::string& message, const std::exception_ptr ex) = 0;
virtual void audit(const std::string& message, const ServiceReferenceBase& sr) = 0;
virtual void audit(const std::string& message, const ServiceReferenceBase& sr, const std::exception_ptr ex) = 0;

virtual void debug(const std::string& message) = 0;
virtual void debug(const std::string& format, const std::string& arg) = 0;
virtual void debug(const std::string& format, const std::string& arg1, const std::string& arg2) = 0;
virtual void debug(const std::string& message, const std::exception_ptr ex) = 0;
virtual void debug(const std::string& message, const ServiceReferenceBase& sr) = 0;
virtual void debug(const std::string& message, const ServiceReferenceBase& sr, const std::exception_ptr ex) = 0;

virtual void error(const std::string& message) = 0;
virtual void error(const std::string& format, const std::string& arg) = 0;
virtual void error(const std::string& format, const std::string& arg1, const std::string& arg2) = 0;
virtual void error(const std::string& message, const std::exception_ptr ex) = 0;
virtual void error(const std::string& message, const ServiceReferenceBase& sr) = 0;
virtual void error(const std::string& message, const ServiceReferenceBase& sr, const std::exception_ptr ex) = 0;

virtual void info(const std::string& message) = 0;
virtual void info(const std::string& format, const std::string& arg) = 0;
virtual void info(const std::string& format, const std::string& arg1, const std::string& arg2) = 0;
virtual void info(const std::string& message, const std::exception_ptr ex) = 0;
virtual void info(const std::string& message, const ServiceReferenceBase& sr) = 0;
virtual void info(const std::string& message, const ServiceReferenceBase& sr, const std::exception_ptr ex) = 0;

virtual void trace(const std::string& message) = 0;
virtual void trace(const std::string& format, const std::string& arg) = 0;
virtual void trace(const std::string& format, const std::string& arg1, const std::string& arg2) = 0;
virtual void trace(const std::string& message, const std::exception_ptr ex) = 0;
virtual void trace(const std::string& message, const ServiceReferenceBase& sr) = 0;
virtual void trace(const std::string& message, const ServiceReferenceBase& sr, const std::exception_ptr ex) = 0;

virtual void warn(const std::string& message) = 0;
virtual void warn(const std::string& format, const std::string& arg) = 0;
virtual void warn(const std::string& format, const std::string& arg1, const std::string& arg2) = 0;
virtual void warn(const std::string& message, const std::exception_ptr ex) = 0;
virtual void warn(const std::string& message, const ServiceReferenceBase& sr) = 0;
virtual void warn(const std::string& message, const ServiceReferenceBase& sr, const std::exception_ptr ex) = 0;

};
} // namespace cppmicroservices

#endif // CPPMICROSERVICES_LOG_SERVICE_H__
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*=============================================================================

Library: CppMicroServices

Copyright (c) The CppMicroServices developers. See the COPYRIGHT
file at the top-level directory of this distribution and at
https://github.com/CppMicroServices/CppMicroServices/COPYRIGHT .

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=============================================================================*/
#ifndef CPPMICROSERVICES_LOGGER_FACTORY_H_
#define CPPMICROSERVICES_LOGGER_FACTORY_H_
#include "cppmicroservices/logservice/Logger.hpp"
#include "cppmicroservices/Bundle.h"

#include <cstdint>
#include <exception>
#include <string>
#include <memory>

namespace cppmicroservices::logservice
{
class LoggerFactory
{
public:

inline static const std::string ROOT_LOGGER_NAME = "ROOT";

virtual ~LoggerFactory() = default;

[[nodiscard]] virtual std::shared_ptr<Logger> getLogger(std::string const& name = ROOT_LOGGER_NAME) const = 0;

[[nodiscard]] virtual std::shared_ptr<Logger> getLogger(cppmicroservices::Bundle bundle, std::string const& name = ROOT_LOGGER_NAME) const = 0;
};
}

#endif
4 changes: 4 additions & 0 deletions compendium/LogServiceImpl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# sources and headers
set(_srcs
src/LogServiceImpl.cpp
src/LoggerFactoryImpl.cpp
src/LoggerImpl.cpp
)

set(_hdrs
src/Activator.hpp
src/LogServiceImpl.hpp
src/LoggerFactoryImpl.hpp
src/LoggerImpl.hpp
)

set(_link_libraries )
Expand Down
13 changes: 9 additions & 4 deletions compendium/LogServiceImpl/src/Activator.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Activator.hpp"
#include "LoggerFactoryImpl.hpp"
#include "LogServiceImpl.hpp"

namespace cppmicroservices
Expand All @@ -9,10 +10,14 @@ namespace cppmicroservices
{
void
Activator::Start(cppmicroservices::BundleContext bc)
{
auto svc
= std::make_shared<cppmicroservices::logservice::LogServiceImpl>("cppmicroservices::logservice");
bc.RegisterService<cppmicroservices::logservice::LogService>(std::move(svc));
{
cppmicroservices::Bundle bundle = bc.GetBundle();
const std::string bsn = bundle.GetSymbolicName();
const std::string logger_name = "LogService." + bsn;
auto svc
= std::make_shared<cppmicroservices::logservice::LogServiceImpl>(logger_name);
bc.RegisterService<cppmicroservices::logservice::LogService>(svc);
bc.RegisterService<cppmicroservices::logservice::LoggerFactory>(svc);
}

void
Expand Down
Loading