Skip to content

Commit

Permalink
chore: first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sjinks committed Sep 20, 2024
0 parents commit b8f6540
Show file tree
Hide file tree
Showing 15 changed files with 762 additions and 0 deletions.
181 changes: 181 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
---
Language: Cpp
AccessModifierOffset: -4
AlignAfterOpenBracket: BlockIndent
AlignArrayOfStructures: None
AlignConsecutiveAssignments:
Enabled: true
AcrossEmptyLines: false
AcrossComments: true
AlignCompound: true
AlignFunctionPointers: false
PadOperators: true
AlignConsecutiveBitFields:
Enabled: true
AcrossEmptyLines: false
AcrossComments: true
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: AcrossComments
# AlignConsecutiveShortCaseStatements: false
AlignEscapedNewlines: Left
AlignOperands: Align
AlignTrailingComments:
Kind: Always
OverEmptyLines: 0
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowBreakBeforeNoexceptSpecifier: OnlyWithParen
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortCompoundRequirementOnASingleLine: true
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BitFieldColonSpacing: Both
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: MultiLine
AfterEnum: false
AfterExternBlock: false
AfterFunction: true
AfterNamespace: false
AfterStruct: false
AfterUnion: false
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
# BracedInitializerIndentWidth: 4
# BreakAdjacentStringLiterals: false
BreakAfterAttributes: Never
BreakArrays: false
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: Always
BreakBeforeInlineASMColon: OnlyMultiline
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: AfterComma
BreakStringLiterals: true
CommentPragmas: '^ NO(LINT|SONAR)'
CompactNamespaces: false
ColumnLimit: 120
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: true
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '"stdafx\.h"'
Priority: -1
SortPriority: 0
CaseSensitive: false
- Regex: '^<[^.]+>'
Priority: 1
SortPriority: 0
CaseSensitive: false
- Regex: '^<.*\.h>'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^<.*'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 4
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '([-_](test|unittest))?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: true
IndentExternBlock: AfterExternBlock
IndentGotoLabels: true
IndentPPDirectives: AfterHash
IndentRequiresClause: false
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertBraces: false
InsertNewlineAtEOF: false
InsertTrailingCommas: None
IntegerLiteralSeparator:
Binary: 4
BinaryMinDigits: 8
Decimal: 3
DecimalMinDigits: 7
Hex: 4
HexMinDigits: 8
KeepEmptyLinesAtTheStartOfBlocks: false
LambdaBodyIndentation: Signature
LineEnding: DeriveLF
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PPIndentWidth: -1
PackConstructorInitializers: BinPack
PointerAlignment: Left
QualifierAlignment: Leave
ReferenceAlignment: Pointer
ReflowComments: true
RemoveBracesLLVM: false
RemoveSemicolon: false
RequiresClausePosition: OwnLine
RequiresExpressionIndentation: OuterScope
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 0
SortIncludes: CaseSensitive
SortUsingDeclarations: Lexicographic
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
# SpaceBeforeJsonColon: false
SpaceBeforeParens: ControlStatementsExceptControlMacros
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: Never
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
# SpacesInParens: Never
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Latest
StatementAttributeLikeMacros:
- Q_EMIT
- emit
StatementMacros:
- Q_UNUSED
TabWidth: 4
UseTab: Never
4 changes: 4 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
Checks: 'bugprone-*,cert-*,clang-analyzer-*,concurrency-*,cppcoreguidelines-*,hicpp-*,misc-*,modernize-*,performance-*,portability-*,readability-*,-modernize-use-trailing-return-type,-bugprone-easily-swappable-parameters,-readability-identifier-length,-readability-named-parameter,-hicpp-special-member-functions,-hicpp-use-equals-default,-hicpp-move-const-arg,-hicpp-named-parameter,-hicpp-vararg,-misc-include-cleaner,-cppcoreguidelines-pro-type-union-access,-misc-non-private-member-variables-in-classes,-*-avoid-do-while'
FormatStyle: none
HeaderFilterRegex: '.*'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.vscode/
/build/
27 changes: 27 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
cmake_minimum_required(VERSION 3.25)

project(opentelemetry_exporter_syslog_logs VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "ON")

option(WITH_TESTING "Whether to enable tests" ON)
option(INSTALL_SYSLOG_EXPORTER "Whether to install the syslog exporter" ON)

# Logs signal became stable in v1.11.0, see https://github.com/open-telemetry/opentelemetry-cpp/pull/2229, https://github.com/open-telemetry/opentelemetry-cpp/blob/v1.11.0/CHANGELOG.md
find_package(opentelemetry-cpp CONFIG REQUIRED)
if(opentelemetry-cpp_VERSION VERSION_LESS 1.11.0)
message(FATAL_ERROR "opentelemetry-cpp version must be at least 1.11.0, ${opentelemetry-cpp_VERSION} found")
endif()

add_subdirectory(src)

if(WITH_TESTING)
include(FindGTest)
find_package(GTest CONFIG COMPONENTS gtest gmock)
if(TARGET GTest::gtest AND TARGET GTest::gmock)
include(CTest)
enable_testing()
add_subdirectory(test)
else()
message(WARNING "GTest not found, tests will not be built")
endif()
endif()
15 changes: 15 additions & 0 deletions cmake/opentelemetry_exporter_syslog_logs-config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
get_filename_component(OTEL_SYSLOG_EXPORTER_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)

list(APPEND CMAKE_MODULE_PATH ${OTEL_SYSLOG_EXPORTER_CMAKE_DIR})

include(CMakeFindDependencyMacro)
find_dependency(opentelemetry-cpp QUIET REQUIRED COMPONENTS logs)
if(opentelemetry-cpp_VERSION VERSION_LESS 1.11.0)
message(FATAL_ERROR "opentelemetry-cpp version must be at least 1.11.0, ${opentelemetry-cpp_VERSION} found")
endif()

