├── test ├── corpora │ ├── cstring │ │ ├── zh-cn │ │ └── ascii │ └── invalid_param_name │ │ ├── 1 │ │ ├── 2 │ │ └── 3 ├── function │ ├── startup │ │ ├── README.md │ │ ├── get_error_stream.cpp │ │ ├── perror.cpp │ │ ├── current_target.cpp │ │ ├── error_memory_failure.cpp │ │ └── entry_memory_failure.cpp │ ├── cpp │ │ ├── param.cpp │ │ ├── target │ │ │ ├── wel.cpp │ │ │ ├── network.cpp │ │ │ └── stream.cpp │ │ ├── memory.cpp │ │ ├── element.cpp │ │ └── version.cpp │ ├── python │ │ └── version.py │ ├── windows │ │ └── events.mc │ ├── leak │ │ ├── error.cpp │ │ ├── wel_supported.cpp │ │ ├── target.cpp │ │ └── buffer.cpp │ ├── level │ │ ├── all_enabled.cpp │ │ ├── all_disabled.cpp │ │ ├── enable_upto_debug.cpp │ │ ├── enable_upto_info.cpp │ │ ├── enable_upto_alert.cpp │ │ ├── enable_upto_err.cpp │ │ ├── enable_upto_notice.cpp │ │ ├── enable_upto_warning.cpp │ │ ├── enable_upto_crit.cpp │ │ └── enable_upto_emerg.cpp │ ├── config │ │ └── socket_supported.cpp │ └── README.md ├── fuzz │ ├── stump_str.cpp │ └── add_message_str.cpp ├── performance │ ├── README.md │ ├── version.cpp │ └── target │ │ ├── buffer.cpp │ │ ├── sqlite3.cpp │ │ ├── wel.cpp │ │ └── journald.cpp ├── thread_safety │ └── target │ │ ├── wel.cpp │ │ └── file.cpp └── helper │ └── usage.cpp ├── l10n └── zh-cn │ ├── 文档 │ └── 示例 │ │ └── 简单 │ │ └── 自述.md │ ├── 包含 │ └── stumpless.h │ └── 自述.md ├── Gemfile ├── tools ├── wrapture │ ├── no_wel_templates.yml │ ├── target.yml │ ├── sqlite3_target.yml │ ├── chain_target.yml │ ├── priority.yml │ ├── severity.yml │ ├── file_target.yml │ ├── socket_target.yml │ └── journald_target.yml ├── check_headers │ ├── benchmark.yml │ ├── cpp_standard_library.yml │ ├── gtest.yml │ ├── sqlite.yml │ ├── c_standard_library.yml │ ├── stumplesscpp.yml │ └── README.md ├── cmake │ ├── install_html.cmake │ ├── fuzz_tests.cmake │ ├── swig.cmake │ ├── gtest.cmake │ ├── examples.cmake │ ├── config_files.cmake │ ├── performance_tests.cmake │ ├── thread_safety_tests.cmake │ ├── chain.cmake │ ├── socket.cmake │ ├── cpp_test.cmake │ ├── example.cmake │ └── sqlite3.cmake ├── sonar │ └── sonar-project.properties ├── pkg-config │ └── libstumpless.pc.in └── README.md ├── .vscode └── extensions.json ├── Gemfile.lock ├── scripts ├── copy_headers.rb ├── README.md └── Repair-HeaderDllExports.ps1 ├── src ├── swig │ └── stumpless.i ├── config │ ├── have_unistd.c │ ├── no_gmtime.c │ ├── have_unistd_getpagesize.c │ ├── abstract_socket_names_unsupported.c │ ├── abstract_socket_names_supported.c │ ├── socket_supported.c │ ├── have_fopen_s.c │ ├── unistd_sysconf_getpagesize_supported.c │ ├── no_strncasecmp.c │ ├── have_pthread.c │ ├── have_unistd_gethostname.c │ ├── have_vsnprintf_s.c │ ├── thread_safety_unsupported.c │ ├── thread_safety_supported.c │ ├── windows_get_now_supported.c │ ├── have_gmtime_r.c │ ├── chain_unsupported.c │ ├── have_gmtime.c │ ├── no_vsnprintf_s.c │ └── no_wcsrtombs_s.c ├── filter.c ├── inthelper.c └── strhelper.c ├── .github ├── pull_request_template.md ├── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md └── workflows │ └── locale.yml ├── .gitattributes ├── docs ├── acronyms.md ├── examples │ ├── wel │ │ └── example_events.mc │ ├── file │ │ └── README.md │ ├── socket │ │ └── README.md │ ├── README.md │ └── stream │ │ └── README.md ├── ide-setup.md └── cpp.md ├── .gitignore ├── CITATION.cff └── include ├── README.md ├── test ├── config.hpp.in └── helper │ ├── resolve.hpp │ ├── utf8.hpp │ ├── usage.hpp │ ├── memory_allocation.hpp │ ├── assert.hpp │ └── network.hpp ├── private ├── config │ ├── have_unistd.h │ ├── have_fopen_s.h │ ├── have_unistd_getpagesize.h │ ├── socket_supported.h │ ├── have_unistd_gethostname.h │ ├── no_vsnprintf_s.h │ ├── have_vsnprintf_s.h │ ├── abstract_socket_names_supported.h │ ├── unistd_sysconf_getpagesize_supported.h │ ├── abstract_socket_names_unsupported.h │ ├── wrapper │ │ ├── fopen.h │ │ ├── format_string.h │ │ ├── strncasecmp.h │ │ ├── getpid.h │ │ ├── gethostbyname.h │ │ ├── chain.h │ │ ├── int_connect.h │ │ ├── wstring.h │ │ ├── sqlite3.h │ │ ├── gethostname.h │ │ ├── get_now.h │ │ ├── getpagesize.h │ │ ├── open_default_target.h │ │ ├── journald.h │ │ └── wel.h │ ├── have_pthread.h │ ├── thread_safety_unsupported.h │ ├── have_stdatomic.h │ ├── no_gmtime.h │ ├── windows_get_now_supported.h │ └── have_gmtime_r.h ├── deprecate.h ├── target │ ├── function.h │ └── socket.h ├── windows_wrapper.h └── prival.h └── stumpless ├── id.h └── generator.h /test/corpora/cstring/zh-cn: -------------------------------------------------------------------------------- 1 | 没有错误 -------------------------------------------------------------------------------- /l10n/zh-cn/文档/示例/简单/自述.md: -------------------------------------------------------------------------------- 1 | # 简单 2 | -------------------------------------------------------------------------------- /test/corpora/cstring/ascii: -------------------------------------------------------------------------------- 1 | ASCII Message -------------------------------------------------------------------------------- /test/corpora/invalid_param_name/1: -------------------------------------------------------------------------------- 1 | par=am -------------------------------------------------------------------------------- /test/corpora/invalid_param_name/2: -------------------------------------------------------------------------------- 1 | par]am -------------------------------------------------------------------------------- /test/corpora/invalid_param_name/3: -------------------------------------------------------------------------------- 1 | par\"am -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'wrapture', '~> 0.5.0' 4 | -------------------------------------------------------------------------------- /tools/wrapture/no_wel_templates.yml: -------------------------------------------------------------------------------- 1 | version: "0.4.0" 2 | templates: 3 | - name: "wel-functions" 4 | value: [] 5 | -------------------------------------------------------------------------------- /tools/check_headers/benchmark.yml: -------------------------------------------------------------------------------- 1 | "benchmark::State": "benchmark/benchmark.h" 2 | "BENCHMARK_F": "benchmark/benchmark.h" 3 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "ms-vscode.cpptools", 4 | "ms-vscode.cmake-tools", 5 | "ms-python.python" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | wrapture (0.5.0) 5 | 6 | PLATFORMS 7 | ruby 8 | 9 | DEPENDENCIES 10 | wrapture (~> 0.5.0) 11 | 12 | BUNDLED WITH 13 | 2.2.1 14 | -------------------------------------------------------------------------------- /scripts/copy_headers.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'fileutils' 4 | 5 | Dir.glob('*.hpp') do |filename| 6 | new_filename = File.join(ARGV[0], filename) 7 | FileUtils.copy_file(filename, new_filename) 8 | end 9 | -------------------------------------------------------------------------------- /tools/cmake/install_html.cmake: -------------------------------------------------------------------------------- 1 | set(HTML_BUILD_DIR "${PROJECT_BINARY_DIR}/docs/${STUMPLESS_LANGUAGE}/html") 2 | 3 | install(DIRECTORY "${HTML_BUILD_DIR}" 4 | DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/doc/libstumpless" 5 | ) 6 | -------------------------------------------------------------------------------- /tools/sonar/sonar-project.properties: -------------------------------------------------------------------------------- 1 | sonar.organization=goatshriek-github 2 | sonar.projectKey=stumpless 3 | sonar.sources=src,test 4 | sonar.cfamily.threads=1 5 | sonar.cfamily.build-wrapper-output=bw-output 6 | sonar.sourceEncoding=UTF-8 7 | sonar.python.version=3.8,3.9,3.10,3.11,3.12 8 | -------------------------------------------------------------------------------- /src/swig/stumpless.i: -------------------------------------------------------------------------------- 1 | %module stumpless 2 | %{ 3 | #include "stumpless.h" 4 | #include "stumpless/config.h" 5 | #include "stumpless/error.h" 6 | #include "stumpless/version.h" 7 | %} 8 | 9 | %include "stumpless.h" 10 | %include "stumpless/config.h" 11 | %include "stumpless/error.h" 12 | %include "stumpless/version.h" 13 | -------------------------------------------------------------------------------- /tools/pkg-config/libstumpless.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${exec_prefix}/lib 4 | includedir=${prefix}/include 5 | 6 | Name: libstumpless 7 | Description: @PROJECT_DESCRIPTION@ 8 | Version: @PROJECT_VERSION@ 9 | Libs: -L${libdir} -lstumpless 10 | Cflags: -I${includedir} 11 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | Describe the overall purpose of your pull request in a few sentences, keeping 2 | things at a high level. If this request is in response to a particular issue, 3 | include a reference to it here. 4 | 5 | Make sure that your pull request follows the guidelines specified in the 6 | [Guidelines for Contributing](https://github.com/goatshriek/stumpless/blob/latest/docs/CONTRIBUTING.md). 7 | -------------------------------------------------------------------------------- /tools/cmake/fuzz_tests.cmake: -------------------------------------------------------------------------------- 1 | file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/fuzz-corpora") 2 | 3 | add_fuzz_test(add_message_str 4 | SOURCES "${PROJECT_SOURCE_DIR}/test/fuzz/add_message_str.cpp" 5 | CORPUS_NAME cstring 6 | ) 7 | 8 | add_fuzz_test(stump_str 9 | SOURCES "${PROJECT_SOURCE_DIR}/test/fuzz/stump_str.cpp" 10 | CORPUS_NAME cstring 11 | ) 12 | 13 | add_custom_target(fuzz 14 | DEPENDS ${STUMPLESS_FUZZ_TESTS} 15 | ) 16 | -------------------------------------------------------------------------------- /test/function/startup/README.md: -------------------------------------------------------------------------------- 1 | # Startup Tests 2 | 3 | Because many of the internals of stumpless are lazily initialized, it's 4 | difficult to write tests that catch these initializations because they often 5 | occur during earlier tests. Therefore, it's necessary to write test suites with 6 | single or only a few tests that can carefully control the internal state and 7 | cover failure scenarios that can occur during initialization, most commonly 8 | memory allocation failures. 9 | -------------------------------------------------------------------------------- /tools/check_headers/cpp_standard_library.yml: -------------------------------------------------------------------------------- 1 | "atomic_int": "atomic" 2 | "chrono": "chrono" 3 | "cout": "iostream" 4 | "get_id": "thread" 5 | "mutex": "mutex" 6 | "size_t": 7 | - "cstddef" 8 | - "cstdio" 9 | - "cstdlib" 10 | - "cstring" 11 | - "ctime" 12 | "string": "string" 13 | "thread": "thread" 14 | "uniform_int_distribution": "random" 15 | "unordered_set": "unordered_set" 16 | "va_end": "cstdarg" 17 | "va_list": "cstdarg" 18 | "va_start": "cstdarg" 19 | "filesystem": "filesystem" 20 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text eol=lf 2 | 3 | *.c text eol=lf 4 | *.cpp text eol=lf linguist-documentation 5 | *.cmake text eol=lf 6 | *.def text eol=crlf 7 | *.h text eol=lf linguist-language=C 8 | *.hpp text eol=lf linguist-documentation 9 | *.i text eol=lf 10 | *.mc text eol=crlf 11 | *.pl text eol=lf 12 | *.ps1 text eol=crlf 13 | *.sh text eol=lf 14 | *.svg text eol=lf 15 | *.rb text eol=lf 16 | *.txt text eol=lf 17 | *.xml text eol=lf 18 | *.yml text eol=lf 19 | -------------------------------------------------------------------------------- /tools/check_headers/gtest.yml: -------------------------------------------------------------------------------- 1 | "ASSERT_EQ": "gtest/gtest.h" 2 | "ASSERT_THAT": "gmock/gmock.h" 3 | "ASSERT_TRUE": "gtest/gtest.h" 4 | "BENCHMARK": "benchmark/benchmark.h" 5 | "BENCHMARK_MAIN": "benchmark/benchmark.h" 6 | "EndsWith": "gmock/gmock.h" 7 | "EXPECT_EQ": "gtest/gtest.h" 8 | "EXPECT_THAT": "gmock/gmock.h" 9 | "EXPECT_TRUE": "gtest/gtest.h" 10 | "FAIL": "gtest/gtest.h" 11 | "HasSubstr": "gmock/gmock.h" 12 | "RUN_ALL_TESTS": "gtest/gtest.h" 13 | "Test": "gtest/gtest.h" 14 | "TEST": "gtest/gtest.h" 15 | "TEST_F": "gtest/gtest.h" 16 | -------------------------------------------------------------------------------- /tools/check_headers/sqlite.yml: -------------------------------------------------------------------------------- 1 | "SQLITE_BUSY": "sqlite3.h" 2 | "SQLITE_DONE": "sqlite3.h" 3 | "SQLITE_OK": "sqlite3.h" 4 | "sqlite3": "sqlite3.h" 5 | "sqlite3_bind_int": "sqlite3.h" 6 | "sqlite3_bind_parameter_index": "sqlite3.h" 7 | "sqlite3_bind_text": "sqlite3.h" 8 | "sqlite3_close_v2": "sqlite3.h" 9 | "sqlite3_column_int": "sqlite3.h" 10 | "sqlite3_column_text": "sqlite3.h" 11 | "sqlite3_finalize": "sqlite3.h" 12 | "sqlite3_open": "sqlite3.h" 13 | "sqlite3_reset": "sqlite3.h" 14 | "sqlite3_step": "sqlite3.h" 15 | "sqlite3_stmt": "sqlite3.h" 16 | -------------------------------------------------------------------------------- /docs/acronyms.md: -------------------------------------------------------------------------------- 1 | While every effort is made to keep function and symbol names clear and concise, 2 | there are some situations in which the advantage of the brevity of an acronym, 3 | nickname, or other shortening outweighs the increased clarity of spelling 4 | everything out. To help newcomers to the codebase cope with these situations, 5 | this document expands on these terms as they are used. 6 | 7 | * _w: wide string version (used for Windows functions) 8 | * init: initialize 9 | * l10n: localization ('l', 10 letters, 'n') 10 | * wel: Windows Event Log 11 | -------------------------------------------------------------------------------- /test/fuzz/stump_str.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | extern "C" 7 | int 8 | LLVMFuzzerTestOneInput( const uint8_t *data, size_t size ) { 9 | char terminated_data[size+1]; 10 | char buffer[8192]; 11 | struct stumpless_target *target; 12 | 13 | memcpy( terminated_data, data, size ); 14 | terminated_data[size] = '\0'; 15 | 16 | target = stumpless_open_buffer_target( "fuzzer", buffer, sizeof( buffer ) ); 17 | stump_str( terminated_data ); 18 | stumpless_close_buffer_target( target ); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.c~ 2 | *.cpp~ 3 | *.cpz~ 4 | docs/html/* 5 | *.h~ 6 | *.hpp~ 7 | *.o 8 | *.log 9 | *.so 10 | *.swp 11 | .vs/* 12 | .vscode/* 13 | !.vscode/extensions.json 14 | CMakeSettings.json 15 | **/.DS_Store 16 | 17 | # Ignore files generated by CMake 18 | build/* 19 | 20 | # Ignore files generated by VS 21 | out/* 22 | 23 | # Ignore tags created by etags, ctags, gtags (GNU global) and cscope 24 | TAGS 25 | .TAGS 26 | !TAGS/ 27 | tags 28 | .tags 29 | !tags/ 30 | gtags.files 31 | GTAGS 32 | GRTAGS 33 | GPATH 34 | GSYMS 35 | cscope.files 36 | cscope.out 37 | cscope.in.out 38 | cscope.po.out 39 | 40 | 41 | -------------------------------------------------------------------------------- /CITATION.cff: -------------------------------------------------------------------------------- 1 | cff-version: 1.2.0 2 | title: Stumpless Logging Library 3 | license: Apache-2.0 4 | repository-code: "https://github.com/goatshriek/stumpless" 5 | version: 3.0.0 6 | date-released: 2024-11-28 7 | keywords: 8 | - journald 9 | - logging 10 | - library 11 | - "structured logging" 12 | - syslog 13 | - systemd 14 | - "windows event log" 15 | type: software 16 | message: >- 17 | If you use this software, please cite it using the 18 | metadata from this file. 19 | type: software 20 | authors: 21 | - given-names: Joel 22 | family-names: Anderson 23 | email: joel@goatshriek.com 24 | -------------------------------------------------------------------------------- /test/performance/README.md: -------------------------------------------------------------------------------- 1 | # Performance Testing 2 | 3 | Performance testing consists of performing a variety of benchmarks on each 4 | function in the library. These tests are performed using the Google Benchmark 5 | library, and can be used to determine the impacts of a change during 6 | development or to compare builds. 7 | 8 | Please keep in mind that performance statistics are highly dependent on the 9 | platform on which they are run. The benchmarks provided here are meant only to 10 | give relative indicators of performance on the same system, and not as 11 | absolute indicators of what will happen on any system. 12 | -------------------------------------------------------------------------------- /test/fuzz/add_message_str.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | extern "C" 7 | int 8 | LLVMFuzzerTestOneInput( const uint8_t *data, size_t size ) { 9 | char terminated_data[size+1]; 10 | char buffer[8192]; 11 | struct stumpless_target *target; 12 | 13 | memcpy( terminated_data, data, size ); 14 | terminated_data[size] = '\0'; 15 | 16 | target = stumpless_open_buffer_target( "fuzzer", buffer, sizeof( buffer ) ); 17 | stumpless_add_message_str( target, terminated_data ); 18 | stumpless_close_buffer_target( target ); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /tools/cmake/swig.cmake: -------------------------------------------------------------------------------- 1 | macro(add_swig_project) 2 | ExternalProject_Add(swig 3 | URL https://github.com/swig/swig/archive/master.zip 4 | PREFIX ${CMAKE_BINARY_DIR}/swig 5 | CONFIGURE_COMMAND cd && /autogen.sh && cd && /configure --without-alllang --with-python 6 | BUILD_COMMAND ${MAKE} 7 | INSTALL_COMMAND "" 8 | ) 9 | 10 | set_target_properties(swig 11 | PROPERTIES 12 | EXCLUDE_FROM_ALL TRUE 13 | ) 14 | 15 | ExternalProject_Get_Property(swig 16 | source_dir 17 | ) 18 | 19 | ExternalProject_Get_Property(swig 20 | binary_dir 21 | ) 22 | endmacro(add_swig_project) 23 | -------------------------------------------------------------------------------- /include/README.md: -------------------------------------------------------------------------------- 1 | The include files within the project are split into two types: private and 2 | public. Private headers are those that are only used within the source files for 3 | the library and are not exposed in the installed headers. These headers are 4 | contained in the `private` folder. 5 | 6 | The files in the `stumpless` directory as well as the `stumpless.h` include file 7 | itself are installed with the project and can be used to call functions from the 8 | library. These header files are compatible with both C and C++ compilers. 9 | 10 | Some headers are only used by tests for the project. These headers are kept in 11 | the `test` subdirectory of the include directory. 12 | -------------------------------------------------------------------------------- /scripts/README.md: -------------------------------------------------------------------------------- 1 | These scripts are useful for various development and build tasks. 2 | 3 | ## copy_headers.rb 4 | Copies C++ header files generated by Wrapture into the project generated 5 | include directory. 6 | 7 | This is not the desired end state, but will be needed until Wrapture has a way 8 | to designate the output directory for header files. 9 | 10 | ## Repair-HeaderDllExports.ps1 11 | Modifies a C++ header file to add `__declspec(dllexport)` to all class 12 | declarations. This is needed to patch C++ classes generated by Wrapture so 13 | that the DLL exports the correct functions. 14 | 15 | This is not the desired end state, but will be needed until Wrapture has a way 16 | to do this itself. 17 | -------------------------------------------------------------------------------- /tools/cmake/gtest.cmake: -------------------------------------------------------------------------------- 1 | set(GTEST_URL https://github.com/google/googletest/archive/52eb8108c5bdec04579160ae17225d66034bd723.zip) # v1.17.0 2 | if(CMAKE_VERSION VERSION_LESS "3.24") 3 | # FIND_PACKAGE_ARGS is not available before 3.24, but for now we don't require 4 | # the higher version just for it 5 | FetchContent_Declare( 6 | googletest 7 | URL ${GTEST_URL} 8 | ) 9 | else() 10 | FetchContent_Declare( 11 | googletest 12 | URL ${GTEST_URL} 13 | FIND_PACKAGE_ARGS NAMES GTest 14 | ) 15 | endif() 16 | 17 | # For Windows: Prevent overriding the parent project's compiler/linker settings 18 | set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) 19 | 20 | FetchContent_MakeAvailable(googletest) 21 | -------------------------------------------------------------------------------- /tools/check_headers/c_standard_library.yml: -------------------------------------------------------------------------------- 1 | "atomic_compare_and_exchange_strong": "stdatomic.h" 2 | "atomic_load": "stdatomic.h" 3 | "atomic_store": "stdatomic.h" 4 | "atomic_uintptr_t": "stdatomic.h" 5 | "bool": "stdbool.h" 6 | "CreateTransaction": "ktmw32.h" 7 | "CRITICAL_SECTION": 8 | - "private/windows_wrapper.h" 9 | - "windows.h" 10 | "socket": 11 | - "sys/socket.h" 12 | - "winsock2.h" 13 | "size_t": 14 | - "stddef.h" 15 | - "stdio.h" 16 | - "stdlib.h" 17 | - "string.h" 18 | - "time.h" 19 | "tolower": "ctype.h" 20 | "true": "stdbool.h" 21 | "va_end": "stdarg.h" 22 | "va_list": "stdarg.h" 23 | "va_start": "stdarg.h" 24 | "wchar_t": 25 | - "stddef.h" 26 | - "wchar.h" 27 | "WSAStartup": "winsock2.h" 28 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for stumpless 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of the problem this feature would solve. 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context about the feature request here, such as links to other discussions or related bugs. 21 | -------------------------------------------------------------------------------- /tools/check_headers/stumplesscpp.yml: -------------------------------------------------------------------------------- 1 | # options 2 | "header-alternates": 3 | "stumpless/.*\\.hpp": "stumpless.hpp" 4 | 5 | # terms 6 | "Element": "stumpless/Element.hpp" 7 | "Entry": "stumpless/Entry.hpp" 8 | "ErrorId": "stumpless/ErrorId.hpp" 9 | "Facility": "stumpless/Facility.hpp" 10 | "FileTarget": "stumpless/FileTarget.hpp" 11 | "FreeAll": "stumpless/MemoryManager.hpp" 12 | "GetAppName": "stumpless/Entry.hpp" 13 | "MemoryManager": "stumpless/MemoryManager.hpp" 14 | "NetworkTarget": "stumpless/NetworkTarget.hpp" 15 | "Param": "stumpless/Param.hpp" 16 | "Severity": "stumpless/Severity.hpp" 17 | "StreamTarget": "stumpless/StreamTarget.hpp" 18 | "StumplessException": "stumpless/StumplessException.hpp" 19 | "Version": "stumpless/Version.hpp" 20 | "WelTarget": "stumpless/WelTarget.hpp" 21 | -------------------------------------------------------------------------------- /docs/examples/wel/example_events.mc: -------------------------------------------------------------------------------- 1 | MessageIdTypedef=DWORD 2 | 3 | SeverityNames=( 4 | Success=0x0:CUSTOM_SEVERITY_SUCCESS 5 | Informational=0x1:CUSTOM_SEVERITY_INFORMATIONAL 6 | Warning=0x2:CUSTOM_SEVERITY_WARNING 7 | Error=0x3:CUSTOM_SEVERITY_ERROR 8 | ) 9 | 10 | FacilityNames=( 11 | Normal=0x100:CUSTOM_FACILITY_NORMAL 12 | ) 13 | 14 | LanguageNames=(English=0x0409:MSG00409) 15 | 16 | ; // category definitions 17 | 18 | MessageIdTypedef=WORD 19 | 20 | MessageId=0x1 21 | SymbolicName=CATEGORY_TREE 22 | Language=English 23 | Tree Indetification Events 24 | . 25 | 26 | ; // message definitions 27 | 28 | MessageIdTypedef=DWORD 29 | 30 | MessageId=0x11 31 | Severity=Success 32 | Facility=Normal 33 | SymbolicName=MSG_TREE_IDENTIFIED_BY_CHILD 34 | Language=English 35 | %1 found a %2 tree!. 36 | . 37 | -------------------------------------------------------------------------------- /tools/cmake/examples.cmake: -------------------------------------------------------------------------------- 1 | 2 | add_example(basic 3 | "${PROJECT_SOURCE_DIR}/docs/examples/basic/basic_example.c" 4 | ) 5 | 6 | add_example(entry 7 | "${PROJECT_SOURCE_DIR}/docs/examples/entry/entry_example.c" 8 | ) 9 | 10 | add_example(file 11 | "${PROJECT_SOURCE_DIR}/docs/examples/file/file_example.c" 12 | ) 13 | 14 | add_example(filter 15 | "${PROJECT_SOURCE_DIR}/docs/examples/filter/filter_example.c" 16 | ) 17 | 18 | add_example(function 19 | "${PROJECT_SOURCE_DIR}/docs/examples/function/function_example.c" 20 | ) 21 | 22 | add_example(severity_level 23 | "${PROJECT_SOURCE_DIR}/docs/examples/severity_level/severity_level_example.c" 24 | ) 25 | 26 | add_example(stream 27 | "${PROJECT_SOURCE_DIR}/docs/examples/stream/stream_example.c" 28 | ) 29 | 30 | add_custom_target(examples 31 | DEPENDS ${STUMPLESS_EXAMPLE_RUNNERS} 32 | ) 33 | -------------------------------------------------------------------------------- /l10n/zh-cn/包含/stumpless.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2024 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | 20 | /** @mainpage 无树桩 21 | * 22 | * 无树桩是一个高性能,很多特征的C日志库。 23 | */ 24 | 25 | /** @example basic_example.c 26 | * 简单的示例。 27 | */ 28 | -------------------------------------------------------------------------------- /src/config/have_unistd.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2018-2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include "private/config/have_unistd.h" 21 | 22 | int 23 | unistd_getpid( void ) { 24 | return ( int ) ( getpid( ) ); 25 | } 26 | -------------------------------------------------------------------------------- /src/config/no_gmtime.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2024 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include "private/config/no_gmtime.h" 21 | 22 | size_t 23 | no_gmtime_get_now( char *buffer ) { 24 | *buffer = '-'; 25 | return 1; 26 | } 27 | -------------------------------------------------------------------------------- /docs/ide-setup.md: -------------------------------------------------------------------------------- 1 | # IDE Setup (VS Code) 2 | 3 | This page helps new contributors open the project in **Visual Studio Code** and install a few helpful extensions. It does **not** change build settings; please see the main development docs for build/run details. 4 | 5 | ## 1) Install VS Code 6 | - Download and install VS Code: 7 | 8 | ## 2) Open the project folder 9 | - `File → Open Folder…` and select the repository root. 10 | 11 | ## 3) Accept the recommended extensions 12 | - VS Code will prompt: “This workspace has extension recommendations.” 13 | - Click **Install** to add the minimal set from `.vscode/extensions.json`. 14 | 15 | > If you prefer manual install, see: 16 | 17 | ## 4) Next steps (follow project docs) 18 | - Build, test, and other workflows are documented in **`docs/development.md`**. 19 | -------------------------------------------------------------------------------- /tools/wrapture/target.yml: -------------------------------------------------------------------------------- 1 | version: "0.4.0" 2 | #enums: 3 | # - name: "TargetType" 4 | # doc: "types of targets" 5 | # namespace: "stumpless" 6 | # includes: "stumpless/target.h" 7 | # elements: 8 | # - name: "BUFFER" 9 | # doc: "writes to a character buffer" 10 | # value: "STUMPLESS_BUFFER_TARGET" 11 | # - name: "FILE" 12 | # doc: "writes to a file" 13 | # value: "STUMPLESS_FILE_TARGET" 14 | # - name: "NETWORK" 15 | # doc: "writes to a network endpoint" 16 | # value: "STUMPLESS_NETWORK_TARGET" 17 | # - name: "SOCKET" 18 | # doc: "writes to a Unix socket" 19 | # value: "STUMPLESS_SOCKET_TARGET" 20 | # - name: "STREAM" 21 | # doc: "writes to a FILE stream" 22 | # value: "STUMPLESS_SOCKET_TARGET" 23 | # - name: "WINDOWS" 24 | # doc: "writes to the Windows Event Log" 25 | # value: "STUMPLESS_WINDOWS_EVENT_LOG" 26 | -------------------------------------------------------------------------------- /src/config/have_unistd_getpagesize.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "private/config/have_unistd_getpagesize.h" 22 | 23 | size_t 24 | unistd_getpagesize( void ) { 25 | return ( size_t ) getpagesize( ); 26 | } 27 | -------------------------------------------------------------------------------- /include/test/config.hpp.in: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2023 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_TEST_CONFIG_H 20 | #define __STUMPLESS_TEST_CONFIG_H 21 | 22 | 23 | /* test environment */ 24 | #define FUZZ_CORPORA_DIR "@FUZZ_CORPORA_DIR@" 25 | 26 | 27 | #endif /* __STUMPLESS_TEST_CONFIG_H */ 28 | -------------------------------------------------------------------------------- /include/private/config/have_unistd.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2018-2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_PRIVATE_CONFIG_HAVE_UNISTD_H 20 | # define __STUMPLESS_PRIVATE_CONFIG_HAVE_UNISTD_H 21 | 22 | int unistd_getpid( void ); 23 | 24 | #endif /* __STUMPLESS_PRIVATE_CONFIG_HAVE_UNISTD_H */ 25 | -------------------------------------------------------------------------------- /include/test/helper/resolve.hpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2019 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_TEST_HELPER_RESOLVE_HPP 20 | # define __STUMPLESS_TEST_HELPER_RESOLVE_HPP 21 | 22 | bool 23 | name_resolves( const char *name, int domain ); 24 | 25 | #endif /* __STUMPLESS_TEST_HELPER_RESOLVE_HPP */ 26 | -------------------------------------------------------------------------------- /docs/examples/file/README.md: -------------------------------------------------------------------------------- 1 | # File Targets 2 | 3 | File targets send logs to a given file, a critical function for any logging 4 | library. File targets offer a simple and straightforward mechanic for writing 5 | logs, but note that you will still need a separate system for other functions 6 | like rotating them, encrypting them, or shipping them to another location. 7 | 8 | The name of the target that is created will also be used as the filename. This 9 | should include any paths as well: 10 | 11 | ```c 12 | file_target = stumpless_open_file_target( "path/to/myfile.log" ); 13 | ``` 14 | 15 | Of course logging to file targets is done as with any other: 16 | 17 | ```c 18 | stumpless_add_entry( file_target, entry ); 19 | ``` 20 | 21 | Targets are closed in the usual way: 22 | 23 | ```c 24 | stumpless_close_file_target( file_target ); 25 | ``` 26 | 27 | Or, using the generic (and slightly slower) function: 28 | 29 | ```c 30 | stumpless_close_target( file_target ); 31 | ``` 32 | -------------------------------------------------------------------------------- /include/test/helper/utf8.hpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2018-2023 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_TEST_HELPER_UTF8_HPP 20 | #define __STUMPLESS_TEST_HELPER_UTF8_HPP 21 | 22 | #include 23 | 24 | void TestUTF8Compliance( const std::string &str ); 25 | 26 | #endif /* __STUMPLESS_TEST_HELPER_UTF8_HPP */ 27 | -------------------------------------------------------------------------------- /test/function/cpp/param.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | 21 | namespace { 22 | 23 | class CppParamTest : public ::testing::Test {}; 24 | 25 | TEST( Constructor, NullName ) { 26 | // EXPECT_THROW( Param( NULL, "val" ), StumplessException * ); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us fix problems 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior. Code snippets are preferred, especially if they are easily converted to unit tests that can be used for regression testing. Be sure to include the full output of running the snippet as well. 15 | 16 | **Expected behavior** 17 | A clear and concise description of what you expected to happen with the provided code. 18 | 19 | **Build Environment** 20 | Describe your build environment and any other factors that contribute to the configuration of Stumpless. This should include: 21 | * your operating system (including flavor) 22 | * your compiler 23 | * any options that you pass to cmake 24 | 25 | **Additional context** 26 | Add any other context about the problem here. 27 | -------------------------------------------------------------------------------- /test/function/startup/get_error_stream.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2019 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | namespace { 24 | 25 | TEST( GetErrorStreamStartupTest, Initialization ) { 26 | EXPECT_EQ( stumpless_get_error_stream( ), stderr ); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/config/abstract_socket_names_unsupported.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2022 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "private/config/abstract_socket_names_unsupported.h" 22 | 23 | size_t 24 | no_abstract_socket_names_get_local_socket_name( char *name ) { 25 | memcpy( name, "stumpless-socket", 17 ); 26 | return 17; 27 | } 28 | -------------------------------------------------------------------------------- /include/private/config/have_fopen_s.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2018 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_PRIVATE_CONFIG_HAVE_FOPEN_S_H 20 | # define __STUMPLESS_PRIVATE_CONFIG_HAVE_FOPEN_S_H 21 | 22 | # include 23 | 24 | FILE * 25 | fopen_s_fopen( const char *filename, const char *mode ); 26 | 27 | #endif /* __STUMPLESS_PRIVATE_CONFIG_HAVE_FOPEN_S_H */ 28 | -------------------------------------------------------------------------------- /include/private/config/have_unistd_getpagesize.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_PRIVATE_CONFIG_HAVE_UNISTD_GETPAGESIZE_H 20 | # define __STUMPLESS_PRIVATE_CONFIG_HAVE_UNISTD_GETPAGESIZE_H 21 | 22 | # include 23 | 24 | size_t unistd_getpagesize( void ); 25 | 26 | #endif /* __STUMPLESS_PRIVATE_CONFIG_HAVE_UNISTD_GETPAGESIZE_H */ 27 | -------------------------------------------------------------------------------- /src/config/abstract_socket_names_supported.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2022 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "private/config/abstract_socket_names_supported.h" 22 | 23 | size_t 24 | abstract_socket_names_get_local_socket_name( char *name ) { 25 | name[0] = '\0'; 26 | memcpy( name + 1, "stumpless-socket", 17 ); 27 | return 18; 28 | } 29 | -------------------------------------------------------------------------------- /test/function/startup/perror.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2019 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | namespace { 25 | 26 | TEST( PerrorStartupTest, Initialization ) { 27 | stumpless_perror( NULL ); 28 | 29 | EXPECT_EQ( stumpless_get_error_stream( ), stderr ); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/config/socket_supported.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2019-2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include "private/config/socket_supported.h" 23 | 24 | struct stumpless_target * 25 | socket_open_default_target( void ) { 26 | return stumpless_open_socket_target( STUMPLESS_DEFAULT_SOCKET, NULL ); 27 | } 28 | -------------------------------------------------------------------------------- /include/private/config/socket_supported.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2019 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_PRIVATE_CONFIG_SOCKET_SUPPORTED_H 20 | # define __STUMPLESS_PRIVATE_CONFIG_SOCKET_SUPPORTED_H 21 | 22 | # include 23 | 24 | struct stumpless_target * 25 | socket_open_default_target( void ); 26 | 27 | #endif /* __STUMPLESS_PRIVATE_CONFIG_SOCKET_SUPPORTED_H */ 28 | -------------------------------------------------------------------------------- /include/private/config/have_unistd_gethostname.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_PRIVATE_CONFIG_HAVE_UNISTD_GETHOSTNAME_H 20 | # define __STUMPLESS_PRIVATE_CONFIG_HAVE_UNISTD_GETHOSTNAME_H 21 | 22 | # include 23 | 24 | int unistd_gethostname( char *buffer, size_t namelen ); 25 | 26 | #endif /* __STUMPLESS_PRIVATE_CONFIG_HAVE_UNISTD_GETHOSTNAME_H */ 27 | -------------------------------------------------------------------------------- /include/private/config/no_vsnprintf_s.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2019 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_PRIVATE_CONFIG_NO_VSNPRINTF_S_H 20 | # define __STUMPLESS_PRIVATE_CONFIG_NO_VSNPRINTF_S_H 21 | 22 | # include 23 | # include 24 | 25 | char * 26 | no_vsnprintf_s_format_string( const char *format, va_list subs, size_t *length ); 27 | 28 | #endif /* __STUMPLESS_PRIVATE_CONFIG_NO_VSNPRINTF_S_H */ 29 | -------------------------------------------------------------------------------- /include/private/config/have_vsnprintf_s.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2019 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_PRIVATE_CONFIG_HAVE_VSNPRINTF_S_H 20 | # define __STUMPLESS_PRIVATE_CONFIG_HAVE_VSNPRINTF_S_H 21 | 22 | # include 23 | # include 24 | 25 | char * 26 | vsnprintf_s_format_string( const char *format, va_list subs, size_t *length ); 27 | 28 | #endif /* __STUMPLESS_PRIVATE_CONFIG_HAVE_VSNPRINTF_S_H */ 29 | -------------------------------------------------------------------------------- /include/private/config/abstract_socket_names_supported.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2022 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_PRIVATE_CONFIG_ABSTRACT_SOCKET_NAMES_SUPPORTED_H 20 | # define __STUMPLESS_PRIVATE_CONFIG_ABSTRACT_SOCKET_NAMES_SUPPORTED_H 21 | 22 | # include 23 | 24 | size_t 25 | abstract_socket_names_get_local_socket_name( char *name ); 26 | 27 | #endif /* __STUMPLESS_PRIVATE_CONFIG_ABSTRACT_SOCKET_NAMES_SUPPORTED_H */ 28 | -------------------------------------------------------------------------------- /include/private/config/unistd_sysconf_getpagesize_supported.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2020-2022 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_PRIVATE_CONFIG_UNISTD_SYSCONF_GETPAGESIZE_SUPPORTED_H 20 | # define __STUMPLESS_PRIVATE_CONFIG_UNISTD_SYSCONF_GETPAGESIZE_SUPPORTED_H 21 | 22 | # include 23 | 24 | size_t unistd_sysconf_getpagesize( void ); 25 | 26 | #endif /* __STUMPLESS_PRIVATE_CONFIG_UNISTD_SYSCONF_GETPAGESIZE_UNSUPPORTED_H */ 27 | -------------------------------------------------------------------------------- /src/config/have_fopen_s.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2018-2019 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "private/config/have_fopen_s.h" 22 | 23 | FILE * 24 | fopen_s_fopen( const char *filename, const char *mode ) { 25 | FILE *handle; 26 | errno_t result; 27 | 28 | result = fopen_s( &handle, filename, mode ); 29 | if( result != 0 ){ 30 | return NULL; 31 | } else { 32 | return handle; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /include/private/config/abstract_socket_names_unsupported.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2022 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_PRIVATE_CONFIG_ABSTRACT_SOCKET_NAMES_UNSUPPORTED_H 20 | # define __STUMPLESS_PRIVATE_CONFIG_ABSTRACT_SOCKET_NAMES_UNSUPPORTED_H 21 | 22 | # include 23 | 24 | size_t 25 | no_abstract_socket_names_get_local_socket_name( char *name ); 26 | 27 | #endif /* __STUMPLESS_PRIVATE_CONFIG_ABSTRACT_SOCKET_NAMES_UNSUPPORTED_H */ 28 | -------------------------------------------------------------------------------- /src/filter.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2022 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | bool 25 | stumpless_mask_filter( const struct stumpless_target *target, 26 | const struct stumpless_entry *entry ) { 27 | return STUMPLESS_SEVERITY_MASK( stumpless_get_entry_severity( entry ) ) 28 | & stumpless_get_target_mask( target ); 29 | } 30 | -------------------------------------------------------------------------------- /src/inthelper.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2018 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "private/inthelper.h" 22 | 23 | int 24 | cap_size_t_to_int( size_t val ){ 25 | if( val > INT_MAX ) { 26 | return INT_MAX; 27 | } else { 28 | return ( int ) val; 29 | } 30 | } 31 | 32 | int 33 | size_t_to_int(size_t val) 34 | { 35 | if( val > INT_MAX ) { 36 | return -1; 37 | } else { 38 | return ( int ) val; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tools/wrapture/sqlite3_target.yml: -------------------------------------------------------------------------------- 1 | version: "0.5.0" 2 | classes: 3 | - name: "Sqlite3Target" 4 | namespace: "stumpless" 5 | equivalent-struct: 6 | name: "stumpless_target" 7 | includes: "stumpless/target.h" 8 | constructors: 9 | - doc: "Creates a new target for the given database." 10 | wrapped-function: 11 | name: "stumpless_open_sqlite3_target" 12 | includes: "stumpless/target/sqlite3.h" 13 | params: 14 | - name: "name" 15 | doc: "The filename of the database." 16 | type: "const char *" 17 | return: 18 | type: "equivalent-struct-pointer" 19 | use-template: "pointer-return-error-check" 20 | destructor: 21 | doc: > 22 | Closes this target and releases all memory and other resources held by 23 | it. 24 | wrapped-function: 25 | name: "stumpless_close_sqlite3_target_and_db" 26 | includes: "stumpless/target/sqlite3.h" 27 | params: 28 | - name: "equivalent-struct-pointer" 29 | functions: 30 | - use-template: "common-target-functions" 31 | -------------------------------------------------------------------------------- /include/stumpless/id.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2018-2019 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** @file 20 | * The identification for targets within the library. 21 | */ 22 | 23 | #ifndef __STUMPLESS_ID_H 24 | # define __STUMPLESS_ID_H 25 | 26 | # ifdef __cplusplus 27 | extern "C" { 28 | # endif 29 | 30 | typedef void * stumpless_id_t; 31 | 32 | # ifdef __cplusplus 33 | } /* extern "C" */ 34 | # endif 35 | 36 | #endif /* __STUMPLESS_ID_H */ 37 | -------------------------------------------------------------------------------- /test/function/python/version.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | #Copyright 2018 Joel E. Anderson 4 | # 5 | #Licensed under the Apache License, Version 2.0 (the "License"); 6 | #you may not use this file except in compliance with the License. 7 | #You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | #Unless required by applicable law or agreed to in writing, software 12 | #distributed under the License is distributed on an "AS IS" BASIS, 13 | #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | #See the License for the specific language governing permissions and 15 | #limitations under the License. 16 | 17 | import stumpless 18 | 19 | version = stumpless.stumpless_get_version() 20 | 21 | if version.major != stumpless.STUMPLESS_MAJOR_VERSION: 22 | print("major version attribute did not match module attribute") 23 | 24 | if version.minor != stumpless.STUMPLESS_MINOR_VERSION: 25 | 26 | print("minor version attribute did not match module attribute") 27 | 28 | if version.patch != stumpless.STUMPLESS_PATCH_VERSION: 29 | print("patch version attribute did not match module attribute") 30 | -------------------------------------------------------------------------------- /src/config/unistd_sysconf_getpagesize_supported.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2020-2022 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include "private/config/unistd_sysconf_getpagesize_supported.h" 23 | 24 | size_t 25 | unistd_sysconf_getpagesize( void ) { 26 | long result; 27 | 28 | result = sysconf( _SC_PAGESIZE ); 29 | 30 | if( result < 0 ){ 31 | return STUMPLESS_FALLBACK_PAGESIZE; 32 | } else { 33 | return ( size_t ) result; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tools/README.md: -------------------------------------------------------------------------------- 1 | # Development Tools 2 | Stumpless uses both custom and external tools to make development easier, 3 | implement features, and maintain the code base. This directory has files that 4 | are specific to these tools such as configuration files and scripts. 5 | 6 | 7 | ## [`check_headers`](./check_headers) 8 | A custom tool written to make sure that appropriate headers are included in 9 | sources according to project conventions. 10 | 11 | 12 | ## [`cmake`](./cmake) 13 | CMake scripts used in the configuration and build of Stumpless. 14 | 15 | 16 | ## [`doxygen`](./doxygen) 17 | Configuration files for generating project documentation with Doxygen. 18 | 19 | 20 | ## [`pkg-config`](./pkg-config) 21 | Configuration for `pkg-config` support. 22 | 23 | 24 | ## [`portage`](./portage) 25 | Packaging files for Gentoo's Portage system. 26 | 27 | 28 | ## [`sonar`](./sonar) 29 | Configuration for Sonarcloud code scanning and analysis. 30 | 31 | 32 | ## [`valgrind`](./valgrind) 33 | Configuration files for valgrind, including false positive annotations. 34 | 35 | 36 | ## [`wrapture`](./wrapture) 37 | Templates for generating C++ language bindings with Wrapture. 38 | -------------------------------------------------------------------------------- /include/private/deprecate.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_PRIVATE_DEPRECATE_H 20 | # define __STUMPLESS_PRIVATE_DEPRECATE_H 21 | 22 | # include 23 | 24 | # ifdef STUMPLESS_DEPRECATION_WARNINGS_ENABLED 25 | # include 26 | # define warn_of_deprecation( WARNING ) printf( "DEPRECATED: " WARNING "\n" ) 27 | # else 28 | # define warn_of_deprecation( WARNING ) ( ( void ) 0 ) 29 | # endif 30 | 31 | #endif /* __STUMPLESS_PRIVATE_DEPRECATE_H */ 32 | -------------------------------------------------------------------------------- /test/function/windows/events.mc: -------------------------------------------------------------------------------- 1 | SeverityNames=( 2 | Success=0x0:CUSTOM_SEVERITY_SUCCESS 3 | Informational=0x1:CUSTOM_SEVERITY_INFORMATIONAL 4 | Warning=0x2:CUSTOM_SEVERITY_WARNING 5 | Error=0x3:CUSTOM_SEVERITY_ERROR 6 | ) 7 | 8 | FacilityNames=( 9 | Normal=0x100:CUSTOM_FACILITY_NORMAL 10 | ) 11 | 12 | LanguageNames=(English=0x0409:MSG00409) 13 | 14 | ; // category definitions 15 | 16 | MessageIdTypedef=WORD 17 | 18 | MessageId=0x1 19 | SymbolicName=CATEGORY_TEST 20 | Language=English 21 | Test Category 22 | . 23 | 24 | ; // message definitions 25 | 26 | MessageIdTypedef=DWORD 27 | 28 | MessageId=0x11 29 | Severity=Success 30 | Facility=Normal 31 | SymbolicName=MSG_SIMPLE 32 | Language=English 33 | This is a simple log message. 34 | . 35 | 36 | MessageId=0x12 37 | Severity=Success 38 | Facility=Normal 39 | SymbolicName=MSG_ONE_INSERTION 40 | Language=English 41 | This is a simple log message with one insertion: %1. 42 | . 43 | 44 | MessageId=0x13 45 | Severity=Success 46 | Facility=Normal 47 | SymbolicName=MSG_TWO_INSERTIONS 48 | Language=English 49 | This is a simple log message with two insertions: %1 and %2. 50 | . 51 | -------------------------------------------------------------------------------- /test/function/startup/current_target.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2019-2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "test/helper/assert.hpp" 22 | 23 | namespace { 24 | 25 | TEST( CurrentTargetStartupTest, Default ) { 26 | struct stumpless_target *target; 27 | 28 | target = stumpless_get_current_target( ); 29 | 30 | EXPECT_NO_ERROR; 31 | EXPECT_NOT_NULL( target ); 32 | EXPECT_EQ( target, stumpless_get_default_target( ) ); 33 | 34 | stumpless_free_all( ); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /include/private/config/wrapper/fopen.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2022 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_PRIVATE_CONFIG_WRAPPER_FOPEN_H 20 | # define __STUMPLESS_PRIVATE_CONFIG_WRAPPER_FOPEN_H 21 | 22 | # include "private/config.h" 23 | 24 | /* definition of config_fopen */ 25 | # ifdef HAVE_FOPEN_S 26 | # include "private/config/have_fopen_s.h" 27 | # define config_fopen fopen_s_fopen 28 | # else 29 | # include 30 | # define config_fopen fopen 31 | # endif 32 | 33 | #endif /* __STUMPLESS_PRIVATE_CONFIG_WRAPPER_FOPEN_H */ -------------------------------------------------------------------------------- /include/test/helper/usage.hpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2020-2024 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_TEST_HELPER_USAGE_HPP 20 | # define __STUMPLESS_TEST_HELPER_USAGE_HPP 21 | 22 | # include 23 | # include 24 | 25 | void 26 | add_messages( struct stumpless_target *target, size_t message_count ); 27 | 28 | void 29 | repeat_add_entry( struct stumpless_target *target, 30 | const struct stumpless_entry *entry, 31 | size_t _count ); 32 | 33 | #endif /* __STUMPLESS_TEST_HELPER_USAGE_HPP */ 34 | -------------------------------------------------------------------------------- /tools/wrapture/chain_target.yml: -------------------------------------------------------------------------------- 1 | version: "0.5.0" 2 | classes: 3 | - name: "ChainTarget" 4 | doc: > 5 | A target allowing entries to be sent to a sequence of targets. 6 | namespace: "stumpless" 7 | equivalent-struct: 8 | name: "stumpless_target" 9 | includes: "stumpless/target.h" 10 | constructors: 11 | - doc: "Creates a new chain target." 12 | wrapped-function: 13 | name: "stumpless_new_chain" 14 | includes: "stumpless/target/chain.h" 15 | params: 16 | - name: "name" 17 | doc: "The name of this target." 18 | type: "const char *" 19 | return: 20 | type: "equivalent-struct-pointer" 21 | use-template: "pointer-return-error-check" 22 | destructor: 23 | doc: > 24 | Closes this chain and releases all memory and other resources held by 25 | it. Does not close the targets in the chain. 26 | wrapped-function: 27 | name: "stumpless_close_chain_only" 28 | includes: "stumpless/target/chain.h" 29 | params: 30 | - name: "equivalent-struct-pointer" 31 | functions: 32 | - use-template: "common-target-functions" 33 | -------------------------------------------------------------------------------- /include/private/config/have_pthread.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_PRIVATE_CONFIG_HAVE_PTHREAD_H 20 | # define __STUMPLESS_PRIVATE_CONFIG_HAVE_PTHREAD_H 21 | 22 | # include 23 | 24 | void 25 | pthread_destroy_mutex( const pthread_mutex_t *mutex ); 26 | 27 | void 28 | pthread_init_mutex( pthread_mutex_t *mutex ); 29 | 30 | void 31 | pthread_lock_mutex( const pthread_mutex_t *mutex ); 32 | 33 | void 34 | pthread_unlock_mutex( const pthread_mutex_t *mutex ); 35 | 36 | #endif /* __STUMPLESS_PRIVATE_CONFIG_HAVE_PTHREAD_H */ 37 | -------------------------------------------------------------------------------- /tools/wrapture/priority.yml: -------------------------------------------------------------------------------- 1 | version: "0.5.0" 2 | classes: 3 | - name: "Priority" 4 | doc: > 5 | PRIVAL as priority value (as defined in RFC 5424) represents both the 6 | Facility and Severity. 7 | The Priority value consists of one, two, or three decimal integers. 8 | namespace: "stumpless" 9 | functions: 10 | - name: "GetOption" 11 | doc: > 12 | Gets the given option for this target. 13 | 14 | While the returned value is the option if it is set, callers can also 15 | simply use the truth value of the return to see if the provided option 16 | is set. 17 | params: 18 | - name: "option" 19 | doc: "The option to check this target for." 20 | type: "int" 21 | return: 22 | doc: > 23 | The option if it is set on the target. If the option is not set, 24 | then zero is returned. 25 | type: "int" 26 | wrapped-function: 27 | name: "stumpless_get_option" 28 | includes: "stumpless/target.h" 29 | params: 30 | - value: "equivalent-struct-pointer" 31 | - value: "option" 32 | return: 33 | type: "int" 34 | -------------------------------------------------------------------------------- /tools/check_headers/README.md: -------------------------------------------------------------------------------- 1 | # Check Headers Tool 2 | 3 | This tool provides a way to perform some basic checks against C/C++ source and 4 | header file include statements. Its primary use case is to make sure that the 5 | files have these two properties: 6 | 7 | * all necessary headers are included, without relying on header files to 8 | include other files themselves 9 | * there are no headers included that are not needed 10 | 11 | These properties are meant to keep compile times manageable while avoiding 12 | complicated header interdependencies. 13 | 14 | The tool uses manifest files to determine what headers are needed for various 15 | terms. For example, the `standard_library.yml` manifest file lists the terms 16 | that may be used from the C and C++ standard libraries, and what headers are 17 | needed for each of them. For example, the ubiquitous `NULL` is defined in 18 | either `stddef.h` or `cstddef`, and so this tool will check for that include in 19 | any source file that contains it. 20 | 21 | There are several subtle details and limitations of this tool, as it does not 22 | implement language parsing and is meant to be as simple as possible. To see a 23 | list of assumptions and quirks, look at the `check_headers.rb` script. 24 | -------------------------------------------------------------------------------- /test/function/leak/error.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2019-2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include "test/helper/memory_counter.hpp" 23 | 24 | NEW_MEMORY_COUNTER( free_all ) 25 | 26 | namespace { 27 | 28 | TEST( ErrorLeakTest, FreeAllDeallocatesStaticError ) { 29 | INIT_MEMORY_COUNTER( free_all ); 30 | 31 | // cause an error 32 | stumpless_new_param( NULL, NULL ); 33 | ASSERT_TRUE( stumpless_has_error( ) ); 34 | 35 | stumpless_free_all( ); 36 | 37 | ASSERT_NO_LEAK( free_all ); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /include/private/target/function.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2021-2023 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_PRIVATE_TARGET_FUNCTION_H 20 | # define __STUMPLESS_PRIVATE_TARGET_FUNCTION_H 21 | 22 | # include 23 | # include 24 | # include 25 | 26 | struct function_target { 27 | stumpless_log_func_t log_function; 28 | }; 29 | 30 | int 31 | send_entry_to_function_target( const struct stumpless_target *target, 32 | const struct stumpless_entry *entry ); 33 | 34 | #endif /* __STUMPLESS_PRIVATE_TARGET_FUNCTION_H */ 35 | -------------------------------------------------------------------------------- /src/config/no_strncasecmp.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2025 Michael Hinz 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "private/config/no_strncasecmp.h" 22 | 23 | /* 24 | * Moved here from strhelper since we only need it if no library function exists. 25 | */ 26 | int 27 | strncasecmp_custom( const char *s1, const char *s2, size_t n ) { 28 | if (n != 0) { 29 | do { 30 | if (tolower(*s1) != tolower(*s2++)) 31 | return tolower(*--s2) - tolower(*s1); 32 | if (*s1++ == '\0') 33 | break; 34 | } while (--n != 0); 35 | if(*s2 != '\0') return tolower(*s2) - tolower(*s1); 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /include/private/config/wrapper/format_string.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2018-2022 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #ifndef __STUMPLESS_PRIVATE_CONFIG_FORMAT_STRING_H 19 | # define __STUMPLESS_PRIVATE_CONFIG_FORMAT_STRING_H 20 | 21 | # include "private/config.h" 22 | 23 | /* definition of config_format_string */ 24 | # ifdef HAVE_VSNPRINTF_S 25 | # include "private/config/have_vsnprintf_s.h" 26 | # define config_format_string vsnprintf_s_format_string 27 | # else 28 | # include "private/config/no_vsnprintf_s.h" 29 | # define config_format_string no_vsnprintf_s_format_string 30 | # endif 31 | 32 | #endif /* __STUMPLESS_PRIVATE_CONFIG_FORMAT_STRING_H */ 33 | -------------------------------------------------------------------------------- /test/function/cpp/target/wel.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | using namespace stumpless; 23 | 24 | namespace { 25 | TEST( CppSetEntryCategories, Basics ) { 26 | Entry basic_entry( Facility::USER, 27 | Severity::INFO, 28 | "cpp-wel-test", 29 | "simple-entry", 30 | "my message" ); 31 | 32 | // use dummy values as this won't actually be logged 33 | basic_entry.SetWelCategory( 12 ); 34 | basic_entry.SetWelEventId( 13 ); 35 | basic_entry.SetWelType( 14 ); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tools/cmake/config_files.cmake: -------------------------------------------------------------------------------- 1 | configure_file( 2 | "${PROJECT_SOURCE_DIR}/include/stumpless/config.h.in" 3 | "${PROJECT_BINARY_DIR}/include/stumpless/config.h" 4 | ) 5 | 6 | configure_file( 7 | "${PROJECT_SOURCE_DIR}/include/private/config.h.in" 8 | "${PROJECT_BINARY_DIR}/include/private/config.h" 9 | ) 10 | 11 | configure_file( 12 | "${PROJECT_SOURCE_DIR}/include/test/config.hpp.in" 13 | "${PROJECT_BINARY_DIR}/include/test/config.hpp" 14 | ) 15 | 16 | configure_file( 17 | "${PROJECT_SOURCE_DIR}/tools/portage/libstumpless.ebuild.in" 18 | "${PROJECT_BINARY_DIR}/tools/portage/libstumpless-${PROJECT_VERSION}.ebuild" 19 | @ONLY 20 | ) 21 | configure_file( 22 | "${PROJECT_SOURCE_DIR}/tools/portage/libstumpless.ebuild.in" 23 | "${PROJECT_BINARY_DIR}/tools/portage/libstumpless-9999.ebuild" 24 | @ONLY 25 | ) 26 | 27 | # generating level header files 28 | set(NAME_DOWNCASE alert crit debug emerg err info notice warning trace) 29 | set(NAME_SHORT a c d em er i n w t) 30 | 31 | foreach(LEVEL_NAME_DOWNCASE LEVEL_SHORTNAME IN ZIP_LISTS NAME_DOWNCASE NAME_SHORT) 32 | string(TOUPPER "${LEVEL_NAME_DOWNCASE}" LEVEL_NAME_UPCASE) 33 | configure_file( 34 | "${PROJECT_SOURCE_DIR}/include/stumpless/level/level.h.in" 35 | "${PROJECT_BINARY_DIR}/include/stumpless/level/${LEVEL_NAME_DOWNCASE}.h" 36 | ) 37 | endforeach() -------------------------------------------------------------------------------- /include/private/config/wrapper/strncasecmp.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2025 Michael Hinz 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** @file 20 | * A wrapper for comparing two strings ignoring case. 21 | */ 22 | 23 | #ifndef __STUMPLESS_PRIVATE_CONFIG_WRAPPER_STRNCASECMP_H 24 | #define __STUMPLESS_PRIVATE_CONFIG_WRAPPER_STRNCASECMP_H 25 | 26 | #include "private/config.h" 27 | 28 | /* definition of config_strncasecmp*/ 29 | #ifdef HAVE_STRNCASECMP 30 | # include 31 | # define config_strncasecmp strncasecmp 32 | #else 33 | # include "private/config/no_strncasecmp.h" 34 | # define config_strncasecmp strncasecmp_custom 35 | #endif 36 | 37 | #endif /* __STUMPLESS_PRIVATE_CONFIG_WRAPPER_STRNCASECMP_H */ 38 | -------------------------------------------------------------------------------- /test/function/level/all_enabled.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2020-2021 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include "test/helper/fixture.hpp" 21 | #include "test/helper/level_enabled.hpp" 22 | 23 | using::testing::HasSubstr; 24 | 25 | namespace { 26 | 27 | BUFFER_TARGET_FIXTURE_CLASS( LevelEnabledTest ); 28 | 29 | TEST_LEVEL_ENABLED( EMERG, em ); 30 | TEST_LEVEL_ENABLED( ALERT, a ); 31 | TEST_LEVEL_ENABLED( CRIT, c ); 32 | TEST_LEVEL_ENABLED( ERR, er ); 33 | TEST_LEVEL_ENABLED( WARNING, w ); 34 | TEST_LEVEL_ENABLED( NOTICE, n ); 35 | TEST_LEVEL_ENABLED( INFO, i ); 36 | TEST_LEVEL_ENABLED( DEBUG, d ); 37 | TEST_LEVEL_ENABLED( TRACE, t ); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /test/function/level/all_disabled.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2020-2021 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include "test/helper/fixture.hpp" 21 | #include "test/helper/level_disabled.hpp" 22 | 23 | using::testing::HasSubstr; 24 | 25 | namespace { 26 | 27 | BUFFER_TARGET_FIXTURE_CLASS( LevelEnabledTest ); 28 | 29 | TEST_LEVEL_DISABLED( EMERG, em ); 30 | TEST_LEVEL_DISABLED( ALERT, a ); 31 | TEST_LEVEL_DISABLED( CRIT, c ); 32 | TEST_LEVEL_DISABLED( ERR, er ); 33 | TEST_LEVEL_DISABLED( WARNING, w ); 34 | TEST_LEVEL_DISABLED( NOTICE, n ); 35 | TEST_LEVEL_DISABLED( INFO, i ); 36 | TEST_LEVEL_DISABLED( DEBUG, d ); 37 | TEST_LEVEL_DISABLED( TRACE, t ); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /scripts/Repair-HeaderDllExports.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Adds missing DLL Exports to C++ header files. 4 | .DESCRIPTION 5 | Fixes Wrapture-generated header files so that they have the correct export 6 | decorations added to declarations. 7 | .EXAMPLE 8 | Example of how to use this cmdlet 9 | .EXAMPLE 10 | Another example of how to use this cmdlet 11 | #> 12 | 13 | [CmdletBinding()] 14 | 15 | Param ( 16 | # The path to the directory containing the header files to repair. 17 | [Parameter(Mandatory=$true,Position=0)] 18 | [string]$InputFileDir, 19 | 20 | # The path to the directory where the modified header files should go. 21 | [Parameter(Mandatory=$true,Position=1)] 22 | [string]$OutputFileDir 23 | ) 24 | 25 | Get-ChildItem -Path $HeaderFileDirectory | Where-Object { $_.Extension -eq '.hpp' } | ForEach-Object { 26 | $newContents = @( 27 | "#ifdef DLL_EXPORTS", 28 | "# define DLL_API __declspec(dllexport)", 29 | "#else", 30 | "# define DLL_API __declspec(dllimport)", 31 | "#endif", 32 | "" 33 | ) 34 | 35 | $newContents += Get-Content $_.FullName | ForEach-Object { $_ -replace "class $className", "class DLL_API $className" } 36 | 37 | $newFile = Join-Path -Path $OutputFileDir -ChildPath $_.Name 38 | Set-Content $newFile -Value $newContents 39 | } 40 | -------------------------------------------------------------------------------- /src/config/have_pthread.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "private/config/have_pthread.h" 22 | 23 | void 24 | pthread_destroy_mutex( const pthread_mutex_t *mutex ) { 25 | pthread_mutex_destroy( ( pthread_mutex_t * ) mutex ); 26 | } 27 | 28 | void 29 | pthread_init_mutex( pthread_mutex_t *mutex ) { 30 | pthread_mutex_init( mutex, NULL ); 31 | } 32 | 33 | void 34 | pthread_lock_mutex( const pthread_mutex_t *mutex ) { 35 | pthread_mutex_lock( ( pthread_mutex_t * ) mutex ); 36 | } 37 | 38 | void 39 | pthread_unlock_mutex( const pthread_mutex_t *mutex ) { 40 | pthread_mutex_unlock( ( pthread_mutex_t * ) mutex ); 41 | } 42 | -------------------------------------------------------------------------------- /include/private/config/wrapper/getpid.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2022 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | 20 | #ifndef __STUMPLESS_PRIVATE_CONFIG_WRAPPER_GETPID_H 21 | # define __STUMPLESS_PRIVATE_CONFIG_WRAPPER_GETPID_H 22 | 23 | # include "private/config.h" 24 | 25 | /* definition of config_getpid */ 26 | # ifdef HAVE_UNISTD_H 27 | # include "private/config/have_unistd.h" 28 | # define config_getpid unistd_getpid 29 | # elif HAVE_WINDOWS_H 30 | # include "private/config/have_windows.h" 31 | # define config_getpid windows_getpid 32 | # else 33 | # include "private/config/fallback.h" 34 | # define config_getpid fallback_getpid 35 | # endif 36 | 37 | #endif /* __STUMPLESS_PRIVATE_CONFIG_WRAPPER_GETPID_H */ 38 | -------------------------------------------------------------------------------- /include/private/windows_wrapper.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** @file 20 | * Serves as a single inclusion point for windows.h, winsock2.h, and 21 | * ws2tcpip.h. Windows headers have ordering dependencies that can cause 22 | * compilation errors, and as such need to be done carefully. 23 | */ 24 | 25 | #ifndef __STUMPLESS_PRIVATE_WINDOWS_WRAPPER_H 26 | # define __STUMPLESS_PRIVATE_WINDOWS_WRAPPER_H 27 | 28 | # include "private/config.h" 29 | 30 | # ifdef HAVE_WINSOCK2_H 31 | # include 32 | # include 33 | # endif 34 | 35 | # ifdef HAVE_WINDOWS_H 36 | # include 37 | # endif 38 | 39 | #endif /* __STUMPLESS_PRIVATE_WINDOWS_WRAPPER_H */ 40 | -------------------------------------------------------------------------------- /test/function/config/socket_supported.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2019-2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "test/helper/assert.hpp" 22 | 23 | namespace { 24 | 25 | TEST( GetDefaultTarget, SocketSupported ) { 26 | struct stumpless_target *target; 27 | 28 | target = stumpless_get_default_target( ); 29 | EXPECT_NO_ERROR; 30 | EXPECT_NOT_NULL( target ); 31 | 32 | #ifndef STUMPLESS_WINDOWS_EVENT_LOG_TARGETS_SUPPORTED 33 | if( target ) { 34 | EXPECT_EQ( target->type, STUMPLESS_SOCKET_TARGET ); 35 | EXPECT_STREQ( target->name, STUMPLESS_DEFAULT_SOCKET ); 36 | } 37 | #endif 38 | 39 | stumpless_free_all( ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/config/have_unistd_gethostname.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include "private/config/have_unistd_gethostname.h" 23 | #include "private/config/wrapper/locale.h" 24 | #include "private/error.h" 25 | 26 | int 27 | unistd_gethostname( char *buffer, size_t namelen ) { 28 | int result; 29 | 30 | result = gethostname( buffer, namelen ); 31 | buffer[namelen - 1] = '\0'; 32 | 33 | if( result == -1 ) { 34 | raise_gethostname_failure( L10N_GETHOSTNAME_FAILED_ERROR_MESSAGE, 35 | errno, 36 | L10N_ERRNO_ERROR_CODE_TYPE ); 37 | } 38 | 39 | return result; 40 | } 41 | -------------------------------------------------------------------------------- /include/stumpless/generator.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2020-2024 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** @file 20 | * Generic functionality to be used with STUMPLESS_FOREACH macros to allow for 21 | * more generic definition of enumerations and to string functions. 22 | */ 23 | 24 | #ifndef __STUMPLESS_GENERATOR_H 25 | #define __STUMPLESS_GENERATOR_H 26 | 27 | /** 28 | * Returns a definition of a symbol with the given name and value fit for use in 29 | * an enum definition. Compatible with \c STUMPLESS_FOREACH_ macro functions 30 | * such as STUMPLESS_FOREACH_FACILITY(). 31 | * 32 | * @since release v2.0.0. 33 | */ 34 | #define STUMPLESS_GENERATE_ENUM( NAME, VALUE ) NAME = ( VALUE ), 35 | 36 | #endif /* __STUMPLESS_GENERATOR_H */ 37 | -------------------------------------------------------------------------------- /test/function/cpp/target/network.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | using namespace stumpless; 24 | 25 | namespace { 26 | TEST( CppDefaultTransportPortTest, EqualToStumpless ) { 27 | EXPECT_STREQ(NetworkTarget::DEFAULT_TRANSPORT_PORT, 28 | STUMPLESS_DEFAULT_TRANSPORT_PORT); 29 | } 30 | 31 | TEST( CppNewPausedTargetTest, Udp4Target ) { 32 | NetworkTarget trgt = NetworkTarget::NewPausedTarget("test-name", 33 | NetworkProtocol::IPV4, 34 | TransportProtocol::UDP); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /include/private/config/wrapper/gethostbyname.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2023 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** @file 20 | * A wrapper for either gethostbyname or gethostbyname2. 21 | */ 22 | 23 | #ifndef __STUMPLESS_PRIVATE_CONFIG_WRAPPER_GETHOSTBYNAME_H 24 | # define __STUMPLESS_PRIVATE_CONFIG_WRAPPER_GETHOSTBYNAME_H 25 | 26 | # include "private/config.h" 27 | 28 | /* definition of config_gethostbyname */ 29 | # ifdef HAVE_GETHOSTBYNAME2 30 | # include 31 | # define config_gethostbyname gethostbyname2 32 | # elif HAVE_GETHOSTBYNAME 33 | # include 34 | # define config_gethostbyname( NAME, DOMAIN ) gethostbyname( ( NAME ) ) 35 | # endif 36 | 37 | #endif /* __STUMPLESS_PRIVATE_CONFIG_WRAPPER_GETHOSTBYNAME_H */ 38 | -------------------------------------------------------------------------------- /test/function/level/enable_upto_debug.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2020-2021 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include "test/helper/fixture.hpp" 21 | #include "test/helper/level_disabled.hpp" 22 | #include "test/helper/level_enabled.hpp" 23 | 24 | using::testing::HasSubstr; 25 | 26 | namespace { 27 | 28 | BUFFER_TARGET_FIXTURE_CLASS( LevelEnabledTest ); 29 | 30 | TEST_LEVEL_ENABLED( EMERG, em ); 31 | TEST_LEVEL_ENABLED( ALERT, a ); 32 | TEST_LEVEL_ENABLED( CRIT, c ); 33 | TEST_LEVEL_ENABLED( ERR, er ); 34 | TEST_LEVEL_ENABLED( WARNING, w ); 35 | TEST_LEVEL_ENABLED( NOTICE, n ); 36 | TEST_LEVEL_ENABLED( INFO, i ); 37 | TEST_LEVEL_ENABLED( DEBUG, d ); 38 | 39 | TEST_LEVEL_DISABLED( TRACE, t ); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /test/function/level/enable_upto_info.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2020-2021 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include "test/helper/fixture.hpp" 21 | #include "test/helper/level_disabled.hpp" 22 | #include "test/helper/level_enabled.hpp" 23 | 24 | using::testing::HasSubstr; 25 | 26 | namespace { 27 | 28 | BUFFER_TARGET_FIXTURE_CLASS( LevelEnabledTest ); 29 | 30 | TEST_LEVEL_ENABLED( EMERG, em ); 31 | TEST_LEVEL_ENABLED( ALERT, a ); 32 | TEST_LEVEL_ENABLED( CRIT, c ); 33 | TEST_LEVEL_ENABLED( ERR, er ); 34 | TEST_LEVEL_ENABLED( WARNING, w ); 35 | TEST_LEVEL_ENABLED( NOTICE, n ); 36 | TEST_LEVEL_ENABLED( INFO, i ); 37 | 38 | TEST_LEVEL_DISABLED( DEBUG, d ); 39 | TEST_LEVEL_DISABLED( TRACE, t ); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /tools/cmake/performance_tests.cmake: -------------------------------------------------------------------------------- 1 | 2 | add_performance_test(element 3 | SOURCES "${PROJECT_SOURCE_DIR}/test/performance/element.cpp" 4 | ) 5 | 6 | add_performance_test(prival 7 | SOURCES "${PROJECT_SOURCE_DIR}/test/performance/prival.cpp" 8 | ) 9 | 10 | add_performance_test(entry 11 | SOURCES 12 | "${PROJECT_SOURCE_DIR}/test/performance/entry.cpp" 13 | $ 14 | ) 15 | 16 | add_performance_test(function 17 | SOURCES 18 | "${PROJECT_SOURCE_DIR}/test/performance/target/function.cpp" 19 | $ 20 | ) 21 | 22 | add_performance_test(buffer 23 | SOURCES 24 | "${PROJECT_SOURCE_DIR}/test/performance/target/buffer.cpp" 25 | $ 26 | ) 27 | 28 | add_performance_test(log 29 | SOURCES "${PROJECT_SOURCE_DIR}/test/performance/log.cpp" 30 | ) 31 | 32 | add_performance_test(param 33 | SOURCES 34 | "${PROJECT_SOURCE_DIR}/test/performance/param.cpp" 35 | $ 36 | ) 37 | 38 | add_performance_test(target 39 | SOURCES 40 | "${PROJECT_SOURCE_DIR}/test/performance/target.cpp" 41 | $ 42 | ) 43 | 44 | add_performance_test(version 45 | SOURCES "${PROJECT_SOURCE_DIR}/test/performance/version.cpp" 46 | ) 47 | 48 | add_custom_target(bench 49 | DEPENDS ${STUMPLESS_PERFORMANCE_TEST_RUNNERS} 50 | ) 51 | -------------------------------------------------------------------------------- /test/function/level/enable_upto_alert.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2020-2021 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include "test/helper/fixture.hpp" 21 | #include "test/helper/level_disabled.hpp" 22 | #include "test/helper/level_enabled.hpp" 23 | 24 | using::testing::HasSubstr; 25 | 26 | namespace { 27 | 28 | BUFFER_TARGET_FIXTURE_CLASS( LevelEnabledTest ); 29 | 30 | TEST_LEVEL_ENABLED( EMERG, em ); 31 | TEST_LEVEL_ENABLED( ALERT, a ); 32 | 33 | TEST_LEVEL_DISABLED( CRIT, c ); 34 | TEST_LEVEL_DISABLED( ERR, er ); 35 | TEST_LEVEL_DISABLED( WARNING, w ); 36 | TEST_LEVEL_DISABLED( NOTICE, n ); 37 | TEST_LEVEL_DISABLED( INFO, i ); 38 | TEST_LEVEL_DISABLED( DEBUG, d ); 39 | TEST_LEVEL_DISABLED( TRACE, t ); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /test/function/level/enable_upto_err.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2020-2021 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include "test/helper/fixture.hpp" 21 | #include "test/helper/level_disabled.hpp" 22 | #include "test/helper/level_enabled.hpp" 23 | 24 | using::testing::HasSubstr; 25 | 26 | namespace { 27 | 28 | BUFFER_TARGET_FIXTURE_CLASS( LevelEnabledTest ); 29 | 30 | TEST_LEVEL_ENABLED( EMERG, em ); 31 | TEST_LEVEL_ENABLED( ALERT, a ); 32 | TEST_LEVEL_ENABLED( CRIT, c ); 33 | TEST_LEVEL_ENABLED( ERR, er ); 34 | 35 | TEST_LEVEL_DISABLED( WARNING, w ); 36 | TEST_LEVEL_DISABLED( NOTICE, n ); 37 | TEST_LEVEL_DISABLED( INFO, i ); 38 | TEST_LEVEL_DISABLED( DEBUG, d ); 39 | TEST_LEVEL_DISABLED( TRACE, t ); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /test/function/level/enable_upto_notice.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2020-2021 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include "test/helper/fixture.hpp" 21 | #include "test/helper/level_disabled.hpp" 22 | #include "test/helper/level_enabled.hpp" 23 | 24 | using::testing::HasSubstr; 25 | 26 | namespace { 27 | 28 | BUFFER_TARGET_FIXTURE_CLASS( LevelEnabledTest ); 29 | 30 | TEST_LEVEL_ENABLED( EMERG, em ); 31 | TEST_LEVEL_ENABLED( ALERT, a ); 32 | TEST_LEVEL_ENABLED( CRIT, c ); 33 | TEST_LEVEL_ENABLED( ERR, er ); 34 | TEST_LEVEL_ENABLED( WARNING, w ); 35 | TEST_LEVEL_ENABLED( NOTICE, n ); 36 | 37 | TEST_LEVEL_DISABLED( INFO, i ); 38 | TEST_LEVEL_DISABLED( DEBUG, d ); 39 | TEST_LEVEL_DISABLED( TRACE, t ); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /test/function/level/enable_upto_warning.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2020-2021 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include "test/helper/fixture.hpp" 21 | #include "test/helper/level_disabled.hpp" 22 | #include "test/helper/level_enabled.hpp" 23 | 24 | using::testing::HasSubstr; 25 | 26 | namespace { 27 | 28 | BUFFER_TARGET_FIXTURE_CLASS( LevelEnabledTest ); 29 | 30 | TEST_LEVEL_ENABLED( EMERG, em ); 31 | TEST_LEVEL_ENABLED( ALERT, a ); 32 | TEST_LEVEL_ENABLED( CRIT, c ); 33 | TEST_LEVEL_ENABLED( ERR, er ); 34 | TEST_LEVEL_ENABLED( WARNING, w ); 35 | 36 | TEST_LEVEL_DISABLED( NOTICE, n ); 37 | TEST_LEVEL_DISABLED( INFO, i ); 38 | TEST_LEVEL_DISABLED( DEBUG, d ); 39 | TEST_LEVEL_DISABLED( TRACE, t ); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /test/function/level/enable_upto_crit.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2020-2021 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include "test/helper/fixture.hpp" 21 | #include "test/helper/level_disabled.hpp" 22 | #include "test/helper/level_enabled.hpp" 23 | 24 | 25 | using::testing::HasSubstr; 26 | 27 | namespace { 28 | 29 | BUFFER_TARGET_FIXTURE_CLASS( LevelEnabledTest ); 30 | 31 | TEST_LEVEL_ENABLED( EMERG, em ); 32 | TEST_LEVEL_ENABLED( ALERT, a ); 33 | TEST_LEVEL_ENABLED( CRIT, c ); 34 | 35 | TEST_LEVEL_DISABLED( ERR, er ); 36 | TEST_LEVEL_DISABLED( WARNING, w ); 37 | TEST_LEVEL_DISABLED( NOTICE, n ); 38 | TEST_LEVEL_DISABLED( INFO, i ); 39 | TEST_LEVEL_DISABLED( DEBUG, d ); 40 | TEST_LEVEL_DISABLED( TRACE, t ); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /test/function/level/enable_upto_emerg.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2020-2021 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include "test/helper/fixture.hpp" 21 | #include "test/helper/level_disabled.hpp" 22 | #include "test/helper/level_enabled.hpp" 23 | 24 | using::testing::HasSubstr; 25 | 26 | namespace { 27 | 28 | BUFFER_TARGET_FIXTURE_CLASS( LevelEnabledTest ); 29 | 30 | TEST_LEVEL_ENABLED( EMERG, em ); 31 | 32 | TEST_LEVEL_DISABLED( ALERT, a ); 33 | TEST_LEVEL_DISABLED( CRIT, c ); 34 | TEST_LEVEL_DISABLED( ERR, er ); 35 | TEST_LEVEL_DISABLED( WARNING, w ); 36 | TEST_LEVEL_DISABLED( NOTICE, n ); 37 | TEST_LEVEL_DISABLED( INFO, i ); 38 | TEST_LEVEL_DISABLED( DEBUG, d ); 39 | TEST_LEVEL_DISABLED( TRACE, t ); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /docs/examples/socket/README.md: -------------------------------------------------------------------------------- 1 | # Socket Targets 2 | 3 | Socket targets can send logs to a process that is listening on a Unix domain 4 | socket. It is up to the remote end to do something with the log once it has been 5 | received. The most common use case for this is to send logs to /dev/log on which 6 | the system logging daemon is listening. 7 | 8 | Opening a target is straightforward, with the first argument being the name of 9 | the target as well as the socket to send logs to. You can ignore the second 10 | argument in most cases. 11 | 12 | ```c 13 | target = stumpless_open_socket_target( "/dev/log", NULL ); 14 | ``` 15 | 16 | This will create a local socket with a randomized name that sends logs to the 17 | specified socket. If you need to be more specific and choose the name of the 18 | local socket that is created, then you can use the second argument to the open 19 | function to do this. 20 | 21 | ```c 22 | target = stumpless_open_socket_target( "/dev/log", "my-local-socket" ); 23 | ``` 24 | 25 | Once the target is created, logs are sent to it as usual: 26 | 27 | ```c 28 | stumpless_add_entry( target, entry ); 29 | ``` 30 | 31 | And of course, closing is just as typical. The local socket will be cleaned up 32 | when the target is closed. 33 | 34 | ```c 35 | stumpless_close_socket_target( target ); 36 | ``` 37 | 38 | And, even less typing at the cost of performance: 39 | 40 | ```c 41 | stumpless_close_target( target ); 42 | ``` 43 | -------------------------------------------------------------------------------- /include/private/config/wrapper/chain.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2024 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_PRIVATE_CONFIG_WRAPPER_CHAIN_H 20 | #define __STUMPLESS_PRIVATE_CONFIG_WRAPPER_CHAIN_H 21 | 22 | #include 23 | 24 | #ifdef STUMPLESS_CHAIN_TARGETS_SUPPORTED 25 | # include 26 | # include "private/target/chain.h" 27 | # define config_close_chain_and_contents stumpless_close_chain_and_contents 28 | # define config_send_entry_to_chain_target send_entry_to_chain_target 29 | #else 30 | # include "private/target.h" 31 | # define config_close_chain_and_contents close_unsupported_target 32 | # define config_send_entry_to_chain_target send_entry_to_unsupported_target 33 | #endif 34 | 35 | #endif /* __STUMPLESS_PRIVATE_CONFIG_WRAPPER_CHAIN_H */ 36 | -------------------------------------------------------------------------------- /test/function/startup/error_memory_failure.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2019-2024 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include "test/helper/assert.hpp" 24 | #include "test/helper/memory_allocation.hpp" 25 | 26 | namespace { 27 | 28 | TEST( ErrorMemoryAllocationFailureTest, Initialization ) { 29 | void *(*result)(size_t); 30 | const struct stumpless_param *param; 31 | 32 | result = stumpless_set_malloc( MALLOC_FAIL ); 33 | ASSERT_NOT_NULL( result ); 34 | 35 | // this will create an immediate failure 36 | param = stumpless_new_param( NULL, NULL ); 37 | EXPECT_NULL( param ); 38 | EXPECT_ERROR_ID_EQ( STUMPLESS_ARGUMENT_EMPTY ); 39 | 40 | stumpless_set_malloc( malloc ); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /tools/cmake/thread_safety_tests.cmake: -------------------------------------------------------------------------------- 1 | add_thread_safety_test(buffer 2 | SOURCES 3 | "${PROJECT_SOURCE_DIR}/test/thread_safety/target/buffer.cpp" 4 | $ 5 | $ 6 | ) 7 | 8 | add_thread_safety_test(element 9 | SOURCES "${PROJECT_SOURCE_DIR}/test/thread_safety/element.cpp" 10 | ) 11 | 12 | add_thread_safety_test(entry 13 | SOURCES 14 | "${PROJECT_SOURCE_DIR}/test/thread_safety/entry.cpp" 15 | $ 16 | ) 17 | 18 | add_thread_safety_test(file 19 | SOURCES 20 | "${PROJECT_SOURCE_DIR}/test/thread_safety/target/file.cpp" 21 | $ 22 | $ 23 | ) 24 | 25 | add_thread_safety_test(function 26 | SOURCES 27 | "${PROJECT_SOURCE_DIR}/test/thread_safety/target/function.cpp" 28 | $ 29 | ) 30 | 31 | add_thread_safety_test(param 32 | SOURCES "${PROJECT_SOURCE_DIR}/test/thread_safety/param.cpp" 33 | ) 34 | 35 | add_thread_safety_test(stream 36 | SOURCES 37 | "${PROJECT_SOURCE_DIR}/test/thread_safety/target/stream.cpp" 38 | $ 39 | $ 40 | ) 41 | 42 | add_thread_safety_test(target 43 | SOURCES "${PROJECT_SOURCE_DIR}/test/thread_safety/target.cpp" 44 | ) 45 | 46 | add_custom_target(check-thread-safety 47 | DEPENDS ${STUMPLESS_THREAD_SAFETY_TEST_RUNNERS} 48 | ) 49 | -------------------------------------------------------------------------------- /test/function/cpp/target/stream.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | using namespace stumpless; 24 | 25 | namespace { 26 | 27 | class CppStreamTargetTest : public::testing::Test { 28 | protected: 29 | const char *filename = "cpptestfile.log"; 30 | FILE *stream; 31 | 32 | virtual void 33 | SetUp( void ) { 34 | stream = fopen( filename, "w+" ); 35 | } 36 | 37 | virtual void 38 | TearDown( void ) { 39 | fclose( stream ); 40 | remove( filename ); 41 | } 42 | }; 43 | 44 | TEST_F( CppStreamTargetTest, AddMessage ) { 45 | StreamTarget target( "test-stream", stream ); 46 | 47 | target.Log( "this is a basic test of the stream target" ); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /include/private/config/thread_safety_unsupported.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2020-2022 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_PRIVATE_CONFIG_THREAD_SAFETY_UNSUPPORTED_H 20 | # define __STUMPLESS_PRIVATE_CONFIG_THREAD_SAFETY_UNSUPPORTED_H 21 | 22 | # include 23 | # include "private/config/wrapper/thread_safety.h" 24 | 25 | bool 26 | no_thread_safety_compare_exchange_bool( config_atomic_bool_t *b, 27 | bool expected, 28 | bool replacement ); 29 | 30 | bool 31 | no_thread_safety_compare_exchange_ptr( config_atomic_ptr_t *p, 32 | const void *expected, 33 | void *replacement ); 34 | 35 | #endif /* __STUMPLESS_PRIVATE_CONFIG_THREAD_SAFETY_UNSUPPORTED_H */ 36 | -------------------------------------------------------------------------------- /test/function/README.md: -------------------------------------------------------------------------------- 1 | # Functionality Testing 2 | Functionality testing of the library consists of several tests on the 3 | exposed interfaces. These tests use the Google Test framework to execute, which 4 | must be available in order for the tests to build. 5 | 6 | 7 | ## `config` 8 | Test suites that are specific to particular configuration options. 9 | 10 | ## `leak` 11 | Test suites for memory leaks. 12 | 13 | 14 | ## `level` 15 | Test suites to ensure that severity level filters function correctly. 16 | 17 | 18 | ## `python` 19 | Test suites for the python extension of the library. 20 | 21 | 22 | ## `target` 23 | Test suites for specific target types. 24 | 25 | 26 | ## `element.cpp` 27 | Tests functions that deal with elements. 28 | 29 | 30 | ## `entry.cpp` 31 | Tests functions that deal with entries. 32 | 33 | 34 | ## `error.cpp` 35 | Tests error handling and querying functions. 36 | 37 | 38 | ## `filter.cpp` 39 | Tests for the filters that are included with the library. 40 | 41 | 42 | ## `memory.cpp` 43 | Tests for the memory handling routines of the library. 44 | 45 | 46 | ## `param.cpp` 47 | Tests functions that deal with params. 48 | 49 | 50 | ## `severity.cpp` 51 | Tests for functions that deal with severities. 52 | 53 | 54 | ## `target.cpp` 55 | Tests for general target functionality. 56 | 57 | 58 | ## `version.cpp` 59 | Tests for versioning of the library. 60 | 61 | 62 | ## `priority.cpp` 63 | Tests for functions that deal with priority values (PRIVAL). 64 | -------------------------------------------------------------------------------- /include/private/config/wrapper/int_connect.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2023 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** @file 20 | * A wrapper for connecting to a host with specific connection characteristics. 21 | * The functions return int connection handles. 22 | */ 23 | 24 | #ifndef __STUMPLESS_PRIVATE_CONFIG_WRAPPER_INT_CONNECT_H 25 | # define __STUMPLESS_PRIVATE_CONFIG_WRAPPER_INT_CONNECT_H 26 | 27 | # include "private/config.h" 28 | 29 | /* definition of config_int_connect */ 30 | # ifdef HAVE_GETADDRINFO 31 | # include "private/config/have_getaddrinfo.h" 32 | # define config_int_connect getaddrinfo_int_connect 33 | # elif SUPPORT_GETHOSTBYNAME 34 | # include "private/config/gethostbyname_supported.h" 35 | # define config_int_connect gethostbyname_int_connect 36 | # endif 37 | 38 | #endif /* __STUMPLESS_PRIVATE_CONFIG_WRAPPER_INT_CONNECT_H */ 39 | -------------------------------------------------------------------------------- /include/private/config/wrapper/wstring.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2022 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_PRIVATE_CONFIG_WRAPPER_WSTRING_H 20 | # define __STUMPLESS_PRIVATE_CONFIG_WRAPPER_WSTRING_H 21 | 22 | # include "private/config.h" 23 | 24 | /* definition of config_copy_wstring_to_cstring */ 25 | # ifdef HAVE_WINDOWS_H 26 | # include "private/config/have_windows.h" 27 | # define config_copy_wstring_to_cstring windows_copy_wstring_to_cstring 28 | # elif !defined HAVE_WCSRTOMBS_S 29 | # include "private/config/no_wcsrtombs_s.h" 30 | # define config_copy_wstring_to_cstring no_wcsrtombs_s_copy_wstring_to_cstring 31 | # else 32 | # include "private/config/fallback.h" 33 | # define config_copy_wstring_to_cstring fallback_copy_wstring_to_cstring 34 | # endif 35 | 36 | #endif /* __STUMPLESS_PRIVATE_CONFIG_WRAPPER_WSTRING_H */ 37 | -------------------------------------------------------------------------------- /docs/examples/README.md: -------------------------------------------------------------------------------- 1 | # Stumpless Examples 2 | 3 | These examples demonstrate how to use features of the stumpless library. If you 4 | aren't sure where to get started, this is the right place! If you're still 5 | not quite sure, take a look at the [basic](basic/README.md) example as a good 6 | starting place. 7 | 8 | If you want to actually compile and run the examples, you'll need to have the 9 | stumpless library available. If you don't want to install it on your system, you 10 | can also use the `examples` build target. Note that some examples are built by 11 | this target, but aren't actually executed. This is because these examples work 12 | best after you modify them to suit your intentions. For example, the TCP example 13 | is configured to send logs to `example.com`, which will fail as this is 14 | obviously not a log server. You can either use the `examples` build target and 15 | then run these afterwards, or you could use the `example-` build 16 | target to just build one at a time. For example, the `example-tcp` target will 17 | build the TCP example, after which you can execute it manually. 18 | 19 | If you want to see even more sample code after looking at the examples, you can 20 | check out the test suites available in the `test` folder of the repository. 21 | While the code in these suites is written with the primary goal of testing and 22 | demonstrating (sometimes nuanced) functionality and performance, it can also be 23 | a good place to find specific usage patterns and expected results. 24 | -------------------------------------------------------------------------------- /tools/wrapture/severity.yml: -------------------------------------------------------------------------------- 1 | version: "0.4.0" 2 | enums: 3 | - name: "Severity" 4 | doc: > 5 | Severities (as defined in RFC 5424) describe the level of importance of a 6 | given log entry. They range from extremely important to ignorable. 7 | 8 | The underlying values of this enumeration will match those provided in 9 | syslog.h if it was available during build. Check for the definition of 10 | STUMPLESS_SYSLOG_H_COMPATIBLE to see if you can rely on this behavior. 11 | namespace: "stumpless" 12 | includes: "stumpless/severity.h" 13 | elements: 14 | - name: "EMERGENCY" 15 | doc: "System is unusable." 16 | value: "STUMPLESS_SEVERITY_EMERG" 17 | - name: "ALERT" 18 | doc: "Action must be taken immediately." 19 | value: "STUMPLESS_SEVERITY_ALERT" 20 | - name: "CRITICAL" 21 | doc: "Critical conditions." 22 | value: "STUMPLESS_SEVERITY_CRIT" 23 | - name: "ERR" 24 | doc: "Error conditions." 25 | value: "STUMPLESS_SEVERITY_ERR" 26 | - name: "WARNING" 27 | doc: "Warning conditions." 28 | value: "STUMPLESS_SEVERITY_WARNING" 29 | - name: "NOTICE" 30 | doc: "Normal but significant conditions." 31 | value: "STUMPLESS_SEVERITY_NOTICE" 32 | - name: "INFO" 33 | doc: "Informational messages." 34 | value: "STUMPLESS_SEVERITY_INFO" 35 | - name: "DEBUG" 36 | doc: "Debug-level messages." 37 | value: "STUMPLESS_SEVERITY_DEBUG" 38 | -------------------------------------------------------------------------------- /include/private/config/wrapper/sqlite3.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2023 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_PRIVATE_CONFIG_WRAPPER_SQLITE3_H 20 | #define __STUMPLESS_PRIVATE_CONFIG_WRAPPER_SQLITE3_H 21 | 22 | #include 23 | 24 | #ifdef STUMPLESS_SQLITE3_TARGETS_SUPPORTED 25 | # include 26 | # include "private/target/sqlite3.h" 27 | # define config_close_sqlite3_target_and_db \ 28 | stumpless_close_sqlite3_target_and_db 29 | # define config_send_entry_to_sqlite3_target send_entry_to_sqlite3_target 30 | #else 31 | # include "private/target.h" 32 | # define config_close_sqlite3_target_and_db close_unsupported_target 33 | # define config_send_entry_to_sqlite3_target send_entry_to_unsupported_target 34 | #endif 35 | 36 | #endif /* __STUMPLESS_PRIVATE_CONFIG_WRAPPER_SQLITE3_H */ 37 | -------------------------------------------------------------------------------- /src/config/have_vsnprintf_s.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2019 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include "private/config/have_vsnprintf_s.h" 23 | #include "private/memory.h" 24 | 25 | char * 26 | vsnprintf_s_format_string( const char *format, va_list subs, size_t *length ) { 27 | char *buffer = NULL; 28 | char *new_buffer; 29 | size_t buffer_size = 128; 30 | int result = -1; 31 | 32 | do { 33 | new_buffer = realloc_mem( buffer, buffer_size ); 34 | if( !new_buffer ) { 35 | goto fail; 36 | } 37 | buffer = new_buffer; 38 | 39 | result = vsnprintf_s( buffer, buffer_size, _TRUNCATE, format, subs ); 40 | buffer_size = buffer_size << 1; 41 | } while( result < 1 ); 42 | 43 | *length = result; 44 | return buffer; 45 | 46 | fail: 47 | free_mem( buffer ); 48 | return NULL; 49 | } 50 | -------------------------------------------------------------------------------- /test/function/leak/wel_supported.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2022 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "test/helper/assert.hpp" 22 | #include "test/helper/fixture.hpp" 23 | #include "test/helper/memory_counter.hpp" 24 | 25 | #define TEST_BUFFER_LENGTH 2048 26 | 27 | NEW_MEMORY_COUNTER( wel_entry_leak ) 28 | 29 | namespace { 30 | 31 | TEST( WelEntryLeakTest, AfterInsertionStringSet ) { 32 | struct stumpless_entry *entry; 33 | 34 | INIT_MEMORY_COUNTER( wel_entry_leak ); 35 | 36 | entry = create_entry( ); 37 | EXPECT_NO_ERROR; 38 | ASSERT_NOT_NULL( entry ); 39 | 40 | stumpless_set_wel_insertion_string( entry, 0, "testing" ); 41 | EXPECT_NO_ERROR; 42 | 43 | stumpless_destroy_entry_and_contents( entry ); 44 | stumpless_free_all( ); 45 | 46 | ASSERT_NO_LEAK( wel_entry_leak ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /include/private/config/wrapper/gethostname.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2022 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | 20 | #ifndef __STUMPLESS_PRIVATE_CONFIG_WRAPPER_GETHOSTNAME_H 21 | # define __STUMPLESS_PRIVATE_CONFIG_WRAPPER_GETHOSTNAME_H 22 | 23 | #include "private/config.h" 24 | 25 | /* definition of config_gethostname */ 26 | # ifdef HAVE_UNISTD_GETHOSTNAME 27 | # include "private/config/have_unistd_gethostname.h" 28 | # define config_gethostname(buffer, namelen) unistd_gethostname((buffer), (namelen)) 29 | # elif HAVE_WINDOWS_H 30 | # include "private/config/have_windows.h" 31 | # define config_gethostname(buffer, namelen) windows_gethostname((buffer), (namelen)) 32 | # else 33 | # include "private/config/fallback.h" 34 | # define config_gethostname(buffer, namelen) fallback_gethostname((buffer), (namelen)) 35 | # endif 36 | 37 | #endif /* __STUMPLESS_PRIVATE_CONFIG_WRAPPER_GETHOSTNAME_H */ 38 | -------------------------------------------------------------------------------- /src/config/thread_safety_unsupported.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2020-2022 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include "private/config/thread_safety_unsupported.h" 21 | #include "private/config/wrapper/thread_safety.h" 22 | 23 | bool 24 | no_thread_safety_compare_exchange_bool( config_atomic_bool_t *b, 25 | bool expected, 26 | bool replacement ) { 27 | if( *b == expected ) { 28 | *b = replacement; 29 | return true; 30 | } else { 31 | return false; 32 | } 33 | } 34 | 35 | bool 36 | no_thread_safety_compare_exchange_ptr( config_atomic_ptr_t *p, 37 | const void *expected, 38 | void *replacement ) { 39 | if( *p == expected ) { 40 | *p = replacement; 41 | return true; 42 | } else { 43 | return false; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/strhelper.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2018-2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "private/memory.h" 22 | #include "private/strhelper.h" 23 | 24 | char * 25 | copy_cstring( const char *str ) { 26 | char *new_string; 27 | size_t length; 28 | 29 | length = strlen( str ); 30 | new_string = alloc_mem( length + 1 ); 31 | if( !new_string ) { 32 | return NULL; 33 | } 34 | 35 | memcpy( new_string, str, length ); 36 | new_string[length] = '\0'; 37 | 38 | return new_string; 39 | } 40 | 41 | char * 42 | copy_cstring_with_length( const char *str, size_t *length ) { 43 | char *new_string; 44 | 45 | *length = strlen( str ); 46 | 47 | new_string = alloc_mem( *length + 1 ); 48 | if( !new_string ) { 49 | return NULL; 50 | } 51 | 52 | memcpy( new_string, str, *length ); 53 | new_string[*length] = '\0'; 54 | 55 | return new_string; 56 | } 57 | 58 | -------------------------------------------------------------------------------- /include/private/config/wrapper/get_now.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2022-2024 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** @file 20 | * A wrapper for getting a string with the current timestamp. 21 | */ 22 | 23 | #ifndef __STUMPLESS_PRIVATE_CONFIG_WRAPPER_GET_NOW_H 24 | #define __STUMPLESS_PRIVATE_CONFIG_WRAPPER_GET_NOW_H 25 | 26 | #include "private/config.h" 27 | 28 | /* definition of config_get_now */ 29 | #ifdef HAVE_GMTIME_R 30 | # include "private/config/have_gmtime_r.h" 31 | # define config_get_now gmtime_r_get_now 32 | #elif SUPPORT_WINDOWS_GET_NOW 33 | # include "private/config/windows_get_now_supported.h" 34 | # define config_get_now windows_get_now 35 | #elif HAVE_GMTIME 36 | # include "private/config/have_gmtime.h" 37 | # define config_get_now gmtime_get_now 38 | #else 39 | # include "private/config/no_gmtime.h" 40 | # define config_get_now no_gmtime_get_now 41 | #endif 42 | 43 | #endif /* __STUMPLESS_PRIVATE_CONFIG_WRAPPER_GET_NOW_H */ 44 | -------------------------------------------------------------------------------- /include/test/helper/memory_allocation.hpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_TEST_HELPER_MEMORY_ALLOCATION_HPP 20 | # define __STUMPLESS_TEST_HELPER_MEMORY_ALLOCATION_HPP 21 | 22 | # include 23 | # include 24 | 25 | # define MALLOC_FAIL \ 26 | []( size_t size ) -> void * { \ 27 | return NULL; \ 28 | } 29 | 30 | # define MALLOC_FAIL_ON_SIZE( fail_size ) \ 31 | []( size_t size ) -> void * { \ 32 | if( size == ( fail_size ) ) { \ 33 | return NULL; \ 34 | } else { \ 35 | return malloc( size ); \ 36 | } \ 37 | } 38 | 39 | # define REALLOC_FAIL \ 40 | []( void *, size_t ) -> void * { \ 41 | return NULL; \ 42 | } 43 | 44 | #endif /* __STUMPLESS_TEST_HELPER_MEMORY_ALLOCATION_HPP */ 45 | -------------------------------------------------------------------------------- /test/performance/version.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2021 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "test/helper/memory_counter.hpp" 22 | 23 | NEW_MEMORY_COUNTER( version_to_string ) 24 | 25 | static void VersionToString(benchmark::State& state){ 26 | const struct stumpless_version *current_version; 27 | char *result; 28 | 29 | INIT_MEMORY_COUNTER( version_to_string ); 30 | current_version = stumpless_get_version( ); 31 | 32 | for(auto _ : state){ 33 | result = stumpless_version_to_string( current_version ); 34 | if( !result ) { 35 | state.SkipWithError( "could not get the version as a string" ); 36 | } else { 37 | version_to_string_memory_counter_free( ( void * ) result ); 38 | } 39 | } 40 | 41 | version_to_string_memory_counter_free( ( void * ) current_version ); 42 | SET_STATE_COUNTERS( state, version_to_string ); 43 | } 44 | 45 | BENCHMARK( VersionToString ); 46 | -------------------------------------------------------------------------------- /include/private/config/wrapper/getpagesize.h: -------------------------------------------------------------------------------- 1 | 2 | /* SPDX-License-Identifier: Apache-2.0 */ 3 | 4 | /* 5 | * Copyright 2022 Joel E. Anderson 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | #ifndef __STUMPLESS_PRIVATE_CONFIG_WRAPPER_GETPAGESIZE_H 21 | # define __STUMPLESS_PRIVATE_CONFIG_WRAPPER_GETPAGESIZE_H 22 | 23 | # include "private/config.h" 24 | 25 | 26 | /* definition of config_getpagesize */ 27 | # ifdef SUPPORT_UNISTD_SYSCONF_GETPAGESIZE 28 | # include "private/config/unistd_sysconf_getpagesize_supported.h" 29 | # define config_getpagesize unistd_sysconf_getpagesize 30 | # elif HAVE_UNISTD_GETPAGESIZE 31 | # include "private/config/have_unistd_getpagesize.h" 32 | # define config_getpagesize unistd_getpagesize 33 | # elif HAVE_WINDOWS_H 34 | # include "private/config/have_windows.h" 35 | # define config_getpagesize windows_getpagesize 36 | # else 37 | # include "private/config/fallback.h" 38 | # define config_getpagesize fallback_getpagesize 39 | # endif 40 | 41 | #endif /* __STUMPLESS_PRIVATE_CONFIG_WRAPPER_GETPAGESIZE_H */ 42 | -------------------------------------------------------------------------------- /tools/cmake/chain.cmake: -------------------------------------------------------------------------------- 1 | list(APPEND STUMPLESS_SOURCES "${PROJECT_SOURCE_DIR}/src/target/chain.c") 2 | list(APPEND WRAPTURE_SPECS "${PROJECT_SOURCE_DIR}/tools/wrapture/chain_target.yml") 3 | 4 | if(INSTALL_HEADERS) 5 | install( 6 | FILES "${PROJECT_SOURCE_DIR}/include/stumpless/target/chain.h" 7 | DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/stumpless/target" 8 | ) 9 | endif() 10 | 11 | list(APPEND DOXYGEN_MANPAGES "${PROJECT_BINARY_DIR}/docs/${STUMPLESS_LANGUAGE}/man/man3/chain.h.3") 12 | 13 | if(INCLUDE_MANPAGES_IN_INSTALL) 14 | install(FILES 15 | "${PROJECT_BINARY_DIR}/docs/${STUMPLESS_LANGUAGE}/man/man3/chain.h.3" 16 | RENAME "stumpless_target_chain.h.3" 17 | DESTINATION "${CMAKE_INSTALL_MANDIR}/man3" 18 | ) 19 | endif() 20 | 21 | if(BUILD_TESTING) 22 | add_function_test(chain 23 | SOURCES 24 | "${PROJECT_SOURCE_DIR}/test/function/target/chain.cpp" 25 | $ 26 | $ 27 | LIBRARIES GTest::gmock 28 | ) 29 | 30 | if(STUMPLESS_THREAD_SAFETY_SUPPORTED) 31 | add_thread_safety_test(chain 32 | SOURCES 33 | "${PROJECT_SOURCE_DIR}/test/thread_safety/target/chain.cpp" 34 | $ 35 | $ 36 | ) 37 | endif() 38 | endif() 39 | 40 | if(BUILD_BENCHMARKING) 41 | add_performance_test(chain 42 | SOURCES 43 | "${PROJECT_SOURCE_DIR}/test/performance/target/chain.cpp" 44 | $ 45 | ) 46 | endif() 47 | 48 | add_example(chain 49 | "${PROJECT_SOURCE_DIR}/docs/examples/chain/chain_example.c" 50 | ) 51 | -------------------------------------------------------------------------------- /test/function/startup/entry_memory_failure.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2018-2024 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include "test/helper/assert.hpp" 24 | #include "test/helper/memory_allocation.hpp" 25 | 26 | using::testing::HasSubstr; 27 | 28 | namespace { 29 | 30 | TEST( EntryStartupTest, MemoryFailure ) { 31 | struct stumpless_entry *entry; 32 | void *(*result)(size_t); 33 | 34 | result = stumpless_set_malloc( MALLOC_FAIL ); 35 | ASSERT_NOT_NULL( result ); 36 | 37 | entry = stumpless_new_entry( STUMPLESS_FACILITY_USER, 38 | STUMPLESS_SEVERITY_INFO, 39 | "app-name", 40 | "msgid", 41 | "message" ); 42 | EXPECT_NULL( entry ); 43 | EXPECT_ERROR_ID_EQ( STUMPLESS_MEMORY_ALLOCATION_FAILURE ); 44 | 45 | stumpless_set_malloc( malloc ); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/config/thread_safety_supported.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2021 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include "private/cache.h" 21 | #include "private/config/thread_safety_supported.h" 22 | #include "private/config/wrapper/thread_safety.h" 23 | 24 | static struct cache *mutex_cache = NULL; 25 | 26 | void 27 | thread_safety_destroy_mutex( const config_mutex_t *mutex ) { 28 | config_destroy_mutex( mutex ); 29 | cache_free( mutex_cache, mutex ); 30 | } 31 | 32 | void 33 | thread_safety_free_all( void ) { 34 | cache_destroy( mutex_cache ); 35 | mutex_cache = NULL; 36 | } 37 | 38 | config_mutex_t * 39 | thread_safety_new_mutex( void ) { 40 | config_mutex_t *mutex; 41 | 42 | if( !mutex_cache ) { 43 | mutex_cache = cache_new( CONFIG_MUTEX_T_SIZE, NULL, NULL ); 44 | if( !mutex_cache ) { 45 | return NULL; 46 | } 47 | } 48 | 49 | mutex = cache_alloc( mutex_cache ); 50 | if( !mutex ) { 51 | return NULL; 52 | } 53 | 54 | config_init_mutex( mutex ); 55 | return mutex; 56 | } 57 | -------------------------------------------------------------------------------- /l10n/zh-cn/自述.md: -------------------------------------------------------------------------------- 1 | ![无树桩的标志](./资产/标志和名字.svg) 2 | 3 | **高性能,很多特征的C日志库** 4 | 5 | [![Linux编译](https://github.com/goatshriek/stumpless/actions/workflows/linux.yml/badge.svg)](https://github.com/goatshriek/stumpless/actions/workflows/linux.yml) 6 | [![Windows编译](https://github.com/goatshriek/stumpless/actions/workflows/windows.yml/badge.svg)](https://github.com/goatshriek/stumpless/actions/workflows/windows.yml) 7 | [![macOS编译](https://github.com/goatshriek/stumpless/actions/workflows/mac.yml/badge.svg)](https://github.com/goatshriek/stumpless/actions/workflows/mac.yml) 8 | [![代碼覆蓋率报告](https://codecov.io/gh/goatshriek/stumpless/branch/latest/graph/badge.svg)](https://codecov.io/gh/goatshriek/stumpless) 9 | [![SonarCloud地位](https://sonarcloud.io/api/project_badges/measure?project=stumpless&metric=alert_status)](https://sonarcloud.io/dashboard?id=stumpless) 10 | [![Gitter](https://badges.gitter.im/stumpless/community.svg)](https://gitter.im/stumpless/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) 11 | [![Apache 2.0许可证](https://img.shields.io/badge/%E8%AE%B8%E5%8F%AF%E8%AF%81-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) 12 | [![贡献者公约](https://img.shields.io/badge/%E8%B4%A1%E7%8C%AE%E8%80%85%E5%85%AC%E7%BA%A6-v2.1-ff69b4.svg)](https://github.com/goatshriek/stumpless/blob/latest/l10n/zh-cn/文档/行为守则.md) 13 | 14 | 15 | [English](./../../README.md) 16 | 17 | 18 | [重要特征](#重要特征) 19 | 20 | 21 | ## 重要特征 22 | 无树桩有很多特征做C日志又快又容易: 23 | * 线程安全 24 | * 访问得容易的 25 | [文档](https://goatshriek.github.io/stumpless/docs/c/latest/index.html), 26 | [示例](https://github.com/goatshriek/stumpless/tree/latest/docs/examples), 27 | [支持](https://gitter.im/stumpless/community)。 28 | -------------------------------------------------------------------------------- /.github/workflows/locale.yml: -------------------------------------------------------------------------------- 1 | name: "Locale" 2 | 3 | on: 4 | push: 5 | branches: [ latest ] 6 | pull_request: 7 | branches: [ latest ] 8 | 9 | env: 10 | CTEST_OUTPUT_ON_FAILURE: 1 11 | 12 | jobs: 13 | locales: 14 | name: "Locale Tests" 15 | runs-on: "ubuntu-latest" 16 | strategy: 17 | matrix: 18 | lang: 19 | - "bg_BG.UTF-8" 20 | - "bn_IN.UTF-8" 21 | - "cz_CZ.UTF-8" 22 | - "da_DK.UTF-8" 23 | - "de_DE.UTF-8" 24 | - "el_GR.UTF-8" 25 | - "es_ES.UTF-8" 26 | - "fr_FR.UTF-8" 27 | - "he_IL.UTF-8" 28 | - "hi_IN.UTF-8" 29 | - "hu_HU.UTF-8" 30 | - "it_IT.UTF-8" 31 | - "ja_JP.UTF-8" 32 | - "pl_PL.UTF-8" 33 | - "pt_BR.UTF-8" 34 | - "si_LK.UTF-8" 35 | - "sk_SK.UTF-8" 36 | - "sq_AL.UTF-8" 37 | - "sv_SE.UTF-8" 38 | - "sw_KE.UTF-8" 39 | - "te_IN.UTF-8" 40 | - "tr_TR.UTF-8" 41 | - "zh_CN.UTF-8" 42 | env: 43 | LANG: ${{ matrix.lang }} 44 | steps: 45 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 46 | - name: Configure 47 | run: | 48 | cmake . 49 | - name: Check Language 50 | run: | 51 | EXPECTED_LANG=$( echo $LANG | sed 's/\(..\)_\(..\).UTF-8/\1-\2/g' ) 52 | grep -q "STUMPLESS_LANGUAGE \"$EXPECTED_LANG\"" include/stumpless/config.h 53 | - name: Build 54 | run: | 55 | make all 56 | - name: Test 57 | run: | 58 | make check 59 | if grep "DEPRECATED" Testing/Temporary/LastTest.log; then exit 1; fi 60 | -------------------------------------------------------------------------------- /tools/cmake/socket.cmake: -------------------------------------------------------------------------------- 1 | list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/target/socket.c) 2 | list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/socket_supported.c) 3 | 4 | list(APPEND WRAPTURE_SPECS ${PROJECT_SOURCE_DIR}/tools/wrapture/socket_target.yml) 5 | 6 | if(INSTALL_HEADERS) 7 | install( 8 | FILES "${PROJECT_SOURCE_DIR}/include/stumpless/target/socket.h" 9 | DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/stumpless/target" 10 | ) 11 | endif() 12 | 13 | list(APPEND DOXYGEN_MANPAGES ${PROJECT_BINARY_DIR}/docs/${STUMPLESS_LANGUAGE}/man/man3/socket.h.3) 14 | 15 | if(INCLUDE_MANPAGES_IN_INSTALL) 16 | install(FILES 17 | ${PROJECT_BINARY_DIR}/docs/${STUMPLESS_LANGUAGE}/man/man3/socket.h.3 18 | RENAME stumpless_target_socket.h.3 19 | DESTINATION ${CMAKE_INSTALL_MANDIR}/man3 20 | ) 21 | endif() 22 | 23 | add_function_test(socket 24 | SOURCES 25 | test/function/target/socket.cpp 26 | $ 27 | $ 28 | LIBRARIES GTest::gmock 29 | ) 30 | 31 | add_function_test(socket_add_malloc_failure 32 | SOURCES 33 | "${PROJECT_SOURCE_DIR}/test/function/startup/target/socket_add_malloc_failure.cpp" 34 | LIBRARIES GTest::gmock 35 | ) 36 | 37 | add_function_test(socket_supported 38 | SOURCES "${PROJECT_SOURCE_DIR}/test/function/config/socket_supported.cpp" 39 | ) 40 | 41 | add_thread_safety_test(socket 42 | SOURCES 43 | "${PROJECT_SOURCE_DIR}/test/thread_safety/target/socket.cpp" 44 | $ 45 | $ 46 | ) 47 | 48 | add_example(socket 49 | "${PROJECT_SOURCE_DIR}/docs/examples/socket/socket_example.c" 50 | ) 51 | -------------------------------------------------------------------------------- /src/config/windows_get_now_supported.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2020-2023 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /* this must be included first to avoid errors */ 20 | #include "private/windows_wrapper.h" 21 | 22 | #include 23 | #include 24 | #include "private/config/windows_get_now_supported.h" 25 | #include "private/formatter.h" 26 | 27 | size_t 28 | windows_get_now( char *buffer ) { 29 | SYSTEMTIME now_st; 30 | int sprintf_result; 31 | 32 | GetSystemTime( &now_st ); 33 | 34 | sprintf_result = sprintf_s( buffer, 35 | RFC_5424_TIMESTAMP_BUFFER_SIZE, 36 | "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", 37 | now_st.wYear, 38 | now_st.wMonth, 39 | now_st.wDay, 40 | now_st.wHour, 41 | now_st.wMinute, 42 | now_st.wSecond, 43 | now_st.wMilliseconds ); 44 | 45 | return sprintf_result < 0 ? 0 : sprintf_result; 46 | } 47 | -------------------------------------------------------------------------------- /src/config/have_gmtime_r.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2018-2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include "private/config/have_gmtime_r.h" 23 | #include "private/formatter.h" 24 | 25 | size_t 26 | gmtime_r_get_now( char *buffer ) { 27 | int gettime_result; 28 | struct tm now_tm; 29 | struct timespec now_ts; 30 | const struct tm *gmtime_result; 31 | size_t written; 32 | 33 | gettime_result = clock_gettime( CLOCK_REALTIME, &now_ts ); 34 | if( gettime_result != 0 ) { 35 | return 0; 36 | } 37 | 38 | gmtime_result = gmtime_r( &(now_ts.tv_sec), &now_tm ); 39 | if( !gmtime_result ) { 40 | return 0; 41 | } 42 | 43 | written = strftime( buffer, 44 | RFC_5424_WHOLE_TIME_BUFFER_SIZE, 45 | "%FT%T", 46 | &now_tm ); 47 | written += snprintf( buffer + written, 48 | RFC_5424_TIME_SECFRAC_BUFFER_SIZE + 2, 49 | ".%06ldZ", 50 | ( now_ts.tv_nsec / 1000 ) % 1000000 ); 51 | 52 | return written; 53 | } 54 | -------------------------------------------------------------------------------- /test/function/cpp/memory.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | using namespace stumpless; 25 | 26 | namespace { 27 | 28 | TEST( SetFreeTest, CustomFunction ) { 29 | void (*result)(void *); 30 | 31 | result = MemoryManager::SetFree( [](void *ptr){ return; } ); 32 | EXPECT_TRUE( result != NULL ); 33 | 34 | result = MemoryManager::SetFree( free ); 35 | ASSERT_TRUE( result == free ); 36 | } 37 | 38 | TEST( SetFreeTest, NullFunction ) { 39 | void (*result)(void *); 40 | 41 | result = MemoryManager::SetFree( NULL ); 42 | ASSERT_EQ( NULL, result ); 43 | } 44 | 45 | TEST( SetMallocTest, NullFunction ) { 46 | void * (*result)(size_t); 47 | 48 | result = MemoryManager::SetMalloc( NULL ); 49 | ASSERT_EQ( NULL, result ); 50 | } 51 | 52 | TEST( SetReallocTest, NullFunction ) { 53 | void * (*result)(void *, size_t); 54 | 55 | result = MemoryManager::SetRealloc( NULL ); 56 | ASSERT_EQ( NULL, result ); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /include/private/config/have_stdatomic.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_PRIVATE_CONFIG_HAVE_STDATOMIC_H 20 | # define __STUMPLESS_PRIVATE_CONFIG_HAVE_STDATOMIC_H 21 | 22 | # include 23 | # include 24 | 25 | bool 26 | stdatomic_compare_exchange_bool( atomic_bool *b, 27 | bool expected, 28 | bool replacement ); 29 | 30 | bool 31 | stdatomic_compare_exchange_ptr( atomic_uintptr_t *p, 32 | const void *expected, 33 | const void *replacement ); 34 | 35 | bool 36 | stdatomic_read_bool( atomic_bool *b ); 37 | 38 | int 39 | stdatomic_read_int( atomic_int *i ); 40 | 41 | void * 42 | stdatomic_read_ptr( atomic_uintptr_t *p ); 43 | 44 | void 45 | stdatomic_write_bool( atomic_bool *b, bool replacement ); 46 | 47 | void 48 | stdatomic_write_int( atomic_int *i, int replacement ); 49 | 50 | void 51 | stdatomic_write_ptr( atomic_uintptr_t *p, void *replacement ); 52 | 53 | #endif /* __STUMPLESS_PRIVATE_CONFIG_HAVE_STDATOMIC_H */ 54 | -------------------------------------------------------------------------------- /test/function/leak/target.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2019-2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include "test/helper/memory_counter.hpp" 23 | 24 | #define TEST_BUFFER_LENGTH 2048 25 | 26 | NEW_MEMORY_COUNTER( add_message_leak ) 27 | 28 | namespace { 29 | 30 | TEST( AddMessageLeakTest, TypicalUse ) { 31 | struct stumpless_target *target; 32 | char buffer[TEST_BUFFER_LENGTH]; 33 | int i; 34 | int add_result; 35 | 36 | INIT_MEMORY_COUNTER( add_message_leak ); 37 | 38 | target = stumpless_open_buffer_target( "add-message-leak-testing", 39 | buffer, 40 | sizeof( buffer ) ); 41 | ASSERT_TRUE( target != NULL ); 42 | 43 | for( i = 0; i < 1000; i++ ) { 44 | add_result = stumpless_add_message( target, "temp message %d", i ); 45 | ASSERT_GE( add_result, 0 ); 46 | } 47 | 48 | stumpless_close_buffer_target( target ); 49 | 50 | stumpless_free_all( ); 51 | 52 | ASSERT_NO_LEAK( add_message_leak ); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /test/thread_safety/target/wel.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include "test/helper/assert.hpp" 24 | #include "test/helper/usage.hpp" 25 | 26 | namespace { 27 | const int THREAD_COUNT = 16; 28 | const int MESSAGE_COUNT = 100; 29 | 30 | TEST( WelWriteConsistency, SimultaneousWrites ) { 31 | struct stumpless_target *target; 32 | size_t i; 33 | std::thread *threads[THREAD_COUNT]; 34 | 35 | // set up the target to log to 36 | target = stumpless_open_local_wel_target("wel-target-test" ); 37 | EXPECT_NO_ERROR; 38 | ASSERT_NOT_NULL( target ); 39 | 40 | for( i = 0; i < THREAD_COUNT; i++ ) { 41 | threads[i] = new std::thread( add_messages, target, MESSAGE_COUNT ); 42 | } 43 | 44 | for( i = 0; i < THREAD_COUNT; i++ ) { 45 | threads[i]->join( ); 46 | delete threads[i]; 47 | } 48 | 49 | // cleanup after the test 50 | stumpless_close_wel_target( target ); 51 | EXPECT_NO_ERROR; 52 | 53 | stumpless_free_all( ); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /include/private/config/no_gmtime.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2024 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** @file 20 | * Fallback functionality for getting the current time. 21 | */ 22 | 23 | #ifndef __STUMPLESS_PRIVATE_CONFIG_NO_GMTIME_H 24 | #define __STUMPLESS_PRIVATE_CONFIG_NO_GMTIME_H 25 | 26 | #include 27 | 28 | /** 29 | * Writes an RFC 5424 NILVALUE to the provided buffer and returns its size. 30 | * 31 | * This function is used to get the time if no other suitable time function is 32 | * available. 33 | * 34 | * **Thread Safety: MT-Safe** 35 | * This function is thread safe. 36 | * 37 | * **Async Signal Safety: AS-Safe** 38 | * This function is safe to call from signal handlers. 39 | * 40 | * **Async Cancel Safety: AC-Safe** 41 | * This function is safe to call from threads that may be asynchronously 42 | * cancelled. 43 | * 44 | * @since release v2.2.0 45 | * 46 | * @param buffer The buffer to write the string into. 47 | * 48 | * @return The number of characters written into the buffer. 49 | */ 50 | size_t 51 | no_gmtime_get_now( char *buffer ); 52 | 53 | #endif /* __STUMPLESS_PRIVATE_CONFIG_NO_GMTIME_H */ 54 | -------------------------------------------------------------------------------- /test/function/cpp/element.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2020-2024 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | using namespace stumpless; 24 | 25 | namespace { 26 | 27 | class CppElementTest : public ::testing::Test { 28 | protected: 29 | Element *element_with_params; 30 | const char *param_1_name = "param-1-name"; 31 | const char *param_2_name = "param-1-name"; 32 | 33 | virtual void 34 | SetUp( void ) { 35 | element_with_params = new Element( "basic" ); 36 | element_with_params->AddParam( param_1_name, "param-1-value" ); 37 | element_with_params->AddParam( param_2_name, "param-2-value" ); 38 | } 39 | 40 | virtual void 41 | TearDown( void ) { 42 | delete element_with_params; 43 | MemoryManager::FreeAll( ); 44 | } 45 | }; 46 | 47 | TEST_F( CppElementTest, GetParamByIndex ) { 48 | Param param = element_with_params->GetParam( ( size_t ) 0 ); 49 | const char *param_name = param.GetName( ); 50 | EXPECT_STREQ( param_name, param_1_name ); 51 | free( ( void * ) param_name ); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /docs/cpp.md: -------------------------------------------------------------------------------- 1 | # Stumpless C++ 2 | 3 | The Stumpless library for C++ lightly wraps the base C library with an object 4 | model, and is intended to make logging feel more natural in C++. Of course, 5 | users can also choose to use the C library directly from their code rather than 6 | use the expanded C++ library. The library is generated using 7 | [Wrapture](https://github.com/goatshriek/wrapture) with a collection of specs 8 | defined in the `wrapture` directory of the source for Stumpless. 9 | 10 | ## Basic Usage 11 | The following snippets show some usage patterns specific to C++. If you're 12 | looking for basic usage of the C library, check out the main project 13 | [readme](https://github.com/goatshriek/stumpless/blob/latest/README.md) for a 14 | quick rundown of what you can do. 15 | 16 | Targets and entries can be created by instantiating the appropriate class, just 17 | as you might expect: 18 | 19 | ```cpp 20 | #include 21 | 22 | // ... 23 | 24 | FileTarget myLogFile( "logfile.log" ); 25 | 26 | Entry processStarting( Facility::USER, 27 | Severity::INFO, 28 | "my-application", 29 | "process-start-msgid", 30 | "A new process is starting." ); 31 | ``` 32 | 33 | And then logged to by using the `Log` function of the target: 34 | 35 | ```cpp 36 | myLogFile.Log( processStarting ); 37 | ``` 38 | 39 | The C++ library also puts functions and constants into a namespace and raises 40 | exceptions when errors are encountered. For more information and examples on 41 | what is possible, check out the 42 | [documentation](https://goatshriek.github.io/stumpless/docs/cpp/latest) for the C++ 43 | bindings and the 44 | [example code](https://goatshriek.github.io/stumpless/examples/cpp.html) in 45 | `docs/examples/cpp`. 46 | -------------------------------------------------------------------------------- /src/config/chain_unsupported.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2024 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include "private/config/wrapper/locale.h" 23 | #include "private/error.h" 24 | 25 | struct stumpless_target * 26 | stumpless_add_target_to_chain( struct stumpless_target *chain, 27 | struct stumpless_target *target ){ 28 | raise_target_unsupported( L10N_CHAIN_TARGETS_UNSUPPORTED ); 29 | return NULL; 30 | } 31 | 32 | void 33 | stumpless_close_chain_and_contents( struct stumpless_target *chain ){ 34 | raise_target_unsupported( L10N_CHAIN_TARGETS_UNSUPPORTED ); 35 | } 36 | 37 | void 38 | stumpless_close_chain_only( struct stumpless_target *chain ){ 39 | raise_target_unsupported( L10N_CHAIN_TARGETS_UNSUPPORTED ); 40 | } 41 | 42 | size_t 43 | stumpless_get_chain_length( const struct stumpless_target *chain ){ 44 | raise_target_unsupported( L10N_CHAIN_TARGETS_UNSUPPORTED ); 45 | return 0; 46 | } 47 | 48 | struct stumpless_target * 49 | stumpless_new_chain( const char *name ){ 50 | raise_target_unsupported( L10N_CHAIN_TARGETS_UNSUPPORTED ); 51 | return NULL; 52 | } 53 | -------------------------------------------------------------------------------- /include/test/helper/assert.hpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2020-2024 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_TEST_HELPER_ASSERT_HPP 20 | #define __STUMPLESS_TEST_HELPER_ASSERT_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #define ASSERT_NOT_NULL( thing ) ASSERT_FALSE( ( thing ) == NULL ) 27 | 28 | #define ASSERT_NULL( thing ) ASSERT_TRUE( ( thing ) == NULL ) 29 | 30 | #define EXPECT_ERROR_ID_EQ( code ) \ 31 | EXPECT_TRUE( stumpless_has_error() ); \ 32 | if( stumpless_has_error() ) { \ 33 | EXPECT_EQ( stumpless_get_error()->id, ( code ) ); \ 34 | } 35 | 36 | #define EXPECT_NO_ERROR \ 37 | EXPECT_FALSE( stumpless_has_error() ); \ 38 | stumpless_perror( "an unexpected error occurred" ) 39 | 40 | #define EXPECT_NOT_NULL( thing ) EXPECT_FALSE( ( thing ) == NULL ) 41 | 42 | #define EXPECT_NULL( thing ) EXPECT_TRUE( ( thing ) == NULL ) 43 | 44 | #endif /* __STUMPLESS_TEST_HELPER_ASSERT_HPP */ 45 | -------------------------------------------------------------------------------- /src/config/have_gmtime.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2023 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include "private/config/have_gmtime.h" 23 | #include "private/config/wrapper/thread_safety.h" 24 | #include "private/formatter.h" 25 | 26 | /** Used to synchronize access to gmtime return values. */ 27 | static config_atomic_bool_t gmtime_free = config_atomic_bool_true; 28 | 29 | size_t 30 | gmtime_get_now( char *buffer ) { 31 | time_t now_time; 32 | time_t time_result; 33 | bool locked; 34 | struct tm *now_tm; 35 | size_t result = 0; 36 | 37 | time_result = time( &now_time ); 38 | if( time_result == -1 ) { 39 | return 0; 40 | } 41 | 42 | do { 43 | locked = config_compare_exchange_bool( &gmtime_free, true, false ); 44 | } while( !locked ); 45 | 46 | now_tm = gmtime( &now_time ); 47 | if( !now_tm ) { 48 | goto cleanup_and_return; 49 | } 50 | 51 | result = strftime( buffer, 52 | RFC_5424_WHOLE_TIME_BUFFER_SIZE + 1, 53 | "%FT%TZ", 54 | now_tm ); 55 | 56 | cleanup_and_return: 57 | config_write_bool( &gmtime_free, true ); 58 | return result; 59 | } 60 | -------------------------------------------------------------------------------- /include/private/config/windows_get_now_supported.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2020-2023 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** @file 20 | * Functionality to get the current time, based on Windows functions. 21 | */ 22 | 23 | #ifndef __STUMPLESS_PRIVATE_CONFIG_WINDOWS_GET_NOW_SUPPORTED_H 24 | # define __STUMPLESS_PRIVATE_CONFIG_WINDOWS_GET_NOW_SUPPORTED_H 25 | 26 | # include 27 | 28 | /** 29 | * Gets the current time as a string and places it into the given buffer. 30 | * 31 | * **Thread Safety: MT-Safe** 32 | * This function is thread safe. 33 | * 34 | * **Async Signal Safety: AS-Unsafe** 35 | * This function is not safe to call from signal handlers, due to the use of 36 | * sprintf_s. 37 | * 38 | * **Async Cancel Safety: AC-Unsafe** 39 | * This function is not safe to call from threads that may be asynchronously 40 | * cancelled, due to the use of sprintf_s. 41 | * 42 | * @param buffer The buffer to write the string into. 43 | * 44 | * @return The number of characters written into the buffer. If an error is 45 | * encountered, then 0 is returned. 46 | */ 47 | size_t 48 | windows_get_now( char *buffer ); 49 | 50 | #endif /* __STUMPLESS_PRIVATE_CONFIG_WINDOWS_GET_NOW_SUPPORTED_H */ 51 | -------------------------------------------------------------------------------- /include/private/target/socket.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2018-2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_PRIVATE_TARGET_SOCKET_H 20 | # define __STUMPLESS_PRIVATE_TARGET_SOCKET_H 21 | 22 | # include 23 | # include 24 | # include 25 | # include 26 | 27 | struct socket_target { 28 | struct sockaddr_un target_addr; 29 | socklen_t target_addr_len; 30 | struct sockaddr_un local_addr; 31 | int local_socket; 32 | }; 33 | 34 | void 35 | destroy_socket_target( const struct socket_target *trgt ); 36 | 37 | int 38 | socket_target_is_open( const struct stumpless_target *target ); 39 | 40 | struct stumpless_target * 41 | open_socket_target( struct stumpless_target *target); 42 | 43 | struct socket_target * 44 | open_bind_socket( struct socket_target *target ); 45 | 46 | struct socket_target * 47 | new_socket_target( const char *dest, size_t dest_len, 48 | const char *source, size_t source_len ); 49 | 50 | int 51 | sendto_socket_target( const struct socket_target *target, 52 | const char *msg, 53 | size_t msg_length ); 54 | 55 | #endif /* __STUMPLESS_PRIVATE_TARGET_SOCKET_H */ 56 | -------------------------------------------------------------------------------- /src/config/no_vsnprintf_s.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2019 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include "private/config/no_vsnprintf_s.h" 23 | #include "private/memory.h" 24 | 25 | char * 26 | no_vsnprintf_s_format_string( const char *format, 27 | va_list subs, 28 | size_t *length ) { 29 | char *buffer; 30 | size_t buffer_size = 128; 31 | int result; 32 | char *new_buffer; 33 | 34 | buffer = alloc_mem( buffer_size ); 35 | if( !buffer ) { 36 | goto fail; 37 | } 38 | 39 | result = vsnprintf( buffer, buffer_size, format, subs ); 40 | if( result < 0 ) { 41 | goto fail_buffer; 42 | } 43 | 44 | if( result > buffer_size ) { 45 | 46 | new_buffer = realloc_mem( buffer, result ); 47 | if( !new_buffer ) { 48 | goto fail_buffer; 49 | } 50 | buffer = new_buffer; 51 | 52 | result = vsnprintf( buffer, buffer_size, format, subs ); 53 | if( result < 0 ) { 54 | goto fail_buffer; 55 | } 56 | 57 | } 58 | 59 | *length = result; 60 | return buffer; 61 | 62 | fail_buffer: 63 | free_mem( buffer ); 64 | fail: 65 | return NULL; 66 | } 67 | -------------------------------------------------------------------------------- /docs/examples/stream/README.md: -------------------------------------------------------------------------------- 1 | # Stream Targets 2 | 3 | Stream targets provide a simple way to send logs to any stream. This differs 4 | from file targets in that it allows the user of the library to open the stream 5 | and use it afterwards, or use a stream that has already been opened by another 6 | portion of code. Stream targets can also be used for logging to standard streams 7 | stdout and stderr, and there are even helper functions to create these targets. 8 | 9 | If you already have a `FILE` pointer, then you can open a stream target using it 10 | with the `stumpless_open_stream_target` function call, like this: 11 | 12 | ```c 13 | my_file = fopen( "myfile.log", "w+" ); 14 | myfile_target = stumpless_open_stream_target( "myfile", my_file ); 15 | ``` 16 | 17 | Note that the file will need to be opened in write or append mode. If it is not, 18 | then any attempts to send entries to it will fail with a write error. 19 | 20 | If you would like to simply log to the stdout or stderr streams, there are 21 | convenience functions that allow you to open these targets: 22 | 23 | ```c 24 | // equivalent to stumpless_open_stream_target( "normal-stuff", stdout ) 25 | console_target = stumpless_open_stdout_target( "normal-stuff" ); 26 | 27 | // equivalent to stumpless_open_stream_target( "bad-stuff", stderr ) 28 | error_target = stumpless_open_stderr_target( "bad-stuff" ); 29 | ``` 30 | 31 | Logging to a stream target is the same as any other target: 32 | 33 | ```c 34 | stumpless_add_entry( myfile_target, entry ); 35 | ``` 36 | 37 | Stream targets are closed with the `stumpless_close_stream_target` function. It 38 | is important to note that this does NOT close the stream itself, only the target 39 | that logs to it. The stream must be closed separately by the caller, like this: 40 | 41 | ```c 42 | stumpless_close_stream_target( myfile_target ); 43 | fclose( myfile ); 44 | ``` 45 | -------------------------------------------------------------------------------- /tools/wrapture/file_target.yml: -------------------------------------------------------------------------------- 1 | version: "0.4.2" 2 | classes: 3 | - name: "FileTarget" 4 | doc: > 5 | A target allowing logs to be written to a given file. Files are created 6 | as needed, and logs are appended to any existing contents. 7 | 8 | Events logged to the file will be separated by a newline character. 9 | namespace: "stumpless" 10 | constants: 11 | - name: "DEFAULT_FILE" 12 | type: "char *" 13 | value: "STUMPLESS_DEFAULT_FILE" 14 | includes: "stumpless/target.h" 15 | equivalent-struct: 16 | name: "stumpless_target" 17 | includes: "stumpless/target.h" 18 | constructors: 19 | - doc: > 20 | Creates a new file target with the given options and default facility 21 | code which will log messages to the given filename. 22 | 23 | Note that this will open the specified file, and it will remain open 24 | while this target is open. If you need to control the stream yourself, 25 | then you should use a StreamTarget instead. 26 | wrapped-function: 27 | name: "stumpless_open_file_target" 28 | includes: "stumpless/target/file.h" 29 | params: 30 | - name: "filename" 31 | doc: > 32 | The path to the file to write logs to. 33 | type: "const char *" 34 | return: 35 | type: "equivalent-struct-pointer" 36 | use-template: "pointer-return-error-check" 37 | destructor: 38 | doc: > 39 | Closes this target and releases all memory and other resources held by 40 | it. 41 | wrapped-function: 42 | name: "stumpless_close_file_target" 43 | includes: "stumpless/target/file.h" 44 | params: 45 | - name: "equivalent-struct-pointer" 46 | functions: 47 | - use-template: "common-target-functions" 48 | -------------------------------------------------------------------------------- /include/private/config/wrapper/open_default_target.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2022 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_PRIVATE_CONFIG_WRAPPER_OPEN_DEFAULT_TARGET_H 20 | # define __STUMPLESS_PRIVATE_CONFIG_WRAPPER_OPEN_DEFAULT_TARGET_H 21 | 22 | # include 23 | 24 | 25 | /* definition of config_open_default_target */ 26 | # ifdef STUMPLESS_WINDOWS_EVENT_LOG_TARGETS_SUPPORTED 27 | # include "private/config/wel_supported.h" 28 | # include "stumpless/target/wel.h" 29 | # define config_open_default_target wel_open_default_target 30 | # define config_close_default_target stumpless_close_wel_target 31 | # elif STUMPLESS_SOCKET_TARGETS_SUPPORTED 32 | # include 33 | # include "private/config/socket_supported.h" 34 | # define config_open_default_target socket_open_default_target 35 | # define config_close_default_target stumpless_close_socket_target 36 | # else 37 | # include 38 | # include "private/target/file.h" 39 | # define config_open_default_target file_open_default_target 40 | # define config_close_default_target stumpless_close_file_target 41 | # endif 42 | #endif /* __STUMPLESS_PRIVATE_CONFIG_WRAPPER_OPEN_DEFAULT_TARGET_H */ 43 | -------------------------------------------------------------------------------- /test/function/cpp/version.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2020 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | using namespace stumpless; 23 | 24 | namespace { 25 | 26 | class CppVersionTest : public ::testing::Test {}; 27 | 28 | TEST( Compare, MajorDifference ) { 29 | Version old_version( 1, 6, 0 ); 30 | Version new_version( 2, 0, 0 ); 31 | 32 | EXPECT_EQ( 100, new_version.Compare( old_version ) ); 33 | EXPECT_EQ( -100, old_version.Compare( new_version ) ); 34 | } 35 | 36 | TEST( Compare, MinorDifference ) { 37 | Version old_version( 1, 5, 0 ); 38 | Version new_version( 1, 6, 0 ); 39 | 40 | EXPECT_EQ( 10, new_version.Compare( old_version ) ); 41 | EXPECT_EQ( -10, old_version.Compare( new_version ) ); 42 | } 43 | 44 | TEST( Compare, PatchDifference ) { 45 | Version old_version( 1, 6, 1 ); 46 | Version new_version( 1, 6, 2 ); 47 | 48 | EXPECT_EQ( 1, new_version.Compare( old_version ) ); 49 | EXPECT_EQ( -1, old_version.Compare( new_version ) ); 50 | } 51 | 52 | TEST( GetVersion, Function ) { 53 | Version current_version = Version::GetCurrent(); 54 | 55 | EXPECT_STREQ(Version::CURRENT_VERSION, current_version.ToString().c_str()); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /test/performance/target/buffer.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2024 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "test/helper/memory_counter.hpp" 22 | #define MAX_BUFFER_SIZE (4ull * 1024ull) // 4 kB 23 | 24 | NEW_MEMORY_COUNTER( buffer ); 25 | 26 | class BufferFixture : public::benchmark::Fixture { 27 | protected: 28 | char buffer[MAX_BUFFER_SIZE]; 29 | 30 | public: 31 | void SetUp( const ::benchmark::State &state ) { 32 | INIT_MEMORY_COUNTER( buffer ); 33 | } 34 | 35 | void TearDown( const ::benchmark::State &state ) { 36 | FINALIZE_MEMORY_COUNTER( buffer ); 37 | stumpless_free_all(); 38 | } 39 | }; 40 | 41 | BENCHMARK_F( BufferFixture, OpenBufferTarget )( benchmark::State &state ) { 42 | for( auto _ : state ) { 43 | struct stumpless_target *target = stumpless_open_buffer_target( "buffer-perf", 44 | buffer, 45 | sizeof( buffer ) ); 46 | if( !target ) { 47 | state.SkipWithError( "could not open buffer target" ); 48 | } 49 | stumpless_close_buffer_target( target ); 50 | } 51 | 52 | SET_STATE_COUNTERS( state, buffer ); 53 | } 54 | -------------------------------------------------------------------------------- /tools/cmake/cpp_test.cmake: -------------------------------------------------------------------------------- 1 | if(MSVC) 2 | # the benefit of simple test code outweighs the burden of writing 3 | # platform-dependent code, such as the _s functions, just for tests 4 | set(cpp_test_compile_flags "-D_CRT_SECURE_NO_WARNINGS") 5 | else() 6 | set(cpp_test_compile_flags "") 7 | endif(MSVC) 8 | 9 | function(private_add_cpp_test) 10 | set(single_val_args NAME) 11 | set(multi_val_args SOURCES LIBRARIES) 12 | cmake_parse_arguments(CPP_TEST_ARG "" "${single_val_args}" "${multi_val_args}" ${ARGN}) 13 | 14 | set(t cpp-test-${CPP_TEST_ARG_NAME}) 15 | add_executable(${t} 16 | EXCLUDE_FROM_ALL 17 | ${CPP_TEST_ARG_SOURCES} 18 | ) 19 | 20 | set_target_properties(${t} 21 | PROPERTIES 22 | BUILD_RPATH "${PROJECT_BINARY_DIR}" 23 | OUTPUT_NAME ${t} 24 | COMPILE_FLAGS "${cpp_test_compile_flags}" 25 | ) 26 | 27 | target_link_libraries(${t} 28 | stumplesscpp 29 | GTest::gtest 30 | GTest::gtest_main 31 | ${CPP_TEST_ARG_LIBRARIES} 32 | ) 33 | 34 | set(have_runtime_dlls 35 | $> 36 | ) 37 | set(copy_command 38 | ${CMAKE_COMMAND} -E copy_if_different 39 | $ 40 | $ 41 | ) 42 | add_custom_command(TARGET ${t} POST_BUILD 43 | COMMAND "$<${have_runtime_dlls}:${copy_command}>" 44 | COMMAND_EXPAND_LISTS 45 | ) 46 | 47 | target_include_directories(cpp-test-${CPP_TEST_ARG_NAME} 48 | PRIVATE 49 | "${PROJECT_SOURCE_DIR}/include" 50 | "${PROJECT_BINARY_DIR}/include" 51 | "${PROJECT_BINARY_DIR}/cpp-lib" 52 | ) 53 | 54 | add_custom_target(run-${t} 55 | COMMAND "${t}" 56 | DEPENDS ${t} 57 | ) 58 | endfunction(private_add_cpp_test) 59 | 60 | macro(add_cpp_test name) 61 | list(APPEND STUMPLESS_CPP_TEST_RUNNERS run-cpp-test-${name}) 62 | 63 | private_add_cpp_test(NAME ${name} ${ARGN}) 64 | endmacro(add_cpp_test name) 65 | -------------------------------------------------------------------------------- /tools/wrapture/socket_target.yml: -------------------------------------------------------------------------------- 1 | version: "0.4.2" 2 | classes: 3 | - name: "SocketTarget" 4 | doc: > 5 | Socket targets allow logs to be sent to a Unix domain socket, like the 6 | frequently used /dev/log or /var/run/syslog sockets associated with syslog 7 | daemons. 8 | namespace: "stumpless" 9 | equivalent-struct: 10 | name: "stumpless_target" 11 | includes: "stumpless/target.h" 12 | constants: 13 | - name: "DEFAULT_SOCKET" 14 | doc: "A string literal with the default socket logged to." 15 | type: "char *" 16 | value: "STUMPLESS_DEFAULT_SOCKET" 17 | constructors: 18 | - doc: > 19 | Opens a socket target. 20 | wrapped-function: 21 | name: "stumpless_open_socket_target" 22 | includes: "stumpless/target/socket.h" 23 | params: 24 | - name: "name" 25 | doc: > 26 | The name of the socket to send logs to. 27 | type: "const char *" 28 | - name: "local_socket" 29 | doc: > 30 | The name of the Unix domain socket to connect from. This can be 31 | set to NULL if you'd like to simply let the target generate one. 32 | type: "const char *" 33 | return: 34 | type: "equivalent-struct-pointer" 35 | use-template: "pointer-return-error-check" 36 | destructor: 37 | doc: > 38 | Closes this target and releases all memory and other resources held by 39 | it. Notably, the connection to the socket is closed, and the local 40 | socket is cleaned up. 41 | wrapped-function: 42 | name: "stumpless_close_socket_target" 43 | includes: "stumpless/target/socket.h" 44 | params: 45 | - name: "equivalent-struct-pointer" 46 | functions: 47 | - use-template: "common-target-functions" 48 | -------------------------------------------------------------------------------- /include/private/config/have_gmtime_r.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2018-2023 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** @file 20 | * Functionality to get the current time, based on gmtime_r. 21 | */ 22 | 23 | #ifndef __STUMPLESS_PRIVATE_CONFIG_HAVE_GMTIME_R_H 24 | # define __STUMPLESS_PRIVATE_CONFIG_HAVE_GMTIME_R_H 25 | 26 | #include 27 | 28 | /** 29 | * Gets the current time as a string and places it into the given buffer. 30 | * 31 | * **Thread Safety: MT-Safe env locale** 32 | * This function is thread safe with the caveat that strftime uses env and 33 | * locale variables, which may cause issues in some cases. 34 | * 35 | * **Async Signal Safety: AS-Unsafe** 36 | * This function is not safe to call from signal handlers, due to the use of 37 | * snprintf. 38 | * 39 | * **Async Cancel Safety: AC-Unsafe** 40 | * This function is not safe to call from threads that may be asynchronously 41 | * cancelled, due to the use of snprintf and gmtime_r. 42 | * 43 | * @param buffer The buffer to write the string into. 44 | * 45 | * @return The number of characters written into the buffer. If an error is 46 | * encountered, then 0 is returned. 47 | */ 48 | size_t 49 | gmtime_r_get_now( char *buffer ); 50 | 51 | #endif /* __STUMPLESS_PRIVATE_CONFIG_HAVE_GMTIME_R_H */ 52 | -------------------------------------------------------------------------------- /test/performance/target/sqlite3.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2023 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include "test/helper/fixture.hpp" 22 | #include "test/helper/memory_counter.hpp" 23 | 24 | NEW_MEMORY_COUNTER( sqlite3_add ); 25 | 26 | class Sqlite3Fixture : public::benchmark::Fixture { 27 | protected: 28 | struct stumpless_target *target; 29 | struct stumpless_entry *entry; 30 | 31 | public: 32 | void SetUp( const ::benchmark::State &state ) { 33 | target = stumpless_open_sqlite3_target( ":memory:" ); 34 | stumpless_create_default_sqlite3_table( target ); 35 | entry = create_entry(); 36 | INIT_MEMORY_COUNTER( sqlite3_add ); 37 | } 38 | 39 | void TearDown( const ::benchmark::State &state ) { 40 | FINALIZE_MEMORY_COUNTER( sqlite3_add ); 41 | stumpless_destroy_entry_and_contents( entry ); 42 | stumpless_close_sqlite3_target_and_db( target ); 43 | stumpless_free_all(); 44 | } 45 | }; 46 | 47 | BENCHMARK_F( Sqlite3Fixture, AddEntry )( benchmark::State &state ) { 48 | for( auto _ : state ) { 49 | if( stumpless_add_entry( target, entry ) < 0 ) { 50 | state.SkipWithError( "could not send an entry" ); 51 | } 52 | } 53 | 54 | SET_STATE_COUNTERS( state, sqlite3_add ); 55 | } 56 | -------------------------------------------------------------------------------- /test/performance/target/wel.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2022 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include "test/helper/fixture.hpp" 23 | #include "test/helper/memory_counter.hpp" 24 | 25 | NEW_MEMORY_COUNTER( wel ); 26 | 27 | class WelFixture : public::benchmark::Fixture { 28 | protected: 29 | struct stumpless_target *target; 30 | struct stumpless_entry *entry; 31 | 32 | public: 33 | void SetUp( const ::benchmark::State &state ) { 34 | target = stumpless_open_local_wel_target( "Application" ); 35 | entry = create_entry( ); 36 | INIT_MEMORY_COUNTER( wel ); 37 | } 38 | 39 | void TearDown( const ::benchmark::State &state ) { 40 | stumpless_set_malloc( malloc ); 41 | stumpless_set_realloc( realloc ); 42 | stumpless_set_free( free ); 43 | stumpless_destroy_entry_and_contents( entry ); 44 | stumpless_close_wel_target( target ); 45 | stumpless_free_all( ); 46 | } 47 | }; 48 | 49 | BENCHMARK_F( WelFixture, AddEntry )( benchmark::State &state ) { 50 | for( auto _ : state ) { 51 | if( stumpless_add_entry( target, entry ) < 0 ) { 52 | state.SkipWithError( "could not send an entry" ); 53 | } 54 | } 55 | 56 | SET_STATE_COUNTERS( state, wel ); 57 | } 58 | -------------------------------------------------------------------------------- /include/private/config/wrapper/journald.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2021 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_PRIVATE_CONFIG_WRAPPER_JOURNALD_H 20 | # define __STUMPLESS_PRIVATE_CONFIG_WRAPPER_JOURNALD_H 21 | 22 | # include 23 | 24 | # ifdef STUMPLESS_JOURNALD_TARGETS_SUPPORTED 25 | # include 26 | # include "private/config/journald_supported.h" 27 | # include "private/target/journald.h" 28 | # define config_close_journald_target stumpless_close_journald_target 29 | # define config_init_journald_element journald_init_journald_element 30 | # define config_init_journald_param journald_init_journald_param 31 | # define config_journald_free_thread journald_free_thread 32 | # define config_send_entry_to_journald_target send_entry_to_journald_target 33 | # else 34 | # include "private/target.h" 35 | # define config_close_journald_target close_unsupported_target 36 | # define config_init_journald_element( ELEMENT ) ( ( void ) 0 ) 37 | # define config_init_journald_param( PARAM ) ( ( void ) 0 ) 38 | # define config_journald_free_thread( ) ( ( void ) 0 ) 39 | # define config_send_entry_to_journald_target send_entry_to_unsupported_target 40 | # endif 41 | 42 | #endif /* __STUMPLESS_PRIVATE_CONFIG_WRAPPER_JOURNALD_H */ 43 | -------------------------------------------------------------------------------- /test/performance/target/journald.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2021 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include "test/helper/fixture.hpp" 23 | #include "test/helper/memory_counter.hpp" 24 | 25 | NEW_MEMORY_COUNTER( function ); 26 | 27 | class JournaldFixture : public::benchmark::Fixture { 28 | protected: 29 | struct stumpless_target *target; 30 | struct stumpless_entry *entry; 31 | 32 | public: 33 | void SetUp( const ::benchmark::State &state ) { 34 | target = stumpless_open_journald_target( "journald-perf" ); 35 | entry = create_entry( ); 36 | INIT_MEMORY_COUNTER( function ); 37 | } 38 | 39 | void TearDown( const ::benchmark::State &state ) { 40 | stumpless_set_malloc( malloc ); 41 | stumpless_set_realloc( realloc ); 42 | stumpless_set_free( free ); 43 | stumpless_destroy_entry_and_contents( entry ); 44 | stumpless_close_journald_target( target ); 45 | stumpless_free_all( ); 46 | } 47 | }; 48 | 49 | BENCHMARK_F( JournaldFixture, AddEntry )( benchmark::State &state ) { 50 | for( auto _ : state ) { 51 | if( stumpless_add_entry( target, entry ) < 0 ) { 52 | state.SkipWithError( "could not send an entry" ); 53 | } 54 | } 55 | 56 | SET_STATE_COUNTERS( state, function ); 57 | } 58 | -------------------------------------------------------------------------------- /tools/wrapture/journald_target.yml: -------------------------------------------------------------------------------- 1 | version: "0.5.0" 2 | classes: 3 | - name: "JournaldTarget" 4 | doc: > 5 | A target allowing entries to be sent to a systemd journald service. 6 | 7 | Journald supports structured logging but does not use the same hierarchy 8 | as RFC 5424, instead providing a simple key/value pairing. To compensate 9 | for this these targets perform a number of transformations to map the 10 | elements and params into the flat hierarchy. By default element and param 11 | names are converted to uppercase and are joined together using 12 | underscores, but this behavior can be customized as needed. 13 | 14 | Because RFC 5424 allows most printable ASCII characters while journald 15 | only allows letters and numbers, incompatible characters of the generated 16 | field name will be replaced with an underscore to comply with journald 17 | requirements. 18 | namespace: "stumpless" 19 | equivalent-struct: 20 | name: "stumpless_target" 21 | includes: "stumpless/target.h" 22 | constructors: 23 | - doc: "Creates a new target with the given function." 24 | wrapped-function: 25 | name: "stumpless_open_journald_target" 26 | includes: "stumpless/target/function.h" 27 | params: 28 | - name: "name" 29 | doc: "The name of this target." 30 | type: "const char *" 31 | return: 32 | type: "equivalent-struct-pointer" 33 | use-template: "pointer-return-error-check" 34 | destructor: 35 | doc: > 36 | Closes this target and releases all memory and other resources held by 37 | it. 38 | wrapped-function: 39 | name: "stumpless_close_journald_target" 40 | includes: "stumpless/target/journald.h" 41 | params: 42 | - name: "equivalent-struct-pointer" 43 | functions: 44 | - use-template: "common-target-functions" 45 | -------------------------------------------------------------------------------- /test/function/leak/buffer.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2018-2024 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include "test/helper/assert.hpp" 23 | #include "test/helper/fixture.hpp" 24 | #include "test/helper/memory_counter.hpp" 25 | 26 | #define TEST_BUFFER_LENGTH 2048 27 | 28 | NEW_MEMORY_COUNTER( buffer_leak ) 29 | 30 | namespace { 31 | 32 | TEST( BufferTargetLeakTest, TypicalUse ) { 33 | struct stumpless_target *target; 34 | char buffer[TEST_BUFFER_LENGTH]; 35 | struct stumpless_entry *entry; 36 | size_t i; 37 | int add_result; 38 | 39 | INIT_MEMORY_COUNTER( buffer_leak ); 40 | 41 | target = stumpless_open_buffer_target( "buffer-leak-testing", 42 | buffer, 43 | TEST_BUFFER_LENGTH ); 44 | ASSERT_NOT_NULL( target ); 45 | 46 | entry = create_entry( ); 47 | ASSERT_NOT_NULL( entry ); 48 | 49 | for( i = 0; i < 1000; i++ ) { 50 | add_result = stumpless_add_entry( target, entry ); 51 | EXPECT_NO_ERROR; 52 | } 53 | 54 | stumpless_destroy_entry_and_contents( entry ); 55 | stumpless_close_buffer_target( target ); 56 | 57 | stumpless_free_all( ); 58 | 59 | ASSERT_NO_LEAK( buffer_leak ); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /tools/cmake/example.cmake: -------------------------------------------------------------------------------- 1 | if(MSVC) 2 | set(example_compile_flags "-D_CRT_SECURE_NO_WARNINGS") 3 | else() 4 | set(example_compile_flags "") 5 | endif() 6 | 7 | function(add_no_run_example name) 8 | add_executable(example-${name} 9 | EXCLUDE_FROM_ALL 10 | ${ARGN} 11 | ) 12 | 13 | set_target_properties(example-${name} 14 | PROPERTIES 15 | BUILD_RPATH "${CMAKE_CURRENT_BINARY_DIR}" 16 | COMPILE_FLAGS "${example_compile_flags}" 17 | ) 18 | 19 | target_link_libraries(example-${name} 20 | stumpless 21 | ) 22 | 23 | target_include_directories(example-${name} 24 | PRIVATE 25 | ${PROJECT_SOURCE_DIR}/include 26 | ${PROJECT_BINARY_DIR}/include 27 | ) 28 | endfunction(add_no_run_example) 29 | 30 | function(add_no_run_single_file_example name) 31 | add_executable(example-single-file-${name} 32 | EXCLUDE_FROM_ALL 33 | $ 34 | ${ARGN} 35 | ) 36 | 37 | set_target_properties(example-single-file-${name} 38 | PROPERTIES 39 | BUILD_RPATH "${CMAKE_CURRENT_BINARY_DIR}" 40 | COMPILE_FLAGS "${example_compile_flags}" 41 | ) 42 | 43 | target_include_directories(example-single-file-${name} 44 | PRIVATE 45 | "${SINGLE_INCLUDE_DIR}" 46 | "${PROJECT_BINARY_DIR}/include" 47 | ) 48 | endfunction(add_no_run_single_file_example) 49 | 50 | macro(add_example name) 51 | add_no_run_example(${name} ${ARGN}) 52 | 53 | list(APPEND STUMPLESS_EXAMPLE_RUNNERS run-example-${name}) 54 | add_custom_target(run-example-${name} 55 | COMMAND "example-${name}" 56 | DEPENDS example-${name} 57 | ) 58 | 59 | add_no_run_single_file_example(${name} ${ARGN}) 60 | list(APPEND STUMPLESS_SINGLE_FILE_TARGETS example-single-file-${name}) 61 | list(APPEND STUMPLESS_EXAMPLE_SINGLE_FILE_RUNNERS run-example-single-file-${name}) 62 | add_custom_target(run-example-single-file-${name} 63 | COMMAND "example-single-file-${name}" 64 | DEPENDS example-single-file-${name} 65 | ) 66 | endmacro(add_example) 67 | -------------------------------------------------------------------------------- /test/helper/usage.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2020-2023 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include "test/helper/assert.hpp" 23 | #include "test/helper/usage.hpp" 24 | 25 | void 26 | add_messages( struct stumpless_target *target, size_t message_count ) { 27 | for( size_t i = 0; i < message_count; i += 2 ) { 28 | stumpless_add_message( target, 29 | "message number #%zd from thread #%d", 30 | i, 31 | std::this_thread::get_id( ) ); 32 | EXPECT_NO_ERROR; 33 | 34 | stumpless_trace_message( target, 35 | __FILE__, 36 | __LINE__, 37 | __func__, 38 | "message number #%zd (trace) from thread #%d", 39 | i + 1, 40 | std::this_thread::get_id( ) ); 41 | EXPECT_NO_ERROR; 42 | } 43 | 44 | stumpless_free_thread( ); 45 | } 46 | 47 | void 48 | repeat_add_entry( struct stumpless_target *target, 49 | const struct stumpless_entry *entry, 50 | size_t count ) { 51 | for( size_t i = 0; i < count; i++ ) { 52 | stumpless_add_entry( target, entry ); 53 | EXPECT_NO_ERROR; 54 | } 55 | 56 | stumpless_free_thread( ); 57 | } 58 | -------------------------------------------------------------------------------- /include/private/config/wrapper/wel.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2018-2022 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_PRIVATE_CONFIG_WRAPPER_WEL_H 20 | # define __STUMPLESS_PRIVATE_CONFIG_WRAPPER_WEL_H 21 | 22 | # include 23 | 24 | # ifdef STUMPLESS_WINDOWS_EVENT_LOG_TARGETS_SUPPORTED 25 | # include 26 | # include "private/config/wel_supported.h" 27 | # include "private/target/wel.h" 28 | # define config_close_wel_target stumpless_close_wel_target 29 | # define config_sendto_wel_target sendto_wel_target 30 | # define config_copy_wel_data copy_wel_data 31 | # define config_destroy_wel_data destroy_wel_data 32 | # define config_initialize_wel_data initialize_wel_data 33 | # define config_set_entry_wel_type set_entry_wel_type 34 | # else 35 | # include 36 | # include "private/target.h" 37 | # define config_close_wel_target close_unsupported_target 38 | # define config_sendto_wel_target send_entry_and_msg_to_unsupported_target 39 | # define config_copy_wel_data( DESTINATION, SOURCE ) ( DESTINATION ) 40 | # define config_destroy_wel_data( ENTRY ) ( ( void ) 0 ) 41 | # define config_initialize_wel_data( ENTRY ) ( true ) 42 | # define config_set_entry_wel_type( ENTRY, SEVERITY ) ( ( void ) 0 ) 43 | # endif 44 | 45 | #endif /* __STUMPLESS_PRIVATE_CONFIG_WRAPPER_WEL_H */ 46 | -------------------------------------------------------------------------------- /include/test/helper/network.hpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2021 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_TEST_HELPER_NETWORK_HPP 20 | # define __STUMPLESS_TEST_HELPER_NETWORK_HPP 21 | 22 | # include 23 | # include "test/helper/server.hpp" 24 | 25 | void 26 | TestSetDestinationOnOpenTarget( struct stumpless_target *target, 27 | const char *original_destination, 28 | const char *new_destination, 29 | socket_handle_t new_dest_server ); 30 | 31 | void 32 | TestSetDestinationOnPausedTarget( struct stumpless_target *target, 33 | const char *new_destination, 34 | socket_handle_t new_dest_server ); 35 | 36 | void 37 | TestSetTransportPortOnOpenTarget( struct stumpless_target *target, 38 | const char *new_port, 39 | socket_handle_t new_port_server ); 40 | 41 | void 42 | TestSetTransportPortOnPausedTarget( struct stumpless_target *target, 43 | const char *destination, 44 | const char *new_port, 45 | socket_handle_t new_port_server ); 46 | 47 | void TestTruncatedMessage( struct stumpless_target *target ); 48 | 49 | #endif /* __STUMPLESS_TEST_HELPER_NETWORK_HPP */ 50 | -------------------------------------------------------------------------------- /test/thread_safety/target/file.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2020-2024 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include "test/helper/assert.hpp" 24 | #include "test/helper/rfc5424.hpp" 25 | #include "test/helper/usage.hpp" 26 | 27 | namespace { 28 | const int THREAD_COUNT = 16; 29 | const int MESSAGE_COUNT = 100; 30 | 31 | TEST( FileWriteConsistency, SimultaneousWrites ) { 32 | const char *filename = "file_target_thread_safety.log"; 33 | struct stumpless_target *target; 34 | size_t i; 35 | std::thread *threads[THREAD_COUNT]; 36 | 37 | remove( filename ); 38 | 39 | // set up the target to log to 40 | target = stumpless_open_file_target( filename ); 41 | EXPECT_NO_ERROR; 42 | ASSERT_NOT_NULL( target ); 43 | 44 | for( i = 0; i < THREAD_COUNT; i++ ) { 45 | threads[i] = new std::thread( add_messages, target, MESSAGE_COUNT ); 46 | } 47 | 48 | for( i = 0; i < THREAD_COUNT; i++ ) { 49 | threads[i]->join( ); 50 | delete threads[i]; 51 | } 52 | 53 | // cleanup after the test 54 | stumpless_close_file_target( target ); 55 | EXPECT_NO_ERROR; 56 | 57 | stumpless_free_all( ); 58 | 59 | // check for consistency in the log file 60 | TestRFC5424File( filename, THREAD_COUNT * MESSAGE_COUNT ); 61 | remove( filename ); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /tools/cmake/sqlite3.cmake: -------------------------------------------------------------------------------- 1 | list(APPEND STUMPLESS_SOURCES "${PROJECT_SOURCE_DIR}/src/target/sqlite3.c") 2 | list( 3 | APPEND WRAPTURE_SPECS 4 | "${PROJECT_SOURCE_DIR}/tools/wrapture/sqlite3_target.yml" 5 | ) 6 | list( 7 | APPEND DOXYGEN_MANPAGES 8 | "${PROJECT_BINARY_DIR}/docs/${STUMPLESS_LANGUAGE}/man/man3/sqlite3.h.3" 9 | ) 10 | 11 | if(INCLUDE_MANPAGES_IN_INSTALL) 12 | install(FILES 13 | "${PROJECT_BINARY_DIR}/docs/${STUMPLESS_LANGUAGE}/man/man3/sqlite3.h.3" 14 | RENAME "stumpless_target_sqlite3.h.3" 15 | DESTINATION "${CMAKE_INSTALL_MANDIR}/man3" 16 | ) 17 | endif() 18 | 19 | if(SQLITE3_SRC_PATH) 20 | add_library(sqlite3-src SHARED EXCLUDE_FROM_ALL "${SQLITE3_SRC_PATH}") 21 | set_target_properties(sqlite3-src PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) 22 | target_compile_definitions(sqlite3-src PUBLIC "SQLITE_OMIT_LOAD_EXTENSION") 23 | set(SQLITE3_LINK_NAME "sqlite3-src") 24 | else() 25 | list(APPEND STUMPLESS_LINK_LIBRARIES "sqlite3") 26 | set(SQLITE3_LINK_NAME "sqlite3") 27 | endif() 28 | 29 | if(BUILD_TESTING) 30 | add_function_test(sqlite3 31 | SOURCES 32 | "${PROJECT_SOURCE_DIR}/test/function/target/sqlite3.cpp" 33 | $ 34 | $ 35 | LIBRARIES 36 | "${SQLITE3_LINK_NAME}" 37 | ) 38 | endif() 39 | 40 | if(BUILD_BENCHMARKING) 41 | add_performance_test(sqlite3 42 | SOURCES 43 | "${PROJECT_SOURCE_DIR}/test/performance/target/sqlite3.cpp" 44 | $ 45 | ) 46 | endif() 47 | 48 | if(STUMPLESS_THREAD_SAFETY_SUPPORTED) 49 | add_thread_safety_test(sqlite3 50 | SOURCES 51 | "${PROJECT_SOURCE_DIR}/test/thread_safety/target/sqlite3.cpp" 52 | $ 53 | LIBRARIES 54 | "${SQLITE3_LINK_NAME}" 55 | ) 56 | endif() 57 | 58 | add_example(sqlite3 59 | "${PROJECT_SOURCE_DIR}/docs/examples/sqlite3/sqlite3_example.c" 60 | "${SQLITE3_SRC_PATH}" 61 | ) 62 | 63 | target_link_libraries(example-sqlite3 64 | "${SQLITE3_LINK_NAME}" 65 | ) 66 | -------------------------------------------------------------------------------- /include/private/prival.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | 3 | /* 4 | * Copyright 2018-2024 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef __STUMPLESS_PRIVATE_PRIVAL_H 20 | #define __STUMPLESS_PRIVATE_PRIVAL_H 21 | 22 | #include 23 | #include 24 | 25 | /** 26 | * Gets the priority value from facility and severity parameters. 27 | * 28 | * Priority value is calculated by left shifting the facility value by 3 29 | * and adding it to the severity value which is according to the 30 | * RFC 5424 Section 6.2.1. The shift operation is done prior to get_prival() 31 | * function with macros in "facility.h" 32 | * 33 | * Moved from "private/entry.h" to "private/prival.h" in release v3.0.0. 34 | * 35 | * **Thread Safety: MT-Safe** 36 | * This function is thread safe. 37 | * 38 | * **Async Signal Safety: AS-Safe ** 39 | * This function must be safe to call from signal handlers 40 | * 41 | * **Async Cancel Safety: AC-Safe** 42 | * This function must be safe to call from threads that may be asynchronously 43 | * cancelled. 44 | * 45 | * @param facility Facility value. This should be a \c STUMPLESS_FACILITY value. 46 | * 47 | * @param severity Severity value. This should be a \c STUMPLESS_SEVERITY value 48 | * 49 | * @return Priority value 50 | */ 51 | int 52 | get_prival( enum stumpless_facility facility, 53 | enum stumpless_severity severity ); 54 | 55 | #endif /* __STUMPLESS_PRIVATE_PRIVAL_H */ 56 | -------------------------------------------------------------------------------- /src/config/no_wcsrtombs_s.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | /* 4 | * Copyright 2022-2024 Joel E. Anderson 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include "private/config/wrapper/locale.h" 24 | #include "private/config/no_wcsrtombs_s.h" 25 | #include "private/error.h" 26 | #include "private/inthelper.h" 27 | #include "private/memory.h" 28 | 29 | char * 30 | no_wcsrtombs_s_copy_wstring_to_cstring( const wchar_t *str, int *copy_size ) { 31 | size_t buffer_size; 32 | char *buffer; 33 | mbstate_t state; 34 | size_t conversion_result; 35 | 36 | memset( &state, 0, sizeof( state ) ); 37 | conversion_result = wcsrtombs( NULL, &str, 0, &state ); 38 | if( conversion_result == -1 ) { 39 | raise_wide_conversion_failure( errno, L10N_ERRNO_ERROR_CODE_TYPE ); 40 | goto fail; 41 | } 42 | 43 | buffer_size = conversion_result + 1; // add NULL terminator 44 | buffer = alloc_mem( buffer_size ); 45 | if( !buffer ) { 46 | goto fail; 47 | } 48 | 49 | conversion_result = wcsrtombs( buffer, &str, buffer_size, &state ); 50 | if( conversion_result == -1 ) { 51 | raise_wide_conversion_failure( errno, L10N_ERRNO_ERROR_CODE_TYPE ); 52 | goto cleanup_and_fail; 53 | } 54 | 55 | if( copy_size ) { 56 | *copy_size = cap_size_t_to_int( buffer_size ); 57 | } 58 | 59 | return buffer; 60 | 61 | cleanup_and_fail: 62 | free_mem( buffer ); 63 | fail: 64 | return NULL; 65 | } 66 | --------------------------------------------------------------------------------