-
Notifications
You must be signed in to change notification settings - Fork 86
feat(os): add Linux syslog OS wrapper for score::os::Syslog #502
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
Open
btirunagaru
wants to merge
1
commit into
eclipse-score:main
Choose a base branch
from
qualcomm:feat/syslog_on_linux
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /******************************************************************************** | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * See the NOTICE file(s) distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Apache License Version 2.0 which is available at | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| ********************************************************************************/ | ||
| #include "score/os/mocklib/mock_syslog.h" | ||
|
|
||
| #include <cstdarg> | ||
| #include <cstdio> | ||
| #include <string> | ||
|
|
||
| namespace score | ||
|
|
||
| { | ||
| namespace os | ||
| { | ||
|
|
||
| // NOLINTNEXTLINE(cert-dcl50-cpp, modernize-avoid-variadic-functions) | ||
| void MockSyslog::syslog(std::int32_t priority, const char* format, ...) const noexcept | ||
| { | ||
| // Create a va_list to hold the variable arguments | ||
| va_list args; | ||
|
|
||
| va_start(args, format); | ||
|
|
||
|
|
||
| // Determine required buffer size | ||
| const auto message_length = std::vsnprintf(nullptr, 0, format, args); | ||
|
|
||
|
|
||
| // Reset the va_list to be able to use it again | ||
| va_end(args); | ||
|
|
||
| va_start(args, format); | ||
|
|
||
|
|
||
| // Create buffer | ||
| std::string message{}; | ||
| message.resize(static_cast<std::size_t>(message_length)); | ||
|
|
||
| // Write formatted string to buffer | ||
| const auto length_including_terminator = static_cast<std::size_t>(message_length) + 1U; | ||
| std::vsnprintf(&message[0], length_including_terminator, format, args); | ||
|
|
||
|
|
||
| // Clean up the va_list | ||
| va_end(args); | ||
|
|
||
|
|
||
| MockedSyslog(priority, message); | ||
| } | ||
|
|
||
| } // namespace os | ||
| } // namespace score | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /******************************************************************************** | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * See the NOTICE file(s) distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Apache License Version 2.0 which is available at | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| ********************************************************************************/ | ||
| #ifndef SCORE_LIB_OS_MOCKLIB_MOCK_SYSLOG_H | ||
| #define SCORE_LIB_OS_MOCKLIB_MOCK_SYSLOG_H | ||
|
|
||
| #include "score/os/syslog.h" | ||
|
|
||
| #include <gmock/gmock.h> | ||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <string> | ||
|
|
||
| namespace score | ||
|
|
||
| { | ||
| namespace os | ||
| { | ||
|
|
||
| class MockSyslog : public Syslog | ||
| { | ||
| public: | ||
| MOCK_METHOD(void, | ||
| openlog, | ||
|
|
||
| (const char* ident, std::int32_t option, std::int32_t facility), | ||
| (const, noexcept, override)); | ||
|
|
||
| MOCK_METHOD(void, closelog, (), (const, noexcept, override)); | ||
|
|
||
|
|
||
| // Googletest does not support variadic arguments. Therefore we pass through the formatted string so that we can | ||
| // use it with MOCK_METHOD. | ||
| MOCK_METHOD(void, MockedSyslog, (std::int32_t priority, const std::string& message), (const, noexcept)); | ||
|
|
||
|
|
||
| void syslog(std::int32_t priority, const char* format, ...) const noexcept override | ||
| __attribute__((format(printf, 3, 4))); | ||
| }; | ||
|
|
||
| } // namespace os | ||
| } // namespace score | ||
|
|
||
| #endif // SCORE_LIB_OS_MOCKLIB_MOCK_SYSLOG_H | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /******************************************************************************** | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * See the NOTICE file(s) distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Apache License Version 2.0 which is available at | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| ********************************************************************************/ | ||
| #include "score/os/syslog.h" | ||
|
|
||
| #include "score/os/syslog_impl.h" | ||
|
|
||
| namespace score | ||
|
|
||
| { | ||
| namespace os | ||
| { | ||
|
|
||
| /* score::cpp::pmr::make_unique takes non-const memory_resource */ | ||
| score::cpp::pmr::unique_ptr<Syslog> Syslog::Default(score::cpp::pmr::memory_resource* memory_resource) noexcept | ||
| { | ||
| return score::cpp::pmr::make_unique<SyslogImpl>(memory_resource); | ||
| } | ||
|
|
||
| } // namespace os | ||
| } // namespace score | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /******************************************************************************** | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * See the NOTICE file(s) distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Apache License Version 2.0 which is available at | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| ********************************************************************************/ | ||
| #ifndef SCORE_LIB_OS_SYSLOG_H | ||
| #define SCORE_LIB_OS_SYSLOG_H | ||
|
|
||
| #include "score/os/errno.h" | ||
|
|
||
| #include "score/memory.hpp" | ||
|
|
||
| #include <syslog.h> | ||
|
|
||
| namespace score | ||
|
|
||
| { | ||
| namespace os | ||
| { | ||
|
|
||
| /// @brief Object-seam wrapper around the POSIX/glibc syslog(3) family, allowing | ||
| /// openlog/syslog/closelog to be mocked in host unit tests. | ||
| class Syslog | ||
| { | ||
| public: | ||
| static score::cpp::pmr::unique_ptr<Syslog> Default(score::cpp::pmr::memory_resource* memory_resource) noexcept; | ||
|
|
||
| virtual void openlog(const char* const ident, | ||
| const std::int32_t option, | ||
| const std::int32_t facility) const noexcept = 0; | ||
|
|
||
| virtual void syslog(const std::int32_t priority, const char* const format, ...) const noexcept | ||
| __attribute__((format(printf, 3, 4))) = 0; | ||
|
|
||
| virtual void closelog() const noexcept = 0; | ||
|
|
||
| /// @brief Construct a new Syslog object | ||
| /// | ||
| Syslog() = default; | ||
|
|
||
| virtual ~Syslog() = default; | ||
| Syslog(const Syslog&) = delete; | ||
| Syslog& operator=(const Syslog&) = delete; | ||
| Syslog(Syslog&& other) = delete; | ||
| Syslog& operator=(Syslog&& other) = delete; | ||
| }; | ||
|
|
||
| } // namespace os | ||
| } // namespace score | ||
|
|
||
| #endif // SCORE_LIB_OS_SYSLOG_H | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /******************************************************************************** | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * See the NOTICE file(s) distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Apache License Version 2.0 which is available at | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| ********************************************************************************/ | ||
| #include "score/os/syslog_impl.h" | ||
|
|
||
| #include <cstdarg> | ||
|
|
||
| namespace score | ||
|
|
||
| { | ||
| namespace os | ||
| { | ||
|
|
||
| void SyslogImpl::openlog(const char* const ident, const std::int32_t option, const std::int32_t facility) const noexcept | ||
| { | ||
| ::openlog(ident, option, facility); | ||
| } | ||
|
|
||
| // NOLINTNEXTLINE(cert-dcl50-cpp, modernize-avoid-variadic-functions) | ||
| void SyslogImpl::syslog(const std::int32_t priority, const char* const format, ...) const noexcept | ||
| { | ||
| // Suppressed here because POSIX method accepts va_list | ||
| // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) see comment above | ||
| va_list args; | ||
| // Suppressed here because POSIX method accepts va_list | ||
| // NOLINTNEXTLINE(hicpp-no-array-decay, cppcoreguidelines-pro-type-vararg) see comment above | ||
| va_start(args, format); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay) see comment above | ||
| // Suppressed here because POSIX method accepts va_list | ||
| // NOLINTNEXTLINE(*array-decay, *pro-type-vararg,*array-to-pointer-decay) see comment above | ||
| ::vsyslog(priority, format, args); | ||
| // Suppressed here because POSIX method accepts va_list | ||
| // NOLINTNEXTLINE(hicpp-no-array-decay, cppcoreguidelines-pro-type-vararg) see comment above | ||
| va_end(args); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay) see comment above | ||
| } | ||
|
|
||
| void SyslogImpl::closelog() const noexcept | ||
| { | ||
| ::closelog(); | ||
| } | ||
|
|
||
| } // namespace os | ||
| } // namespace score | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /******************************************************************************** | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * See the NOTICE file(s) distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Apache License Version 2.0 which is available at | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| ********************************************************************************/ | ||
| #ifndef SCORE_LIB_OS_SYSLOG_IMPL_H | ||
| #define SCORE_LIB_OS_SYSLOG_IMPL_H | ||
|
|
||
| #include "score/os/syslog.h" | ||
|
|
||
| namespace score | ||
|
|
||
| { | ||
| namespace os | ||
| { | ||
|
|
||
| class SyslogImpl : public Syslog | ||
| { | ||
| public: | ||
| void openlog(const char* const ident, | ||
| const std::int32_t option, | ||
| const std::int32_t facility) const noexcept override; | ||
|
|
||
| void syslog(const std::int32_t priority, const char* const format, ...) const noexcept override | ||
| __attribute__((format(printf, 3, 4))); | ||
|
|
||
| void closelog() const noexcept override; | ||
| }; | ||
|
|
||
| } // namespace os | ||
| } // namespace score | ||
|
|
||
| #endif // SCORE_LIB_OS_SYSLOG_IMPL_H | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QNX has syslog API as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the idea to use slog on qnx and only syslog on linux providing the equivalent functionality on target.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not to give freedom to use it also on QNX? I would add qnx target as far as code is the same
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as i mentioned - the kSystem log mode on QNX is already filled by slog and its widely used on QNX and it make sense to use that.
so i would assume the choice of the users to use slog vs syslog on QNX is more of a different ask. Till the community show interest to have this dual choice. its best we treat this and compile for Linux only and enable for QNX later (until we find a genuine user for this back end)
If there is a interest and the enablement for QNX can come later as a different requirement if that's the need.