if(NOT TARGET opentelemetry_exporter_syslog_logs::opentelemetry_exporter_syslog_logs)
include("${OTEL_SYSLOG_EXPORTER_CMAKE_DIR}/opentelemetry_exporter_syslog_logs-target.cmake")
endif()

set(OTEL_SYSLOG_EXPORTER_LIBRARIES opentelemetry_exporter_syslog_logs::opentelemetry_exporter_syslog_logs)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef FD634219_63FB_4E23_BC1D_6DB0BC20B6BE
#define FD634219_63FB_4E23_BC1D_6DB0BC20B6BE

#include <memory>
#include <opentelemetry/nostd/string_view.h>
#include <opentelemetry/sdk/logs/exporter.h>

#include "opentelemetry_exporter_syslog_logs_export.h"
#include "syslog_interface.h"

namespace opentelemetry::exporter::logs {

class OPENTELEMETRY_EXPORTER_SYSLOG_LOGS_EXPORT SyslogLogRecordExporterFactory {
public:
static std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter> Create(opentelemetry::nostd::string_view ident);

static std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter>
Create(opentelemetry::nostd::string_view ident, int option, int facility);

static std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter>
Create(opentelemetry::nostd::string_view ident, const std::shared_ptr<SyslogInterface>& syslog);

static std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter> Create(
opentelemetry::nostd::string_view ident, const std::shared_ptr<SyslogInterface>& syslog, int option,
int facility
);

static void setSyslogImplementation(const std::shared_ptr<SyslogInterface>& syslog);
};

} // namespace opentelemetry::exporter::logs

#endif /* FD634219_63FB_4E23_BC1D_6DB0BC20B6BE */
20 changes: 20 additions & 0 deletions include/opentelemetry_exporter_syslog_logs/syslog_interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef F6CC3A7F_2A2D_4616_B15D_A7739D98F053
#define F6CC3A7F_2A2D_4616_B15D_A7739D98F053

#include <opentelemetry/nostd/string_view.h>
#include "opentelemetry_exporter_syslog_logs_export.h"

namespace opentelemetry::exporter::logs {

// NOLINTNEXTLINE(*-special-member-functions)
class OPENTELEMETRY_EXPORTER_SYSLOG_LOGS_EXPORT SyslogInterface {
public:
virtual ~SyslogInterface() = default;
virtual void openlog(opentelemetry::nostd::string_view ident, int option, int facility) = 0;
virtual void syslog(int priority, opentelemetry::nostd::string_view message) = 0;
virtual void closelog() = 0;
};

} // namespace opentelemetry::exporter::logs

#endif /* F6CC3A7F_2A2D_4616_B15D_A7739D98F053 */
74 changes: 74 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
include(GenerateExportHeader)

set(sources
syslog_exporter.cpp
syslog_exporter_factory.cpp
default_syslog_implementation_p.cpp
)

set(headers
${CMAKE_CURRENT_BINARY_DIR}/opentelemetry_exporter_syslog_logs_export.h
${CMAKE_SOURCE_DIR}/include/opentelemetry_exporter_syslog_logs/syslog_exporter_factory.h
${CMAKE_SOURCE_DIR}/include/opentelemetry_exporter_syslog_logs/syslog_interface.h
)

add_library(${PROJECT_NAME} ${sources})
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
target_link_libraries(${PROJECT_NAME} PUBLIC opentelemetry-cpp::logs)

target_include_directories(${PROJECT_NAME}
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}
)

set_target_properties(
${PROJECT_NAME}
PROPERTIES
CXX_EXTENSIONS OFF
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON
POSITION_INDEPENDENT_CODE ON
PUBLIC_HEADER "${headers}"
INTERFACE_COMPILE_FEATURES cxx_std_17
)

generate_export_header(${PROJECT_NAME} BASE_NAME ${PROJECT_NAME})
if(NOT BUILD_SHARED_LIBS)
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS -DOPENTELEMETRY_EXPORTER_SYSLOG_LOGS_STATIC_DEFINE)
endif()

if(INSTALL_SYSLOG_EXPORTER)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

install(
TARGETS ${PROJECT_NAME}
EXPORT "${PROJECT_NAME}-target"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}"
)

install(EXPORT "${PROJECT_NAME}-target"
FILE "${PROJECT_NAME}-target.cmake"
NAMESPACE "${PROJECT_NAME}::"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)

write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
"${CMAKE_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)
endif()
13 changes: 13 additions & 0 deletions src/default_syslog_implementation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef D17D59F2_0FDF_4FF4_96EE_244866D19190
#define D17D59F2_0FDF_4FF4_96EE_244866D19190

#include "opentelemetry_exporter_syslog_logs/syslog_interface.h"

class DefaultSyslogImplementation : public opentelemetry::exporter::logs::SyslogInterface {
public:
void openlog(opentelemetry::nostd::string_view ident, int option, int facility) override;
void syslog(int priority, opentelemetry::nostd::string_view message) override;
void closelog() override;
};

#endif /* D17D59F2_0FDF_4FF4_96EE_244866D19190 */
18 changes: 18 additions & 0 deletions src/default_syslog_implementation_p.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "default_syslog_implementation.h"

#include <syslog.h>

void DefaultSyslogImplementation::openlog(opentelemetry::nostd::string_view ident, int option, int facility)
{
::openlog(ident.data(), option, facility);
}

void DefaultSyslogImplementation::syslog(int priority, opentelemetry::nostd::string_view message)
{
::syslog(priority, "%s", message.data()); // NOLINT(*-type-vararg)
}

void DefaultSyslogImplementation::closelog()
{
::closelog();
}
Loading

0 comments on commit b8f6540

Please sign in to comment.