pax_global_header00006660000000000000000000000064145014201440014505gustar00rootroot0000000000000052 comment=dffe82c0483bb95d0d518ba1e36c568e63a24628 yder-1.4.20/000077500000000000000000000000001450142014400125345ustar00rootroot00000000000000yder-1.4.20/.github/000077500000000000000000000000001450142014400140745ustar00rootroot00000000000000yder-1.4.20/.github/workflows/000077500000000000000000000000001450142014400161315ustar00rootroot00000000000000yder-1.4.20/.github/workflows/codeql-analysis.yml000066400000000000000000000041751450142014400217530ustar00rootroot00000000000000name: "CodeQL" on: push: branches: [master, ] pull_request: # The branches below must be a subset of the branches above branches: [master] schedule: - cron: '0 4 * * 6' jobs: analyse: name: Analyse runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v2 with: # We must fetch at least the immediate parents so that if this is # a pull request then we can checkout the head. fetch-depth: 2 # If this run was triggered by a pull request event, then checkout # the head of the pull request instead of the merge commit. - run: git checkout HEAD^2 if: ${{ github.event_name == 'pull_request' }} # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@v1 # Override language selection by uncommenting this and choosing your languages # with: # languages: go, javascript, csharp, python, cpp, java # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) #- name: Autobuild # uses: github/codeql-action/autobuild@v1 # â„šī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl # âœī¸ If the Autobuild fails above, remove it and uncomment the following three lines # and modify them (or add more) to build your code if your project # uses a compiled language - name: dependencies run: | sudo apt-get update sudo apt-get install -y cmake pkg-config libsystemd-dev doxygen cd /opt git clone https://github.com/babelouest/orcania.git mkdir build cd build cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_LIBDIR=lib ../orcania make sudo make install rm -rf * - run: | mkdir build cd build cmake -DBUILD_YDER_DOCUMENTATION=on .. make && make doc sudo make install - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v1 yder-1.4.20/.github/workflows/main.yml000066400000000000000000000017001450142014400175760ustar00rootroot00000000000000on: [push, pull_request] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - name: install dependencies run: | sudo apt-get update sudo apt-get install -y cmake pkg-config check libsubunit-dev cppcheck libsystemd-dev doxygen - name: cppcheck run: cppcheck --force --enable=warning,missingInclude --error-exitcode=1 . - name: dependencies run: | cd /opt git clone https://github.com/babelouest/orcania.git mkdir build cd build cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_LIBDIR=lib ../orcania make sudo make install rm -rf * - name: build run: | mkdir build cd build cmake -DBUILD_YDER_TESTING=on -DBUILD_YDER_DOCUMENTATION=on .. make test package doc sudo make install sudo ldconfig cd .. make make clean check yder-1.4.20/.gitignore000066400000000000000000000000541450142014400145230ustar00rootroot00000000000000*.o *.so *.so.*.* *.a *.pc *.log yder-cfg.h yder-1.4.20/API.md000066400000000000000000000007701450142014400134730ustar00rootroot00000000000000# Yder Logging library written in C. Simple and easy to use logging library. You can log messages to the console, a file, syslog, journald or a callback function. Yder is multi-thread, which mean that you can use multiple instances of the function `y_log_message` at the same time in your program. Yet, `y_init_logs`, `y_set_logs_callback`, `y_set_date_format`, `y_set_split_message_newline` and `y_close_logs` are mono-thread. You might use those functions in the `main()` routine to ensure safety. yder-1.4.20/CHANGELOG.md000066400000000000000000000044661450142014400143570ustar00rootroot00000000000000# Yder Changelog ## 1.4.20 - cmake: remove `DownloadProject` feature, now dependencies must be previously installed ## 1.4.19 - Improve cmake script and MSVC support - Build with flag `-Wconversion` ## 1.4.18 - Minor bugfixes ## 1.4.17 - Fix `CMAKE_MODULE_PATH` who was used as single value (for real) ## 1.4.16 - Fix pkg-config file with absolute path for `CMAKE_INSTALL_{INCLUDE,LIB}DIR` - Fix `CMAKE_MODULE_PATH` who was used as single value - Add `y_set_split_message_newline` to split log messages on newline characters ## 1.4.15 - Use `o_strnullempty` instead of `o_strlen` to check if a `char *` has data ## 1.4.14 - Add ld flags in libyder.pc on static build ## 1.4.13 - Use `gmtime_s` on Windows (Thanks sudhip) ## 1.4.12 - Use `gmtime_r` instead of `localtime` - Fix documentation typos ## 1.4.11 - Update CI pipelines - cmake script: Add option `DOWNLOAD_DEPENDENCIES` - Harmonize licenses - Fix install pkgconfig by Makefile ## 1.4.10 - Add `y_set_date_format`, closes #17 - Remove generated doc from source package ## 1.4.9 - Fix pkgconfig dependency - Add doxygen documentation ## 1.4.8 - Avoid running `y_init_logs` without closing between ## 1.4.7 - Fix build for MacOSX (thanks JohnAZoidberg!) - Clean build process - Clean static variables if error initializing logs with file ## 1.4.6 - Fix package dependencies in cmake script ## 1.4.5 - Install pkgconfig file when using Makefile - Update src/Makefile to show more information - Adapt for MSVC - Fix pkgconfig bugs ## 1.4.4 - Improve build config file and install headers ## 1.4.3 - Add config file yder-cfg.h dynamically built with the options ## 1.4.2 - Add Travis CI - Change cmake option BUILD_TESTING to BUILD_YDER_TESTING - Add RPM in CMake script package ## 1.4.1 - Fix a bug about including time.h in the wrong place ## 1.4.0 - Add y_init_callback_logs to redirect all logs in a callback function ## 1.3.4 - Fix CMake build when /usr/local is not present in default build path ## 1.3.3 - Fix Makefile soname ## 1.3.2 - Fix Debian package build on CMake script ## 1.3.1 - Add Debian hardening patch on Makefile ## 1.3 - Fix Syslog bug - Add Journald (SystemD) logs with the mode Y_LOG_MODE_JOURNALD ## 1.2.1 - Update Orcania version - Added flags for building local static libraries ## 1.2.0 - Add CMake installation script yder-1.4.20/CMakeLists.txt000066400000000000000000000325221450142014400153000ustar00rootroot00000000000000# # Yder library # # CMake file used to build all programs # # Copyright 2018 Silvio Clecio # Copyright 2018-2022 Nicolas Mora # # This program is free software; you can redistribute it and/or # modify it under the terms of the MIT License # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # cmake_minimum_required(VERSION 3.5) project(yder C) set(CMAKE_C_STANDARD 99) if (NOT MSVC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror") endif() # library info set(PROJECT_DESCRIPTION "Logging library for C applications") set(PROJECT_HOMEPAGE_URL "https://github.com/babelouest/yder/") set(PROJECT_BUGREPORT_PATH "https://github.com/babelouest/yder/issues") set(LIBRARY_VERSION_MAJOR "1") set(LIBRARY_VERSION_MINOR "4") set(LIBRARY_VERSION_PATCH "20") set(PROJECT_VERSION "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}") set(PROJECT_VERSION_MAJOR ${LIBRARY_VERSION_MAJOR}) set(PROJECT_VERSION_MINOR ${LIBRARY_VERSION_MINOR}) set(PROJECT_VERSION_PATCH ${LIBRARY_VERSION_PATCH}) if (${LIBRARY_VERSION_MAJOR} VERSION_LESS 10) set (LIBRARY_VERSION_MAJOR_PAD "0${LIBRARY_VERSION_MAJOR}") else () set (LIBRARY_VERSION_MAJOR_PAD "${LIBRARY_VERSION_MAJOR}") endif () if (${LIBRARY_VERSION_MINOR} VERSION_LESS 10) set (LIBRARY_VERSION_MINOR_PAD "0${LIBRARY_VERSION_MINOR}") else () set (LIBRARY_VERSION_MINOR_PAD "${LIBRARY_VERSION_MINOR}") endif () if (${LIBRARY_VERSION_PATCH} VERSION_LESS 10) set (LIBRARY_VERSION_PATCH_PAD "0${LIBRARY_VERSION_PATCH}") else () set (LIBRARY_VERSION_PATCH_PAD "${LIBRARY_VERSION_PATCH}") endif () set(PROJECT_VERSION_NUMBER "${LIBRARY_VERSION_MAJOR_PAD}${LIBRARY_VERSION_MINOR_PAD}${LIBRARY_VERSION_PATCH_PAD}") set(LIBRARY_VERSION "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}") set(LIBRARY_SOVERSION "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}") set(ORCANIA_VERSION_REQUIRED "2.3.3") # cmake modules set(Y_CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules) list(APPEND CMAKE_MODULE_PATH "${Y_CMAKE_MODULE_PATH}") include(GNUInstallDirs) include(CheckSymbolExists) include(CMakePackageConfigHelpers) # check if _GNU_SOURCE is available if (NOT _GNU_SOURCE) check_symbol_exists(__GNU_LIBRARY__ "features.h" _GNU_SOURCE) if (NOT _GNU_SOURCE) unset(_GNU_SOURCE CACHE) check_symbol_exists(_GNU_SOURCE "features.h" _GNU_SOURCE) endif () endif () if (_GNU_SOURCE) add_definitions(-D_GNU_SOURCE) endif () # directories and source set(INC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) include_directories(${INC_DIR}) set(LIB_SRC ${INC_DIR}/yder.h # allow many IDEs to find and edit it ${SRC_DIR}/yder.c) # dependencies set(WITH_JOURNALD_DEFAULT ON) if(WIN32) set(WITH_JOURNALD_DEFAULT OFF) endif() option(WITH_JOURNALD "Check journald." ${WITH_JOURNALD_DEFAULT}) if (WITH_JOURNALD) find_package(Systemd REQUIRED) set(SYSTEMD_LIBRARIES Systemd::Systemd) set(Y_DISABLE_JOURNALD OFF) else() set(Y_DISABLE_JOURNALD ON) set(SYSTEMD_LIBRARIES ) endif () option(BUILD_SHARED "Build shared library." ON) option(BUILD_STATIC "Build static library." OFF) if (NOT BUILD_SHARED AND NOT BUILD_STATIC) message(FATAL_ERROR "BUILD_SHARED and BUILD_STATIC cannot be both disabled") endif () # static library if (BUILD_STATIC) add_library(yder_static STATIC ${LIB_SRC}) add_library(Yder::Yder-static ALIAS yder_static) target_include_directories(yder_static PUBLIC "$" PUBLIC "$" PUBLIC "$") target_compile_definitions(yder_static PUBLIC O_STATIC_LIBRARY) set_target_properties(yder_static PROPERTIES PUBLIC_HEADER "${INC_DIR}/yder.h;${PROJECT_BINARY_DIR}/yder-cfg.h" OUTPUT_NAME yder EXPORT_NAME Yder-static) if (MSVC) set_target_properties(yder_static PROPERTIES OUTPUT_NAME yder-static) else () target_compile_options(yder_static PRIVATE -Wextra -Wconversion) endif () set(yder_lib yder_static) endif () # shared library if (BUILD_SHARED) add_library(yder SHARED ${LIB_SRC}) add_library(Yder::Yder ALIAS yder) target_include_directories(yder PUBLIC "$" PUBLIC "$" PUBLIC "$") set_target_properties(yder PROPERTIES PUBLIC_HEADER "${INC_DIR}/yder.h;${PROJECT_BINARY_DIR}/yder-cfg.h" VERSION "${LIBRARY_VERSION}" SOVERSION "${LIBRARY_SOVERSION}" WINDOWS_EXPORT_ALL_SYMBOLS TRUE EXPORT_NAME Yder) if (WIN32) set_target_properties(yder PROPERTIES SUFFIX "-${LIBRARY_VERSION_MAJOR}.dll") endif () if (NOT MSVC) target_compile_options(yder PRIVATE -Wextra -Wconversion) endif () set(yder_lib yder) endif() find_package(Orcania ${ORCANIA_VERSION_REQUIRED} REQUIRED) if ("${ORCANIA_VERSION_STRING}" VERSION_GREATER_EQUAL "${ORCANIA_VERSION_REQUIRED}") message(STATUS "Orcania found: ${ORCANIA_VERSION_STRING}") else () message( FATAL_ERROR "Orcania version required: ${ORCANIA_VERSION_REQUIRED} - version installed: ${ORCANIA_VERSION_STRING}") endif () if (BUILD_SHARED) target_link_libraries(yder PRIVATE $ ${SYSTEMD_LIBRARIES}) endif () if (BUILD_STATIC) if(TARGET Orcania::Orcania-static) target_link_libraries(yder_static PRIVATE $ ${SYSTEMD_LIBRARIES}) else() target_link_libraries(yder_static PRIVATE $ ${SYSTEMD_LIBRARIES}) endif() endif () set(PKGCONF_REQ_PRIVATE "liborcania") set(PKGCONF_REQ "") if (WITH_JOURNALD) string(APPEND PKGCONF_REQ_PRIVATE ", libsystemd") endif () # documentation option(BUILD_YDER_DOCUMENTATION "Build the documentation." OFF) if (BUILD_YDER_DOCUMENTATION) find_package(Doxygen) if (DOXYGEN_FOUND) set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/doc/doxygen.cfg) set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/doxyfile) configure_file(${doxyfile_in} ${doxyfile} @ONLY) add_custom_target(doc COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile_in} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "Generating documentation with Doxygen" VERBATIM) else () message(FATAL_ERROR "Doxygen is needed to build the documentation.") endif () endif () # build yder-cfg.h file configure_file(${INC_DIR}/yder-cfg.h.in ${PROJECT_BINARY_DIR}/yder-cfg.h) set (CMAKE_EXTRA_INCLUDE_FILES ${PROJECT_BINARY_DIR}) include_directories(${PROJECT_BINARY_DIR}) # tests option(BUILD_YDER_TESTING "Build the testing tree." OFF) # because we don not use include(CTest) if (BUILD_YDER_TESTING) find_package(Check) if (CHECK_FOUND) if (NOT WIN32 AND NOT APPLE) find_package(Subunit REQUIRED) endif () enable_testing() set(CMAKE_CTEST_COMMAND ctest -V) set(TST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test) set(TEST_LIBS ${yder_lib} Check::Check Orcania::Orcania) if (NOT WIN32) find_package(Threads REQUIRED) list(APPEND TEST_LIBS ${CMAKE_THREAD_LIBS_INIT} m) endif () if (NOT APPLE) list(APPEND TEST_LIBS rt) endif () if (NOT WIN32 AND NOT APPLE) list(APPEND TEST_LIBS Subunit::Subunit) endif () set(TESTS yder_test) configure_file( "${Y_CMAKE_MODULE_PATH}/CTestCustom.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake" @ONLY) foreach (t ${TESTS}) add_executable(${t} EXCLUDE_FROM_ALL ${TST_DIR}/${t}.c) target_include_directories(${t} PRIVATE ${TST_DIR}) target_link_libraries(${t} PUBLIC ${TEST_LIBS}) add_test(NAME ${t} WORKING_DIRECTORY ${TST_DIR} COMMAND ${t}) endforeach () endif () endif () # install target option(INSTALL_HEADER "Install the header files" ON) # Install yder.h or not if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}") set(PKGCONFIG_TARGET_INCLUDES "${CMAKE_INSTALL_INCLUDEDIR}") else() set(PKGCONFIG_TARGET_INCLUDES "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") endif() if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}") set(PKGCONFIG_TARGET_LIBDIR "${CMAKE_INSTALL_LIBDIR}") else() set(PKGCONFIG_TARGET_LIBDIR "\${prefix}/${CMAKE_INSTALL_LIBDIR}") endif() configure_file(libyder.pc.in libyder.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libyder.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) set(TARGETS ) if (BUILD_SHARED) list(APPEND TARGETS yder) endif () if (BUILD_STATIC) list(APPEND TARGETS yder_static) endif () if (INSTALL_HEADER) install(TARGETS ${TARGETS} EXPORT YderExports RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) install(DIRECTORY examples/ DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples/ COMPONENT runtime) install(FILES README.md DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT runtime) else () install(TARGETS ${TARGETS} EXPORT YderExports RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif () if (INSTALL_HEADER) set(YDER_INSTALL_CMAKEDIR_DEFAULT "${CMAKE_INSTALL_LIBDIR}/cmake/Yder") if (WIN32 AND NOT MINGW) set(YDER_INSTALL_CMAKEDIR_DEFAULT "cmake") endif () set(YDER_INSTALL_CMAKEDIR ${YDER_INSTALL_CMAKEDIR_DEFAULT} CACHE STRING "Location where to install the cmake config files") install(EXPORT YderExports DESTINATION "${YDER_INSTALL_CMAKEDIR}" NAMESPACE "Yder::" FILE "YderTargets.cmake") configure_package_config_file(cmake-modules/YderConfig.cmake.in YderConfig.cmake INSTALL_DESTINATION "${YDER_INSTALL_CMAKEDIR}") write_basic_package_version_file(YderConfigVersion.cmake COMPATIBILITY AnyNewerVersion) install(FILES cmake-modules/FindSystemd.cmake "${PROJECT_BINARY_DIR}/YderConfig.cmake" "${PROJECT_BINARY_DIR}/YderConfigVersion.cmake" DESTINATION "${YDER_INSTALL_CMAKEDIR}") endif () # uninstall target if (NOT TARGET uninstall) configure_file( "${Y_CMAKE_MODULE_PATH}/CMakeUninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY) add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) endif () # packaging set(CPACK_PACKAGE_VERSION_MAJOR ${LIBRARY_VERSION_MAJOR}) set(CPACK_PACKAGE_VERSION_MINOR ${LIBRARY_VERSION_MINOR}) set(CPACK_PACKAGE_VERSION_PATCH ${LIBRARY_VERSION_PATCH}) if (INSTALL_HEADER) set(PACKAGE_FILE_NAME "lib${CMAKE_PROJECT_NAME}-dev_${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") else () set(PACKAGE_FILE_NAME "lib${CMAKE_PROJECT_NAME}_${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") endif () set(PACKAGE_IGNORED_FILES "${CMAKE_CURRENT_BINARY_DIR}/;/.git/;.gitignore;~$;${CPACK_SOURCE_IGNORE_FILES}") set(CPACK_PACKAGE_NAME "libyder") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Logging library for C applications") set(CPACK_GENERATOR "TGZ;DEB") set(CPACK_PACKAGE_VERSION_MAJOR ${LIBRARY_VERSION_MAJOR}) set(CPACK_PACKAGE_VERSION_MINOR ${LIBRARY_VERSION_MINOR}) set(CPACK_PACKAGE_VERSION_PATCH ${LIBRARY_VERSION_PATCH}) option(BUILD_RPM "Build a RPM for your system" OFF) if (BUILD_RPM) set(CPACK_GENERATOR "TGZ;DEB;RPM") set(CPACK_RPM_PACKAGE_LICENSE "LGPL") set(CPACK_RPM_PACKAGE_URL "http://babelouest.github.io/yder/") endif () set(CPACK_DEBIAN_PACKAGE_MAINTAINER "mail@babelouest.org") set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.4), liborcania (>= ${ORCANIA_VERSION_REQUIRED})") if (INSTALL_HEADER) if (WITH_SYSTEMD) set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libsystemd-dev") endif () else () if (WITH_SYSTEMD) set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libsystemd0") endif () endif () set(CPACK_PACKAGE_FILE_NAME ${PACKAGE_FILE_NAME}) set(CPACK_SOURCE_GENERATOR "TGZ") set(CPACK_SOURCE_PACKAGE_FILE_NAME ${PACKAGE_FILE_NAME}) set(CPACK_SOURCE_IGNORE_FILES ${PACKAGE_IGNORED_FILES}) include(CPack) add_custom_target(dist_y COMMAND ${CMAKE_MAKE_PROGRAM} package_source) message(STATUS "Journald support: ${WITH_JOURNALD}") message(STATUS "Build shared library: ${BUILD_SHARED}") message(STATUS "Build static library: ${BUILD_STATIC}") message(STATUS "Build testing tree: ${BUILD_YDER_TESTING}") message(STATUS "Install the header files: ${INSTALL_HEADER}") message(STATUS "Build RPM package: ${BUILD_RPM}") message(STATUS "Build documentation: ${BUILD_YDER_DOCUMENTATION}") yder-1.4.20/LICENSE000066400000000000000000000635361450142014400135560ustar00rootroot00000000000000 GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. (This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.) Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. {description} Copyright (C) {year} {fullname} This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. {signature of Ty Coon}, 1 April 1990 Ty Coon, President of Vice That's all there is to it! yder-1.4.20/Makefile000066400000000000000000000026151450142014400142000ustar00rootroot00000000000000# # Example program # # Makefile used to build all programs # # Copyright 2014-2022 Nicolas Mora # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public License # as published by the Free Software Foundation; # version 2.1 of the License. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU GENERAL PUBLIC LICENSE for more details. # # You should have received a copy of the GNU General Public # License along with this library. If not, see . # LIBYDER_LOCATION=./src EXAMPLE_LOCATION=./examples TEST_LOCATION=./test all: release debug: cd $(LIBYDER_LOCATION) && $(MAKE) debug $* install: cd $(LIBYDER_LOCATION) && $(MAKE) install clean: cd $(LIBYDER_LOCATION) && $(MAKE) clean cd $(EXAMPLE_LOCATION) && $(MAKE) clean cd $(TEST_LOCATION) && $(MAKE) clean rm -rf doc/html/ check: cd $(TEST_LOCATION) && $(MAKE) test release: cd $(LIBYDER_LOCATION) && $(MAKE) log_console: cd $(EXAMPLE_LOCATION) && $(MAKE) log_console log_file: cd $(EXAMPLE_LOCATION) && $(MAKE) log_file log_syslog: cd $(EXAMPLE_LOCATION) && $(MAKE) log_syslog log_combined: cd $(EXAMPLE_LOCATION) && $(MAKE) log_combined doxygen: doxygen doc/doxygen.cfg yder-1.4.20/README.md000066400000000000000000000163051450142014400140200ustar00rootroot00000000000000# Yder Logging library written in C. ![.github/workflows/main.yml](https://github.com/babelouest/yder/workflows/.github/workflows/main.yml/badge.svg) Simple and easy to use logging library. You can log messages to the console, a file, Syslog, journald or a callback function. Yder is mono-thread, which mean that you can use only one instance of Yder log at the same time in your program. See the [online documentation](https://babelouest.github.io/yder/) for a doxygen format of the API documentation. # Installation ## Distribution packages [![Packaging status](https://repology.org/badge/vertical-allrepos/yder.svg)](https://repology.org/metapackage/yder) Yder is available in multiple distributions as official package. Check out your distribution documentation to install the package automatically. ```shell $ # Example for Debian testing $ sudo apt install libyder-dev # Or apt install libyder2.0 if you don't need the development files ``` ## Pre-compiled packages You can install Yder with a pre-compiled package available in the [release pages](https://github.com/babelouest/yder/releases/latest/). Note that you need to install [Orcania](https://github.com/babelouest/orcania/releases/latest/) first. `jansson` development files packages is required to install Yder. ## Manual install ### Prerequisites You must install [Orcania](https://github.com/babelouest/orcania) first before building Yder. Orcania will be automatically installed if missing and you're using CMake. ### CMake - Multi architecture [CMake](https://cmake.org/download/) minimum 3.5 is required. Run the CMake script in a sub-directory, example: Last Yder release: [https://github.com/babelouest/yder/releases/latest/](https://github.com/babelouest/yder/releases/latest/) ```shell $ cd $ mkdir build $ cd build $ cmake .. $ make && sudo make install ``` The available options for CMake are: - `-DWITH_JOURNALD=[on|off]` (default `on`): Build with journald (SystemD) support - `-DBUILD_STATIC=[on|off]` (default `off`): Build the static archive in addition to the shared library - `-DBUILD_YDER_TESTING=[on|off]` (default `off`): Build unit tests - `-DBUILD_YDER_DOCUMENTATION=[on|off]` (default `off`): Build the documentation, doxygen is required - `-DINSTALL_HEADER=[on|off]` (default `on`): Install header file `yder.h` - `-DBUILD_RPM=[on|off]` (default `off`): Build RPM package when running `make package` - `-DCMAKE_BUILD_TYPE=[Debug|Release]` (default `Release`): Compile with debugging symbols or not ### Good ol' Makefile Download Yder from GitHub repository, compile and install. Last Yder release: [https://github.com/babelouest/yder/releases/latest/](https://github.com/babelouest/yder/releases/latest/) ```shell $ cd yder/src $ make $ sudo make install ``` To build Yder without Journald (SystemD) support, add the option Y_DISABLE_JOURNALD=1 to the `make command`: ```shell $ git clone https://github.com/babelouest/yder.git $ cd yder/src $ make Y_DISABLE_JOURNALD=1 $ sudo make install ``` By default, the shared library and the header file will be installed in the `/usr/local` location. To change this setting, you can modify the `DESTDIR` value in the `src/Makefile`. Example: install Yder in /tmp/lib directory ```shell $ cd src $ make && make DESTDIR=/tmp install ``` You can install Yder without root permission if your user has write access to `$(DESTDIR)`. A `ldconfig` command is executed at the end of the install, it will probably fail if you don't have root permission, but this is harmless. If you choose to install Yder in another directory, you must set your environment variable `LD_LIBRARY_PATH` properly. ### Install Yder as a static archive Install Yder library as a static archive, `libyder.a`, use the make commands `make static*`: ```shell $ cd src $ make static && sudo make static-install # or make DESTDIR=/tmp static-install if you want to install in `/tmp/lib` ``` # API Documentation ## Header files and compilation To use Yder in your code, you must include the file `yder.h`. ```c #include ``` ### Initialization Use the `y_init_logs` function to start logging. The prototype of this function is: ```c /** * Initialize logging with mode and level parameters, specify a log file if needed * Return true on success, false on error */ int y_init_logs(const char * app, const unsigned long init_mode, const unsigned long init_level, const char * init_log_file, const char * message); ``` The parameter `init_mode` is the initial mode for logging. You can specify and combine the following modes available: ```c Y_LOG_MODE_CONSOLE Y_LOG_MODE_SYSLOG Y_LOG_MODE_JOURNALD Y_LOG_MODE_FILE Y_LOG_MODE_CALLBACK ``` If you use Y_LOG_MODE_FILE in your initial mode, you must specify a valid path for the `init_log_file` parameter. The parameter `init_level` is the bottom level of your log messages. The levels available are, by level order: ```c Y_LOG_LEVEL_NONE Y_LOG_LEVEL_ERROR Y_LOG_LEVEL_WARNING Y_LOG_LEVEL_INFO Y_LOG_LEVEL_DEBUG ``` For example, if you specify `Y_LOG_LEVEL_WARNING` as init_level, you will see in your log output only `Y_LOG_LEVEL_WARNING` and `Y_LOG_LEVEL_ERROR`. If you specify `Y_LOG_LEVEL_DEBUG`, you will see in your log output all log messages. ### Redirect log messages to a callback function If you need to redirect log messages to a custom callback function, for example if you need to interact with other logging libraries, you must use the init_mode `Y_LOG_MODE_CALLBACK` in the `init_mode` parameter in the `y_init_logs` function, then use the function `y_set_logs_callback` with your callback function as parameter. ```C /** * Specify a callback function that will catch all log messages * In addition to other logs output already defined in y_init_logs */ int y_set_logs_callback(void (* y_callback_log_message) (void * cls, const char * app_name, const time_t date, const unsigned long level, const char * message), void * cls, const char * message); ``` The callback log function must have the following signature: ```C void y_callback_log_message(void * cls, const char * app_name, const time_t date, const unsigned long level, const char * message); ``` The parameters in the callback function are: ```C - void * cls // Your specified parameter - const char * app_name // The value app_name from y_init_logs - const time_t date // The datestamp when the log message was launched - const unsigned long level // The log level of the message, values can be: Y_LOG_LEVEL_ERROR, Y_LOG_LEVEL_WARNING, Y_LOG_LEVEL_INFO, Y_LOG_LEVEL_DEBUG ``` ### Close Yder To close Yder and free its allocated memory, use the function `y_close_logs`: ```c /** * Close the logs */ int y_close_logs(); ``` ### Log a message To log a message, use the function `y_log_message`, defined by: ```c /** * Log a message using current parameters */ void y_log_message(const unsigned long type, const char * message, ...); ``` This function uses `printf` prototype for the message and the log message type. For example: ```c y_log_message(Y_LOG_LEVEL_INFO, "Initializing application"); y_log_message(Y_LOG_LEVEL_ERROR, "Error in application, you have %d over %d threads in error mode", threads_error, threads_total); ``` ### Example source code See `examples` folder for detailed sample source codes. yder-1.4.20/_config.yml000066400000000000000000000000311450142014400146550ustar00rootroot00000000000000theme: jekyll-theme-slateyder-1.4.20/cmake-modules/000077500000000000000000000000001450142014400152625ustar00rootroot00000000000000yder-1.4.20/cmake-modules/CMakeUninstall.cmake.in000066400000000000000000000020641450142014400215450ustar00rootroot00000000000000if (NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt") endif (NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files) string(REGEX REPLACE "\n" ";" files "${files}") foreach (file ${files}) message(STATUS "Uninstalling $ENV{DESTDIR}${file}") if (IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") exec_program( "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" OUTPUT_VARIABLE rm_out RETURN_VALUE rm_retval ) if (NOT "${rm_retval}" STREQUAL 0) message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") endif (NOT "${rm_retval}" STREQUAL 0) else (IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") message(STATUS "File $ENV{DESTDIR}${file} does not exist.") endif (IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") endforeach (file) yder-1.4.20/cmake-modules/CTestCustom.cmake.in000066400000000000000000000001421450142014400211030ustar00rootroot00000000000000string(REPLACE ";" " " TESTS "@TESTS@") set(CTEST_CUSTOM_PRE_TEST "@CMAKE_MAKE_PROGRAM@ ${TESTS}")yder-1.4.20/cmake-modules/FindCheck.cmake000066400000000000000000000054641450142014400201130ustar00rootroot00000000000000#.rst: # FindCheck # ----------- # # Find Check # # Find Check headers and libraries. # # :: # # CHECK_FOUND - True if Check found. # CHECK_INCLUDE_DIRS - Where to find check.h. # CHECK_LIBRARIES - List of libraries when using Check. # CHECK_VERSION_STRING - The version of Check found. #============================================================================= # Copyright 2018 Silvio Clecio # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public License # as published by the Free Software Foundation; # version 2.1 of the License. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU GENERAL PUBLIC LICENSE for more details. # # You should have received a copy of the GNU General Public # License along with this library. If not, see . #============================================================================= # Sat Jan 20 23:33:47 -03 2018 find_package(PkgConfig QUIET) pkg_check_modules(PC_CHECK QUIET check) find_path(CHECK_INCLUDE_DIR NAMES check.h HINTS ${PC_CHECK_INCLUDEDIR} ${PC_CHECK_INCLUDE_DIRS}) find_library(CHECK_LIBRARY NAMES check libcheck HINTS ${PC_CHECK_LIBDIR} ${PC_CHECK_LIBRARY_DIRS}) if (PC_CHECK_VERSION) set(CHECK_VERSION_STRING ${PC_CHECK_VERSION}) elseif (CHECK_INCLUDE_DIR AND EXISTS "${CHECK_INCLUDE_DIR}/check.h") set(check_version_list MAJOR MINOR MICRO) foreach (v ${check_version_list}) set(regex_check_version "^#define CHECK_${v}_VERSION +\\(?([0-9]+)\\)?$") file(STRINGS "${CHECK_INCLUDE_DIR}/check.h" check_version_${v} REGEX "${regex_check_version}") string(REGEX REPLACE "${regex_check_version}" "\\1" check_version_${v} "${check_version_${v}}") unset(regex_check_version) endforeach () set(CHECK_VERSION_STRING "${check_version_MAJOR}.${check_version_MINOR}.${check_version_MICRO}") foreach (v check_version_list) unset(check_version_${v}) endforeach () unset(check_version_list) endif () include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Check REQUIRED_VARS CHECK_LIBRARY CHECK_INCLUDE_DIR VERSION_VAR CHECK_VERSION_STRING) if (CHECK_FOUND) set(CHECK_LIBRARIES ${CHECK_LIBRARY}) set(CHECK_INCLUDE_DIRS ${CHECK_INCLUDE_DIR}) if (NOT TARGET Check::Check) add_library(Check::Check UNKNOWN IMPORTED) set_target_properties(Check::Check PROPERTIES IMPORTED_LOCATION "${CHECK_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES "${CHECK_INCLUDE_DIR}") endif () endif () mark_as_advanced(CHECK_INCLUDE_DIR CHECK_LIBRARY) yder-1.4.20/cmake-modules/FindSubunit.cmake000066400000000000000000000043041450142014400205170ustar00rootroot00000000000000#.rst: # FindSubunit # ----------- # # Find Subunit # # Find Subunit headers and libraries. # # :: # # SUBUNIT_FOUND - True if Subunit found. # SUBUNIT_INCLUDE_DIRS - Where to find subunit/child.h. # SUBUNIT_LIBRARIES - List of libraries when using Subunit. # SUBUNIT_VERSION_STRING - The version of Subunit found. #============================================================================= # Copyright 2018 Silvio Clecio # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public License # as published by the Free Software Foundation; # version 2.1 of the License. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU GENERAL PUBLIC LICENSE for more details. # # You should have received a copy of the GNU General Public # License along with this library. If not, see . #============================================================================= # Fri Jan 19 22:27:51 -03 2018 find_package(PkgConfig QUIET) pkg_check_modules(PC_SUBUNIT QUIET libsubunit) set(SUBUNIT_VERSION_STRING "${PC_SUBUNIT_VERSION}") find_path(SUBUNIT_INCLUDE_DIR NAMES child.h HINTS ${PC_SUBUNIT_INCLUDEDIR} ${PC_SUBUNIT_INCLUDE_DIRS} PATH_SUFFIXES subunit) find_library(SUBUNIT_LIBRARY NAMES subunit libsubunit HINTS ${PC_SUBUNIT_LIBDIR} ${PC_SUBUNIT_LIBRARY_DIRS}) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Subunit REQUIRED_VARS SUBUNIT_LIBRARY SUBUNIT_INCLUDE_DIR VERSION_VAR SUBUNIT_VERSION_STRING) if (SUBUNIT_FOUND) set(SUBUNIT_LIBRARIES ${SUBUNIT_LIBRARY}) set(SUBUNIT_INCLUDE_DIRS ${SUBUNIT_INCLUDE_DIR}) if (NOT TARGET Subunit::Subunit) add_library(Subunit::Subunit UNKNOWN IMPORTED) set_target_properties(Subunit::Subunit PROPERTIES IMPORTED_LOCATION "${SUBUNIT_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES "${SUBUNIT_INCLUDE_DIR}") endif () endif () mark_as_advanced(SUBUNIT_INCLUDE_DIR SUBUNIT_LIBRARY)yder-1.4.20/cmake-modules/FindSystemd.cmake000066400000000000000000000040721450142014400205200ustar00rootroot00000000000000#.rst: # FindSystemd # ----------- # # Find Systemd # # Find Systemd headers and libraries. # # :: # # SYSTEMD_FOUND - True if Systemd found. # SYSTEMD_INCLUDE_DIRS - Where to find orcania.h. # SYSTEMD_LIBRARIES - List of libraries when using Systemd. #============================================================================= # Copyright 2018 Silvio Clecio # Copyright 2018 Nicolas Mora # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public License # as published by the Free Software Foundation; # version 2.1 of the License. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU GENERAL PUBLIC LICENSE for more details. # # You should have received a copy of the GNU General Public # License along with this library. If not, see . #============================================================================= # Sat Jan 27 15:57:36 -03 2018 find_package(PkgConfig QUIET) pkg_check_modules(PC_SYSTEMD QUIET systemd) find_path(SYSTEMD_INCLUDE_DIR NAMES systemd/_sd-common.h HINTS ${PC_SYSTEMD_INCLUDEDIR} ${PC_SYSTEMD_INCLUDE_DIRS}) find_library(SYSTEMD_LIBRARY NAMES systemd libsystemd HINTS ${PC_SYSTEMD_LIBDIR} ${PC_SYSTEMD_LIBRARY_DIRS}) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Systemd REQUIRED_VARS SYSTEMD_LIBRARY SYSTEMD_INCLUDE_DIR) if (SYSTEMD_FOUND) set(SYSTEMD_LIBRARIES ${SYSTEMD_LIBRARY}) set(SYSTEMD_INCLUDE_DIRS ${SYSTEMD_INCLUDE_DIR}) if (NOT TARGET Systemd:Systemd) add_library(Systemd::Systemd IMPORTED UNKNOWN) set_target_properties(Systemd::Systemd PROPERTIES IMPORTED_LOCATION "${SYSTEMD_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES "${SYSTEMD_INCLUDE_DIR}") endif () endif () mark_as_advanced(SYSTEMD_INCLUDE_DIR SYSTEMD_LIBRARY) yder-1.4.20/cmake-modules/YderConfig.cmake.in000066400000000000000000000016141450142014400207240ustar00rootroot00000000000000@PACKAGE_INIT@ include("${CMAKE_CURRENT_LIST_DIR}/YderTargets.cmake") set(YDER_JOURNALD @WITH_JOURNALD@) set(CMAKE_CURRENT_LIST_DIR ${_original_cmake_module_path}) if(TARGET Yder::Yder-static) set(ORCANIA_INCLUDE_DIRS $) set(ORCANIA_LIBRARIES Yder::Yder-static) endif() if(TARGET Yder::Yder) set(ORCANIA_INCLUDE_DIRS $) set(ORCANIA_LIBRARIES Yder::Yder) endif() include(CMakeFindDependencyMacro) set(_original_cmake_module_path ${CMAKE_MODULE_PATH}) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") find_dependency(Orcania) if(TARGET Yder::Yder-static) if(YDER_JOURNALD) find_dependency(Systemd) endif() endif() set(CMAKE_MODULE_PATH ${_original_cmake_module_path}) set(YDER_VERSION_STRING "@PROJECT_VERSION@") set(Yder_FOUND TRUE) yder-1.4.20/doc/000077500000000000000000000000001450142014400133015ustar00rootroot00000000000000yder-1.4.20/doc/doxygen.cfg000066400000000000000000000050751450142014400154460ustar00rootroot00000000000000# Doxyfile 1.9.1 PROJECT_NAME = "Yder" PROJECT_BRIEF = "Logging library written in C" INPUT = API.md \ ./src/ \ ./include/ USE_MDFILE_AS_MAINPAGE = API.md #--------------------------------------------------------------------------- # Project related configuration options #--------------------------------------------------------------------------- DOXYFILE_ENCODING = UTF-8 OUTPUT_DIRECTORY = doc CREATE_SUBDIRS = NO ALLOW_UNICODE_NAMES = NO OUTPUT_LANGUAGE = English BRIEF_MEMBER_DESC = YES REPEAT_BRIEF = YES ABBREVIATE_BRIEF = "The $name class" \ "The $name widget" \ "The $name file" \ is \ provides \ specifies \ contains \ represents \ a \ an \ the TAB_SIZE = 4 OPTIMIZE_OUTPUT_FOR_C = YES OPTIMIZE_OUTPUT_JAVA = NO OPTIMIZE_FOR_FORTRAN = NO OPTIMIZE_OUTPUT_VHDL = NO OPTIMIZE_OUTPUT_SLICE = NO #--------------------------------------------------------------------------- # Build related configuration options #--------------------------------------------------------------------------- EXTRACT_ALL = YES EXTRACT_PRIVATE = NO #--------------------------------------------------------------------------- # Configuration options related to the input files #--------------------------------------------------------------------------- INPUT_ENCODING = UTF-8 FILE_PATTERNS = *.c \ *.h \ *.md RECURSIVE = YES #--------------------------------------------------------------------------- # Configuration options related to the HTML output #--------------------------------------------------------------------------- GENERATE_HTML = YES HTML_OUTPUT = html HTML_FILE_EXTENSION = .html HTML_COLORSTYLE_HUE = 220 HTML_COLORSTYLE_SAT = 100 HTML_COLORSTYLE_GAMMA = 80 HTML_TIMESTAMP = NO HTML_DYNAMIC_MENUS = YES HTML_DYNAMIC_SECTIONS = NO GENERATE_LATEX = NO GENERATE_RTF = NO GENERATE_MAN = NO GENERATE_XML = NO GENERATE_DOCBOOK = NO GENERATE_AUTOGEN_DEF = NO GENERATE_PERLMOD = NO ENABLE_PREPROCESSING = YES MACRO_EXPANSION = NO EXPAND_ONLY_PREDEF = NO SEARCH_INCLUDES = YES HAVE_DOT = NO yder-1.4.20/examples/000077500000000000000000000000001450142014400143525ustar00rootroot00000000000000yder-1.4.20/examples/.gitignore000066400000000000000000000001401450142014400163350ustar00rootroot00000000000000log_combined log_console log_file log_syslog log_journald log_callback log_newline valgrind.txt yder-1.4.20/examples/Makefile000066400000000000000000000124751450142014400160230ustar00rootroot00000000000000# # Example program # # Makefile used to build the software # # Copyright 2014-2020 Nicolas Mora # # This program is free software; you can redistribute it and/or # modify it under the terms of the MIT License # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU GENERAL PUBLIC LICENSE for more details. # CC=gcc CFLAGS=-c -Wall -D_REENTRANT $(ADDITIONALFLAGS) -I$(INCLUDE_LOCATION) YDER_LOCATION=../src INCLUDE_LOCATION=../include LIBS=-lc -lyder -L$(YDER_LOCATION) ADDITIONALFLAGS=-O3 TARGET=log_console log_syslog log_file log_combined log_callback log_newline ifndef Y_DISABLE_JOURNALD TARGET+= log_journald endif all: libyder.so $(TARGET) clean: rm -f *.o valgrind.txt log_console log_syslog log_file log_combined log_journald log_callback log_newline debug: ADDITIONALFLAGS=-DDEBUG -g -O0 debug: libyder.so $(TARGET) libyder.so: cd $(YDER_LOCATION) && $(MAKE) log_console: log_console.c $(CC) -c $(CFLAGS) log_console.c $(CC) -o log_console log_console.o $(LIBS) log_syslog: log_syslog.c $(CC) -c $(CFLAGS) log_syslog.c $(CC) -o log_syslog log_syslog.o $(LIBS) log_journald: log_journald.c $(CC) -c $(CFLAGS) log_journald.c $(CC) -o log_journald log_journald.o $(LIBS) log_file: log_file.c $(CC) -c $(CFLAGS) log_file.c $(CC) -o log_file log_file.o $(LIBS) log_combined: log_combined.c $(CC) -c $(CFLAGS) log_combined.c $(CC) -o log_combined log_combined.o $(LIBS) log_callback: log_callback.c $(CC) -c $(CFLAGS) log_callback.c $(CC) -o log_callback log_callback.o $(LIBS) log_newline: log_newline.c $(CC) -c $(CFLAGS) log_newline.c $(CC) -o log_newline log_newline.o $(LIBS) test_console: libyder.so log_console LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./log_console test_syslog: libyder.so log_syslog LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./log_syslog test_file: libyder.so log_file LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./log_file test_combined: libyder.so log_combined LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./log_combined test_journald: libyder.so log_journald LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./log_journald test_callback: libyder.so log_callback LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./log_callback test_newline: libyder.so log_newline LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./log_newline ifndef Y_DISABLE_JOURNALD test: libyder.so $(TARGET) LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./log_console LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./log_syslog LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./log_file LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./log_combined LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./log_journald LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./log_callback LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./log_newline else LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./log_console LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./log_syslog LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./log_file LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./log_combined LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./log_callback LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./log_newline endif ifndef Y_DISABLE_JOURNALD memcheck: libyder.so $(TARGET) LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all ./log_console 2>valgrind.txt LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all ./log_syslog 2>>valgrind.txt LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all ./log_file 2>>valgrind.txt LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all ./log_combined 2>>valgrind.txt LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all ./log_journald 2>>valgrind.txt LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all ./log_callback 2>>valgrind.txt LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all ./log_newline 2>>valgrind.txt else LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all ./log_console 2>valgrind.txt LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all ./log_syslog 2>>valgrind.txt LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all ./log_file 2>>valgrind.txt LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all ./log_combined 2>>valgrind.txt LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all ./log_callback 2>>valgrind.txt LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all ./log_newline 2>>valgrind.txt endif yder-1.4.20/examples/log_callback.c000066400000000000000000000056351450142014400171240ustar00rootroot00000000000000/** * * Yder example program * * This example program describes the main features * that are available in a callback function * * Copyright 2014-2020 Nicolas Mora * * License MIT * */ #include #include #include #include #include "yder.h" void y_callback_log_message(void * cls, const char * app_name, const time_t date, const unsigned long level, const char * message) { char *level_name, date_stamp[20]; struct tm * tm_stamp; tm_stamp = localtime (&date); #ifndef _WIN32 strftime (date_stamp, sizeof(date_stamp), "%FT%TZ", tm_stamp); #else strftime (date_stamp, sizeof(date_stamp), "%Y-%m-%dT%H:%M:%S", tm_stamp); #endif switch (level) { case Y_LOG_LEVEL_ERROR: level_name = "ERROR"; break; case Y_LOG_LEVEL_WARNING: level_name = "WARNING"; break; case Y_LOG_LEVEL_INFO: level_name = "INFO"; break; case Y_LOG_LEVEL_DEBUG: level_name = "DEBUG"; break; default: level_name = "NONE"; break; } printf("Here is my callback log function\n- cls is %s\n- app_name is %s\n- date is %s\n- level is %s\n- message is '%s'\n\n", (char *)cls, app_name, date_stamp, level_name, message); } void write_logs(const char * level) { y_log_message(Y_LOG_LEVEL_ERROR, "This is an error message while level is %s", level); y_log_message(Y_LOG_LEVEL_WARNING, "This is a warning message while level is %s", level); y_log_message(Y_LOG_LEVEL_INFO, "This is an information message while level is %s", level); y_log_message(Y_LOG_LEVEL_DEBUG, "This is a debug message while level is %s", level); } int main(int argc, char ** argv) { char * level = NULL; char * cls = "my cls"; y_log_message(Y_LOG_LEVEL_ERROR, "This is an test error message without initialized logs"); if (y_init_logs("Yder Tests", Y_LOG_MODE_CALLBACK, Y_LOG_LEVEL_ERROR, NULL, "Initializing logs mode: callback, logs level: error") && y_set_logs_callback(&y_callback_log_message, cls, "callback init")) { level = "error"; write_logs(level); y_close_logs(); } if (y_init_logs("Yder Tests", Y_LOG_MODE_CALLBACK, Y_LOG_LEVEL_WARNING, NULL, "Initializing logs mode: callback, logs level: warning") && y_set_logs_callback(&y_callback_log_message, cls, "callback init")) { level = "warning"; write_logs(level); y_close_logs(); } if (y_init_logs("Yder Tests", Y_LOG_MODE_CALLBACK, Y_LOG_LEVEL_INFO, NULL, "Initializing logs mode: callback, logs level: info") && y_set_logs_callback(&y_callback_log_message, cls, "callback init")) { level = "info"; write_logs(level); y_close_logs(); } if (y_init_logs("Yder Tests", Y_LOG_MODE_CALLBACK, Y_LOG_LEVEL_DEBUG, NULL, "Initializing logs mode: callback, logs level: debug") && y_set_logs_callback(&y_callback_log_message, cls, "callback init")) { level = "debug"; write_logs(level); y_close_logs(); } return 0; } yder-1.4.20/examples/log_combined.c000066400000000000000000000033351450142014400171430ustar00rootroot00000000000000/** * * Yder example program * * This example program describes the main features * that are available in a callback function * * Copyright 2014-2020 Nicolas Mora * * License MIT * */ #include #include #include "yder.h" void write_logs(const char * level) { y_log_message(Y_LOG_LEVEL_ERROR, "This is an error message while level is %s", level); y_log_message(Y_LOG_LEVEL_WARNING, "This is a warning message while level is %s", level); y_log_message(Y_LOG_LEVEL_INFO, "This is an information message while level is %s", level); y_log_message(Y_LOG_LEVEL_DEBUG, "This is a debug message while level is %s", level); } int main(int argc, char ** argv) { if (y_init_logs("Yder Tests", Y_LOG_MODE_FILE | Y_LOG_MODE_CONSOLE | Y_LOG_MODE_SYSLOG, Y_LOG_LEVEL_ERROR, "/tmp/yder_log_error_combined.log", "Initializing logs mode: console, logs level: error")) { write_logs("error"); y_close_logs(); } if (y_init_logs("Yder Tests", Y_LOG_MODE_FILE | Y_LOG_MODE_CONSOLE | Y_LOG_MODE_SYSLOG, Y_LOG_LEVEL_WARNING, "/tmp/yder_log_warning_combined.log", "Initializing logs mode: console, logs level: warning")) { write_logs("warning"); y_close_logs(); } if (y_init_logs("Yder Tests", Y_LOG_MODE_FILE | Y_LOG_MODE_CONSOLE | Y_LOG_MODE_SYSLOG, Y_LOG_LEVEL_INFO, "/tmp/yder_log_info_combined.log", "Initializing logs mode: console, logs level: info")) { write_logs("info"); y_close_logs(); } if (y_init_logs("Yder Tests", Y_LOG_MODE_FILE | Y_LOG_MODE_CONSOLE | Y_LOG_MODE_SYSLOG, Y_LOG_LEVEL_DEBUG, "/tmp/yder_log_debug_combined.log", "Initializing logs mode: console, logs level: debug")) { write_logs("debug"); y_close_logs(); } return 0; } yder-1.4.20/examples/log_console.c000066400000000000000000000032441450142014400170240ustar00rootroot00000000000000/** * * Yder example program * * This example program describes the main features * that are available in a callback function * * Copyright 2014-2020 Nicolas Mora * * License MIT * */ #include #include #include #include "yder.h" void write_logs(const char * level) { y_log_message(Y_LOG_LEVEL_ERROR, "This is an error message while level is %s", level); y_log_message(Y_LOG_LEVEL_WARNING, "This is a warning message while level is %s", level); y_log_message(Y_LOG_LEVEL_INFO, "This is an information message while level is %s", level); y_log_message(Y_LOG_LEVEL_DEBUG, "This is a debug message while level is %s", level); } int main(int argc, char ** argv) { char * level = NULL; y_log_message(Y_LOG_LEVEL_ERROR, "This is an test error message without initialized logs"); if (y_init_logs("Yder Tests", Y_LOG_MODE_CONSOLE, Y_LOG_LEVEL_ERROR, NULL, "Initializing logs mode: console, logs level: error")) { level = "error"; write_logs(level); y_close_logs(); } if (y_init_logs("Yder Tests", Y_LOG_MODE_CONSOLE, Y_LOG_LEVEL_WARNING, NULL, "Initializing logs mode: console, logs level: warning")) { level = "warning"; write_logs(level); y_close_logs(); } if (y_init_logs("Yder Tests", Y_LOG_MODE_CONSOLE, Y_LOG_LEVEL_INFO, NULL, "Initializing logs mode: console, logs level: info")) { level = "info"; write_logs(level); y_close_logs(); } if (y_init_logs("Yder Tests", Y_LOG_MODE_CONSOLE, Y_LOG_LEVEL_DEBUG, NULL, "Initializing logs mode: console, logs level: debug")) { level = "debug"; write_logs(level); y_close_logs(); } return 0; } yder-1.4.20/examples/log_file.c000066400000000000000000000030111450142014400162710ustar00rootroot00000000000000/** * * Yder example program * * This example program describes the main features * that are available in a callback function * * Copyright 2014-2020 Nicolas Mora * * License MIT * */ #include #include #include "yder.h" void write_logs(const char * level) { y_log_message(Y_LOG_LEVEL_ERROR, "This is an error message while level is %s", level); y_log_message(Y_LOG_LEVEL_WARNING, "This is a warning message while level is %s", level); y_log_message(Y_LOG_LEVEL_INFO, "This is an information message while level is %s", level); y_log_message(Y_LOG_LEVEL_DEBUG, "This is a debug message while level is %s", level); } int main(int argc, char ** argv) { if (y_init_logs("Yder Tests", Y_LOG_MODE_FILE, Y_LOG_LEVEL_ERROR, "/tmp/yder_log_error.log", "Initializing logs mode: file, logs level: error")) { write_logs("error"); y_close_logs(); } if (y_init_logs("Yder Tests", Y_LOG_MODE_FILE, Y_LOG_LEVEL_WARNING, "/tmp/yder_log_warning.log", "Initializing logs mode: file, logs level: warning")) { write_logs("warning"); y_close_logs(); } if (y_init_logs("Yder Tests", Y_LOG_MODE_FILE, Y_LOG_LEVEL_INFO, "/tmp/yder_log_info.log", "Initializing logs mode: file, logs level: info")) { write_logs("info"); y_close_logs(); } if (y_init_logs("Yder Tests", Y_LOG_MODE_FILE, Y_LOG_LEVEL_DEBUG, "/tmp/yder_log_debug.log", "Initializing logs mode: file, logs level: debug")) { write_logs("debug"); y_close_logs(); } return 0; } yder-1.4.20/examples/log_journald.c000066400000000000000000000030271450142014400171770ustar00rootroot00000000000000/** * * Yder example program * * This example program describes the main features * that are available in a callback function * * Copyright 2014-2020 Nicolas Mora * * License MIT * */ #include #include #include "yder.h" #ifdef Y_DISABLE_JOURNALD #error "Journald log disabled" #endif void write_logs(const char * level) { y_log_message(Y_LOG_LEVEL_ERROR, "This is an error message while level is %s", level); y_log_message(Y_LOG_LEVEL_WARNING, "This is a warning message while level is %s", level); y_log_message(Y_LOG_LEVEL_INFO, "This is an information message while level is %s", level); y_log_message(Y_LOG_LEVEL_DEBUG, "This is a debug message while level is %s", level); } int main(int argc, char ** argv) { if (y_init_logs("Yder Tests", Y_LOG_MODE_JOURNALD, Y_LOG_LEVEL_ERROR, NULL, "Initializing logs mode: journald, logs level: error")) { write_logs("error"); y_close_logs(); } if (y_init_logs("Yder Tests", Y_LOG_MODE_JOURNALD, Y_LOG_LEVEL_WARNING, NULL, "Initializing logs mode: journald, logs level: warning")) { write_logs("warning"); y_close_logs(); } if (y_init_logs("Yder Tests", Y_LOG_MODE_JOURNALD, Y_LOG_LEVEL_INFO, NULL, "Initializing logs mode: journald, logs level: info")) { write_logs("info"); y_close_logs(); } if (y_init_logs("Yder Tests", Y_LOG_MODE_JOURNALD, Y_LOG_LEVEL_DEBUG, NULL, "Initializing logs mode: journald, logs level: debug")) { write_logs("debug"); y_close_logs(); } return 0; } yder-1.4.20/examples/log_newline.c000066400000000000000000000076161450142014400170320ustar00rootroot00000000000000/** * * Yder example program * * This example program describes the main features * that are available in a callback function * * Copyright 2014-2020 Nicolas Mora * * License MIT * */ #include #include #include #include "yder.h" void y_callback_log_message(void * cls, const char * app_name, const time_t date, const unsigned long level, const char * message) { char *level_name, date_stamp[20]; struct tm * tm_stamp; tm_stamp = localtime (&date); #ifndef _WIN32 strftime (date_stamp, sizeof(date_stamp), "%FT%TZ", tm_stamp); #else strftime (date_stamp, sizeof(date_stamp), "%Y-%m-%dT%H:%M:%S", tm_stamp); #endif switch (level) { case Y_LOG_LEVEL_ERROR: level_name = "ERROR"; break; case Y_LOG_LEVEL_WARNING: level_name = "WARNING"; break; case Y_LOG_LEVEL_INFO: level_name = "INFO"; break; case Y_LOG_LEVEL_DEBUG: level_name = "DEBUG"; break; default: level_name = "NONE"; break; } printf("Here is my callback log function\n- cls is %s\n- app_name is %s\n- date is %s\n- level is %s\n- message is '%s'\n\n", (char *)cls, app_name, date_stamp, level_name, message); } int main(int argc, char ** argv) { char * cls = "my cls"; if (y_init_logs("Yder Tests", Y_LOG_MODE_CONSOLE, Y_LOG_LEVEL_DEBUG, NULL, "Initializing logs mode: console, logs level: debug")) { y_set_split_message_newline(1, "Set newline"); y_log_message(Y_LOG_LEVEL_DEBUG, "A message in one line"); y_log_message(Y_LOG_LEVEL_DEBUG, "A message in\ntwo lines"); y_log_message(Y_LOG_LEVEL_DEBUG, "A message\nin\nfour\nlines"); y_close_logs(); } if (y_init_logs("Yder Tests", Y_LOG_MODE_FILE, Y_LOG_LEVEL_DEBUG, "/tmp/log_newline.log", "Initializing logs mode: file, logs level: debug")) { y_set_split_message_newline(1, "Set newline"); y_log_message(Y_LOG_LEVEL_DEBUG, "A message in one line"); y_log_message(Y_LOG_LEVEL_DEBUG, "A message in\ntwo lines"); y_log_message(Y_LOG_LEVEL_DEBUG, "A message\nin\nfour\nlines"); y_close_logs(); } if (y_init_logs("Yder Tests", Y_LOG_MODE_JOURNALD, Y_LOG_LEVEL_DEBUG, NULL, "Initializing logs mode: journald, logs level: debug")) { y_set_split_message_newline(1, "Set newline"); y_log_message(Y_LOG_LEVEL_DEBUG, "A message in one line"); y_log_message(Y_LOG_LEVEL_DEBUG, "A message in\ntwo lines"); y_log_message(Y_LOG_LEVEL_DEBUG, "A message\nin\nfour\nlines"); y_close_logs(); } if (y_init_logs("Yder Tests", Y_LOG_MODE_SYSLOG, Y_LOG_LEVEL_DEBUG, NULL, "Initializing logs mode: syslog, logs level: debug")) { y_set_split_message_newline(1, "Set newline"); y_log_message(Y_LOG_LEVEL_DEBUG, "A message in one line"); y_log_message(Y_LOG_LEVEL_DEBUG, "A message in\ntwo lines"); y_log_message(Y_LOG_LEVEL_DEBUG, "A message\nin\nfour\nlines"); y_close_logs(); } if (y_init_logs("Yder Tests", Y_LOG_MODE_CALLBACK, Y_LOG_LEVEL_DEBUG, NULL, "Initializing logs mode: callback, logs level: warning") && y_set_logs_callback(&y_callback_log_message, cls, "callback init")) { y_set_split_message_newline(1, "Set newline"); y_log_message(Y_LOG_LEVEL_DEBUG, "A message in one line"); y_log_message(Y_LOG_LEVEL_DEBUG, "A message in\ntwo lines"); y_log_message(Y_LOG_LEVEL_DEBUG, "A message\nin\nfour\nlines"); y_close_logs(); } if (y_init_logs("Yder Tests", Y_LOG_MODE_CONSOLE|Y_LOG_MODE_FILE|Y_LOG_MODE_CALLBACK, Y_LOG_LEVEL_DEBUG, "/tmp/log_newline_combined.log", "Initializing logs mode: file, logs level: debug") && y_set_logs_callback(&y_callback_log_message, cls, "callback init")) { y_set_split_message_newline(1, "Set newline"); y_log_message(Y_LOG_LEVEL_DEBUG, "A message in one line"); y_log_message(Y_LOG_LEVEL_DEBUG, "A message in\ntwo lines"); y_log_message(Y_LOG_LEVEL_DEBUG, "A message\nin\nfour\nlines"); y_close_logs(); } return 0; } yder-1.4.20/examples/log_syslog.c000066400000000000000000000027041450142014400167020ustar00rootroot00000000000000/** * * Yder example program * * This example program describes the main features * that are available in a callback function * * Copyright 2014-2020 Nicolas Mora * * License MIT * */ #include #include #include "yder.h" void write_logs(const char * level) { y_log_message(Y_LOG_LEVEL_ERROR, "This is an error message while level is %s", level); y_log_message(Y_LOG_LEVEL_WARNING, "This is a warning message while level is %s", level); y_log_message(Y_LOG_LEVEL_INFO, "This is an information message while level is %s", level); y_log_message(Y_LOG_LEVEL_DEBUG, "This is a debug message while level is %s", level); } int main(int argc, char ** argv) { if (y_init_logs("Yder Tests", Y_LOG_MODE_SYSLOG, Y_LOG_LEVEL_ERROR, NULL, "Initializing logs mode: syslog, logs level: error")) { write_logs("error"); y_close_logs(); } if (y_init_logs("Yder Tests", Y_LOG_MODE_SYSLOG, Y_LOG_LEVEL_WARNING, NULL, "Initializing logs mode: syslog, logs level: warning")) { write_logs("warning"); y_close_logs(); } if (y_init_logs("Yder Tests", Y_LOG_MODE_SYSLOG, Y_LOG_LEVEL_INFO, NULL, "Initializing logs mode: syslog, logs level: info")) { write_logs("info"); y_close_logs(); } if (y_init_logs("Yder Tests", Y_LOG_MODE_SYSLOG, Y_LOG_LEVEL_DEBUG, NULL, "Initializing logs mode: syslog, logs level: debug")) { write_logs("debug"); y_close_logs(); } return 0; } yder-1.4.20/include/000077500000000000000000000000001450142014400141575ustar00rootroot00000000000000yder-1.4.20/include/yder-cfg.h.in000066400000000000000000000023301450142014400164330ustar00rootroot00000000000000/** * * Yder Framework * * Logging framework library * * yder-cfg.h: configuration file * * Copyright 2018-2022 Nicolas Mora * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; * version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU General Public * License along with this library. If not, see . * */ #ifndef _YDER_CFG_H_ #define _YDER_CFG_H_ #define YDER_VERSION ${PROJECT_VERSION} #define YDER_VERSION_STR "${PROJECT_VERSION}" #define YDER_VERSION_MAJOR ${PROJECT_VERSION_MAJOR} #define YDER_VERSION_MINOR ${PROJECT_VERSION_MINOR} #define YDER_VERSION_PATCH ${PROJECT_VERSION_PATCH} #define YDER_VERSION_NUMBER ((YDER_VERSION_MAJOR << 16) | (YDER_VERSION_MINOR << 8) | (YDER_VERSION_PATCH << 0)) #cmakedefine Y_DISABLE_JOURNALD #endif /* _YDER_CFG_H_ */ yder-1.4.20/include/yder.h000066400000000000000000000106161450142014400152770ustar00rootroot00000000000000/** * * @file yder.h * @brief Yder framework * * Logging framework library * * yder.h: structures and functions declarations * * Copyright 2015-2022 Nicolas Mora * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; * version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU General Public * License along with this library. If not, see . * */ #ifndef __YDER_H__ #define __YDER_H__ #ifdef __cplusplus extern "C" { #endif #include "yder-cfg.h" #include /** * @defgroup const Constants * @{ */ #define Y_LOG_MODE_NONE 0x00000000 #define Y_LOG_MODE_CONSOLE 0x000000F0 #define Y_LOG_MODE_SYSLOG 0x00000F00 #define Y_LOG_MODE_FILE 0x0000F000 #define Y_LOG_MODE_JOURNALD 0x000F0000 #define Y_LOG_MODE_CALLBACK 0x00F00000 #define Y_LOG_MODE_CURRENT 0xFFFFFFFF #define Y_LOG_LEVEL_NONE 0x0000 #define Y_LOG_LEVEL_ERROR 0x000F #define Y_LOG_LEVEL_WARNING 0x00F0 #define Y_LOG_LEVEL_INFO 0x0F00 #define Y_LOG_LEVEL_DEBUG 0xF000 #define Y_LOG_LEVEL_CURRENT 0xFFFF #define Y_SPLIT_CURRENT -1 /** * @} */ /** * @defgroup init Initialization and closing functions * @{ */ /** * Initialize logging with mode and level parameters, specify a log file if needed * @param app: the name of the application that will be included in all log messages * @param init_mode: log mode, values available are * Y_LOG_MODE_NONE, Y_LOG_MODE_CONSOLE, Y_LOG_MODE_SYSLOG, Y_LOG_MODE_FILE, Y_LOG_MODE_JOURNALD * Multiple log modes are possible, values must be stacked, ex: Y_LOG_MODE_SYSLOG|Y_LOG_MODE_JOURNALD * @param init_level: minimum level of the log messages * Values available are Y_LOG_LEVEL_NONE, Y_LOG_LEVEL_ERROR, Y_LOG_LEVEL_WARNING, Y_LOG_LEVEL_INFO or Y_LOG_LEVEL_DEBUG * @param init_log_file: path to the file that will contain the log messages if log mode Y_LOG_MODE_FILE is selected * @param message: first message that will be appear in the logs * @return 1 on success, 0 on error */ int y_init_logs(const char * app, const unsigned long init_mode, const unsigned long init_level, const char * init_log_file, const char * message); /** * Specify a callback function that will catch all log messages * In addition to other logs output already defined in y_init_logs * @param y_callback_log_message a pointer to a user-defined callback function * @param cls a user-defined pointer that will be available on y_callback_log_message * @param message message that will be appear in the logs * @return 1 on success, 0 on error */ int y_set_logs_callback(void (* y_callback_log_message) (void * cls, const char * app_name, const time_t date, const unsigned long level, const char * message), void * cls, const char * message); /** * Specify a date format for console and file logging * Uses strftime syntax * @param format date format using strftime syntax * @param message message that will be appear in the logs * @return 1 on success, 0 on error */ int y_set_date_format(const char * format, const char * message); /** * Specify if the log messages must be splitted when a newline is in it * This function may have incidence on the application speed, * because it adds more memory allocations on each log message. * I recommend to use it only if relevant * @param split 0 to disable splitted logs, 1 to enable * @param message message that will be appear in the logs * @return 1 on success, 0 on error */ int y_set_split_message_newline(int split, const char * message); /** * Close the logs * @return 1 on success, 0 on error */ int y_close_logs(void); /** * @} */ /** * @defgroup log Logging function * @{ */ /** * Log a message using current parameters * @param type type of the log message * Values available are Y_LOG_LEVEL_ERROR, Y_LOG_LEVEL_WARNING, Y_LOG_LEVEL_INFO or Y_LOG_LEVEL_DEBUG * @param message the message to log, using printf format */ void y_log_message(const unsigned long type, const char * message, ...); /** * @} */ #ifdef __cplusplus } #endif #endif // __YDER_H__ yder-1.4.20/libyder.pc.in000066400000000000000000000006041450142014400151170ustar00rootroot00000000000000prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=@CMAKE_INSTALL_PREFIX@ libdir=@PKGCONFIG_TARGET_LIBDIR@ includedir=@PKGCONFIG_TARGET_INCLUDES@ Name: @PROJECT_NAME@ Description: @PROJECT_DESCRIPTION@ URL: @PROJECT_BUGREPORT_PATH@ Version: @LIBRARY_VERSION@ Requires: @PKGCONF_REQ@ Requires.private: @PKGCONF_REQ_PRIVATE@ Libs: -L${libdir} -lyder -lorcania @LIB_STATIC@ Cflags: -I${includedir} yder-1.4.20/src/000077500000000000000000000000001450142014400133235ustar00rootroot00000000000000yder-1.4.20/src/Makefile000066400000000000000000000115551450142014400147720ustar00rootroot00000000000000# # Yder Framework # # Makefile used to build the software # # Copyright 2015-2022 Nicolas Mora # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public License # as published by the Free Software Foundation; # version 2.1 of the License. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU GENERAL PUBLIC LICENSE for more details. # # You should have received a copy of the GNU General Public # License along with this library. If not, see . # PROJECT_NAME=yder PROJECT_DESCRIPTION=Logging library for C applications PROJECT_BUGREPORT_PATH=https://github.com/babelouest/yder/issues PKGCONF_REQ= PKGCONF_REQ_PRIVATE= DESTDIR=/usr/local YDER_INCLUDE=../include CONFIG_TEMPLATE=$(YDER_INCLUDE)/yder-cfg.h.in CONFIG_FILE=$(YDER_INCLUDE)/yder-cfg.h PKGCONFIG_FILE=../libyder.pc PKGCONFIG_TEMPLATE=../libyder.pc.in CC=gcc CFLAGS+=-c -fPIC -Wall -Werror -Wextra -Wconversion -D_REENTRANT -I$(YDER_INCLUDE) $(ADDITIONALFLAGS) $(CPPFLAGS) LIBS=-lc -lorcania OUTPUT=libyder.so VERSION_MAJOR=1 VERSION_MINOR=4 VERSION_PATCH=20 SONAME = -soname ifeq ($(shell uname -s),Darwin) SONAME = -install_name endif ifndef Y_DISABLE_JOURNALD DISABLE_JOURNALD=0 LIBSYSTEMD=-lsystemd else DISABLE_JOURNALD=1 endif all: release $(CONFIG_FILE): @cp $(CONFIG_TEMPLATE) $(CONFIG_FILE) @echo Config file $(CONFIG_FILE) generated @sed -i -e 's/$${PROJECT_VERSION}/$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH)/g' $(CONFIG_FILE) @sed -i -e 's/$${PROJECT_VERSION_MAJOR}/$(VERSION_MAJOR)/g' $(CONFIG_FILE) @sed -i -e 's/$${PROJECT_VERSION_MINOR}/$(VERSION_MINOR)/g' $(CONFIG_FILE) @sed -i -e 's/$${PROJECT_VERSION_PATCH}/$(VERSION_PATCH)/g' $(CONFIG_FILE) @sed -i -e 's/$${PROJECT_VERSION_NUMBER}/$(shell printf '%02d' $(VERSION_MAJOR))$(shell printf '%02d' $(VERSION_MINOR))$(shell printf '%02d' $(VERSION_PATCH))/g' $(CONFIG_FILE) @if [ "$(DISABLE_JOURNALD)" = "1" ]; then \ echo "JOURNALD SUPPORT DISABLED"; \ sed -i -e 's/\#cmakedefine Y_DISABLE_JOURNALD/\#define Y_DISABLE_JOURNALD/g' $(CONFIG_FILE); \ else \ echo "JOURNALD SUPPORT ENABLED"; \ sed -i -e 's/\#cmakedefine Y_DISABLE_JOURNALD/\/* #undef Y_DISABLE_JOURNALD *\//g' $(CONFIG_FILE); \ fi $(PKGCONFIG_FILE): @cp $(PKGCONFIG_TEMPLATE) $(PKGCONFIG_FILE) @echo Pkgconfig file $(PKGCONFIG_FILE) generated @sed -i -e 's#@CMAKE_INSTALL_PREFIX@#$(DESTDIR)#g' $(PKGCONFIG_FILE) @sed -i -e 's#@PKGCONFIG_TARGET_LIBDIR@#$${prefix}/lib#g' $(PKGCONFIG_FILE) @sed -i -e 's#@PKGCONFIG_TARGET_INCLUDES@#$${prefix}/include#g' $(PKGCONFIG_FILE) @sed -i -e 's/@PROJECT_NAME@/$(PROJECT_NAME)/g' $(PKGCONFIG_FILE) @sed -i -e 's/@PROJECT_DESCRIPTION@/$(PROJECT_DESCRIPTION)/g' $(PKGCONFIG_FILE) @sed -i -e 's|@PROJECT_BUGREPORT_PATH@|$(PROJECT_BUGREPORT_PATH)|g' $(PKGCONFIG_FILE) @sed -i -e 's/@LIBRARY_VERSION@/$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH)/g' $(PKGCONFIG_FILE) @sed -i -e 's/@PKGCONF_REQ@/$(PKGCONF_REQ)/g' $(PKGCONFIG_FILE) @sed -i -e 's/@PKGCONF_REQ_PRIVATE@/$(PKGCONF_REQ_PRIVATE)/g' $(PKGCONFIG_FILE) @sed -i -e 's/@LIB_STATIC@/$(LIB_STATIC)/g' $(PKGCONFIG_FILE) libyder.so: yder.o $(PKGCONFIG_FILE) $(CC) -shared -fPIC -Wl,$(SONAME),$(OUTPUT) -o $(OUTPUT).$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH) yder.o $(LIBS) $(LIBSYSTEMD) $(LDFLAGS) ln -sf $(OUTPUT).$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH) $(OUTPUT) libyder.a: yder.o $(PKGCONFIG_FILE) ar rcs libyder.a yder.o yder.o: $(CONFIG_FILE) $(YDER_INCLUDE)/yder.h yder.c $(CC) $(CFLAGS) yder.c clean: rm -f *.o *.so *.a $(OUTPUT) $(PKGCONFIG_FILE) $(OUTPUT).* $(YDER_INCLUDE)/yder-cfg.h install: all install $(OUTPUT).$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH) $(DESTDIR)/lib mkdir -p $(DESTDIR)/lib/pkgconfig/ $(DESTDIR)/include install -m644 $(PKGCONFIG_FILE) $(DESTDIR)/lib/pkgconfig/ install -m644 $(YDER_INCLUDE)/yder.h $(DESTDIR)/include install -m644 $(CONFIG_FILE) $(DESTDIR)/include -ldconfig $(DESTDIR)/lib static-install: static install libyder.a $(DESTDIR)/lib mkdir -p $(DESTDIR)/lib/pkgconfig/ $(DESTDIR)/include install -m644 $(PKGCONFIG_FILE) $(DESTDIR)/lib/pkgconfig install -m644 $(YDER_INCLUDE)/yder.h $(DESTDIR)/include install -m644 $(CONFIG_FILE) $(DESTDIR)/include uninstall: rm -f $(DESTDIR)/lib/$(OUTPUT) $(DESTDIR)/lib/libyder.a rm -f $(DESTDIR)/lib/$(OUTPUT).* rm -f $(DESTDIR)/include/yder.h rm -f $(DESTDIR)/include/$(CONFIG_FILE) rm -f $(DESTDIR)/lib/pkgconfig/$(PKGCONFIG_FILE) debug: ADDITIONALFLAGS=-DDEBUG -g -O0 debug: libyder.so release: ADDITIONALFLAGS=-O3 release: libyder.so static-debug: ADDITIONALFLAGS=-DDEBUG -g -O0 static-debug: libyder.a static: ADDITIONALFLAGS=-O3 static: libyder.a static: LIB_STATIC=$(LIBSYSTEMD) yder-1.4.20/src/yder.c000066400000000000000000000302461450142014400144370ustar00rootroot00000000000000/** * * Yder Framework * * Logging framework library * * yder.h: structures and functions declarations * * Copyright 2015-2022 Nicolas Mora * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; * version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU General Public * License along with this library. If not, see . * */ #include #include #include #include #include #include "yder.h" #ifndef _WIN32 #include #ifndef Y_DISABLE_JOURNALD #include #endif #endif /** * Write log message to console output (stdout or stderr) */ static void y_write_log_console(const char * app_name, const char * date_format, const time_t date, const unsigned long level, const char * message, int split) { char * level_name = NULL, date_stamp[64], ** message_split = NULL; FILE * output = NULL; struct tm tm_stamp; size_t i; #ifdef _WIN32 gmtime_s(&tm_stamp, &date); #else gmtime_r(&date, &tm_stamp); #endif if (date_format == NULL) { #ifndef _WIN32 strftime (date_stamp, sizeof(date_stamp), "%FT%TZ", &tm_stamp); #else strftime (date_stamp, sizeof(date_stamp), "%Y-%m-%dT%H:%M:%S", &tm_stamp); #endif } else { strftime (date_stamp, sizeof(date_stamp), date_format, &tm_stamp); } switch (level) { case Y_LOG_LEVEL_ERROR: level_name = "ERROR"; break; case Y_LOG_LEVEL_WARNING: level_name = "WARNING"; break; case Y_LOG_LEVEL_INFO: level_name = "INFO"; break; case Y_LOG_LEVEL_DEBUG: level_name = "DEBUG"; break; default: level_name = "NONE"; break; } if (level & Y_LOG_LEVEL_WARNING || level & Y_LOG_LEVEL_ERROR) { // Write to stderr output = stderr; } else { // Write to stdout output = stdout; } if (split == 1) { if (split_string(message, "\n", &message_split)) { for (i=0; message_split[i] != NULL; i++) { fprintf(output, "%s - %s %s: %s\n", date_stamp, app_name, level_name, message_split[i]); } free_string_array(message_split); } } else { fprintf(output, "%s - %s %s: %s\n", date_stamp, app_name, level_name, message); } fflush(output); } #ifndef _WIN32 /** * Write log message to syslog */ static void y_write_log_syslog(const char * app_name, const unsigned long level, const char * message) { openlog(app_name, LOG_PID|LOG_CONS, LOG_USER); switch (level) { case Y_LOG_LEVEL_ERROR: syslog( LOG_ERR, "%s", message ); break; case Y_LOG_LEVEL_WARNING: syslog( LOG_WARNING, "%s", message ); break; case Y_LOG_LEVEL_INFO: syslog( LOG_INFO, "%s", message ); break; case Y_LOG_LEVEL_DEBUG: syslog( LOG_DEBUG, "%s", message ); break; } closelog(); } #ifndef Y_DISABLE_JOURNALD /** * Write log message to journald */ static void y_write_log_journald(const char * app_name, const unsigned long level, const char * message) { switch (level) { case Y_LOG_LEVEL_ERROR: sd_journal_print( LOG_ERR, "%s - %s", app_name, message ); break; case Y_LOG_LEVEL_WARNING: sd_journal_print( LOG_WARNING, "%s - %s", app_name, message ); break; case Y_LOG_LEVEL_INFO: sd_journal_print( LOG_INFO, "%s - %s", app_name, message ); break; case Y_LOG_LEVEL_DEBUG: sd_journal_print( LOG_DEBUG, "%s - %s", app_name, message ); break; } } #endif #endif /** * Append log message to the log file */ static void y_write_log_file(const char * app_name, const char * date_format, const time_t date, FILE * log_file, const unsigned long level, const char * message, int split) { char * level_name = NULL, date_stamp[20], ** message_split = NULL; struct tm tm_stamp; size_t i; if (log_file != NULL) { #ifdef _WIN32 gmtime_s(&tm_stamp, &date); #else gmtime_r(&date, &tm_stamp); #endif if (date_format == NULL) { #ifndef _WIN32 strftime (date_stamp, sizeof(date_stamp), "%FT%TZ", &tm_stamp); #else strftime (date_stamp, sizeof(date_stamp), "%Y-%m-%dT%H:%M:%S", &tm_stamp); #endif } else { strftime (date_stamp, sizeof(date_stamp), date_format, &tm_stamp); } switch (level) { case Y_LOG_LEVEL_ERROR: level_name = "ERROR"; break; case Y_LOG_LEVEL_WARNING: level_name = "WARNING"; break; case Y_LOG_LEVEL_INFO: level_name = "INFO"; break; case Y_LOG_LEVEL_DEBUG: level_name = "DEBUG"; break; default: level_name = "NONE"; break; } if (split == 1) { if (split_string(message, "\n", &message_split)) { for (i=0; message_split[i] != NULL; i++) { fprintf(log_file, "%s - %s %s: %s\n", date_stamp, app_name, level_name, message_split[i]); } free_string_array(message_split); } } else { fprintf(log_file, "%s - %s %s: %s\n", date_stamp, app_name, level_name, message); } fflush(log_file); } } /** * Main function for logging messages * Warning ! Contains static variables used for not having to pass general configuration values every time you call log_message */ static int y_write_log(const char * app_name, const unsigned long init_mode, const unsigned long init_level, const char * init_log_file, void (* y_callback_log_message) (void * cls, const char * app_name, const time_t date, const unsigned long level, const char * message), void * cls, const char * date_format, int split, const unsigned long level, const char * message) { static unsigned long cur_mode = Y_LOG_MODE_NONE, cur_level = Y_LOG_LEVEL_NONE; FILE * cur_log_file = NULL; static char * cur_app_name = NULL; static const char * cur_log_file_path = NULL; static void (* cur_callback_log_message) (void * cls, const char * app_name, const time_t date, const unsigned long level, const char * message) = NULL; static void * cur_cls = NULL; static char * cur_date_format = NULL; static int cur_split = 0; time_t now; char ** message_split = NULL; size_t i; // Closing logs: free cur_app_name if (app_name == NULL && init_mode == Y_LOG_MODE_NONE && init_level == Y_LOG_LEVEL_NONE && init_log_file == NULL && level == Y_LOG_LEVEL_NONE && message == NULL) { o_free(cur_app_name); o_free(cur_date_format); cur_app_name = NULL; return 1; } time(&now); if (init_mode != Y_LOG_MODE_CURRENT) { cur_mode = init_mode; } if (init_level != Y_LOG_LEVEL_CURRENT) { cur_level = init_level; } if (y_callback_log_message != NULL) { cur_callback_log_message = y_callback_log_message; cur_cls = cls; } if (date_format != NULL) { o_free(cur_date_format); cur_date_format = o_strdup(date_format); } if (split != Y_SPLIT_CURRENT) { cur_split = split; } if (cur_mode == Y_LOG_MODE_NONE && cur_level == Y_LOG_LEVEL_NONE) { // Logs have not been initialized, cancel return 0; } if (init_log_file != NULL) { if (cur_log_file_path == NULL) { cur_log_file_path = init_log_file; } else { // Logs have already been initialized, cancel perror("Error - yder logs already initialized"); return 0; } } if (app_name != NULL) { if (cur_app_name == NULL) { cur_app_name = o_strdup(app_name); } else { // Logs have already been initialized, cancel perror("Error - yder logs already initialized"); return 0; } } if (init_mode == Y_LOG_MODE_FILE && o_strnullempty(cur_log_file_path)) { // Logs have already been initialized, cancel perror("Error - log file path missing"); return 0; } if (cur_log_file_path != NULL) { if ((cur_log_file = fopen(cur_log_file_path, "a+")) == NULL) { fprintf(stderr, "%s - ", cur_log_file_path); perror("Error opening log file"); cur_log_file_path = NULL; o_free(cur_app_name); o_free(cur_date_format); cur_app_name = NULL; return 0; } } // write message to expected output if level expected if (cur_level >= level) { if (message != NULL) { if (cur_mode & Y_LOG_MODE_CONSOLE) { y_write_log_console(cur_app_name, cur_date_format, now, level, message, cur_split); } #ifndef _WIN32 if (cur_mode & Y_LOG_MODE_SYSLOG) { y_write_log_syslog(cur_app_name, level, message); } #endif #if !defined(_WIN32) && !defined(Y_DISABLE_JOURNALD) if (cur_mode & Y_LOG_MODE_JOURNALD) { y_write_log_journald(cur_app_name, level, message); } #endif if (cur_mode & Y_LOG_MODE_FILE) { y_write_log_file(cur_app_name, cur_date_format, now, cur_log_file, level, message, cur_split); } if (cur_mode & Y_LOG_MODE_CALLBACK && cur_callback_log_message != NULL) { if (cur_split == 1) { if (split_string(message, "\n", &message_split)) { for (i=0; message_split[i] != NULL; i++) { cur_callback_log_message(cur_cls, cur_app_name, now, level, message_split[i]); } free_string_array(message_split); } } else { cur_callback_log_message(cur_cls, cur_app_name, now, level, message); } } } } if (cur_log_file != NULL && cur_log_file_path != NULL) { if (fclose(cur_log_file) != 0) { perror("Error closing log file"); return 0; } } return 1; } int y_init_logs(const char * app, const unsigned long init_mode, const unsigned long init_level, const char * init_log_file, const char * message) { #ifdef _WIN32 if (init_mode & Y_LOG_MODE_SYSLOG) { perror("syslog mode not supported on your architecture"); return 0; } #endif #if defined(_WIN32) || defined(Y_DISABLE_JOURNALD) if (init_mode & Y_LOG_MODE_JOURNALD) { perror("journald mode not supported on your architecture"); return 0; } #endif return y_write_log(app, init_mode, init_level, init_log_file, NULL, NULL, NULL, Y_SPLIT_CURRENT, Y_LOG_LEVEL_INFO, message); } int y_set_logs_callback(void (* y_callback_log_message) (void * cls, const char * app_name, const time_t date, const unsigned long level, const char * message), void * cls, const char * message) { if (y_callback_log_message != NULL) { return y_write_log(NULL, Y_LOG_MODE_CURRENT, Y_LOG_LEVEL_CURRENT, NULL, y_callback_log_message, cls, NULL, Y_SPLIT_CURRENT, Y_LOG_LEVEL_INFO, message); } else { return 0; } } int y_set_date_format(const char * format, const char * message) { if (!o_strnullempty(format)) { return y_write_log(NULL, Y_LOG_MODE_CURRENT, Y_LOG_LEVEL_CURRENT, NULL, NULL, NULL, format, Y_SPLIT_CURRENT, Y_LOG_LEVEL_INFO, message); } else { return 0; } } int y_set_split_message_newline(int split, const char * message) { return y_write_log(NULL, Y_LOG_MODE_CURRENT, Y_LOG_LEVEL_CURRENT, NULL, NULL, NULL, NULL, split, Y_LOG_LEVEL_INFO, message); } int y_close_logs(void) { return y_write_log(NULL, 0, 0, NULL, NULL, NULL, NULL, Y_SPLIT_CURRENT, 0, NULL); } void y_log_message(const unsigned long level, const char * message, ...) { va_list args, args_cpy; size_t out_len = 0; char * out = NULL; va_start(args, message); // Use va_copy to make a new args pointer to avoid problems with vsnprintf which can change args parameter on some architectures va_copy(args_cpy, args); out_len = (size_t)vsnprintf(NULL, 0, message, args); out = o_malloc((out_len + 1)*sizeof(char)); if (out != NULL) { vsnprintf(out, (out_len + 1), message, args_cpy); y_write_log(NULL, Y_LOG_MODE_CURRENT, Y_LOG_LEVEL_CURRENT, NULL, NULL, NULL, NULL, Y_SPLIT_CURRENT, level, out); o_free(out); } va_end(args); va_end(args_cpy); } yder-1.4.20/test/000077500000000000000000000000001450142014400135135ustar00rootroot00000000000000yder-1.4.20/test/.gitignore000066400000000000000000000000311450142014400154750ustar00rootroot00000000000000yder_test valgrind-*.txt yder-1.4.20/test/Makefile000066400000000000000000000020151450142014400151510ustar00rootroot00000000000000# # Public domain, no copyright. Use at your own risk. # CC=gcc CFLAGS+=-Wall -D_REENTRANT -DDEBUG -g -O0 -I$(INCLUDE_LOCATION) $(CPPFLAGS) YDER_LOCATION=../src INCLUDE_LOCATION=../include LDFLAGS=-lc -lorcania -lyder $(shell pkg-config --libs check) -L$(YDER_LOCATION) TARGET=yder_test VALGRIND_COMMAND=valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all VERBOSE=0 MEMCHECK=0 all: test clean: rm -f *.o $(TARGET) *.log valgrind-*.txt $(YDER_LIBRARY): $(YDER_LOCATION)/yder.c cd $(YDER_LOCATION) && $(MAKE) debug $* %: $(YDER_LIBRARY) %.c $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) test: $(YDER_LIBRARY) $(TARGET) test_yder_test check: test test_%: % $(YDER_LIBRARY) @if [ "$(VERBOSE)" = "0" ] && [ "$(MEMCHECK)" = "0" ]; then \ LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./run_test.sh ./$^; \ elif [ "$(MEMCHECK)" = "0" ]; then \ LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./$^ ; \ else \ LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} $(VALGRIND_COMMAND) ./$^ 2>valgrind-$@.txt; \ fi yder-1.4.20/test/run_test.sh000077500000000000000000000005751450142014400157240ustar00rootroot00000000000000#!/bin/bash printf_new() { str=$1 num=$2 v=$(printf "%-${num}s" "$str") printf "${v// / }" } RED='\033[0;31m' GREEN='\033[0;32m' NC='\033[0m' # No Color COMMAND=$1 CHRLEN=${#COMMAND} NBSP=$((32-$CHRLEN)) printf "Run $1" printf_new " " $NBSP $1 $2 $3 $4 $5 $6 $7 $8 $9 1>$1.log 2>&1 if [ $? -ne 0 ] then printf "${RED}FAIL${NC}\n" else printf "${GREEN}SUCCESS${NC}\n" fi yder-1.4.20/test/yder_test.c000066400000000000000000000234671450142014400156750ustar00rootroot00000000000000/* Public domain, no copyright. Use at your own risk. */ #include #include #include #include #include #include #include #include "yder.h" char message[1024]; char app_name[128]; int level; void unit_test_callback(void * cls, const char * log_app_name, const time_t date, const unsigned long log_level, const char * log_message) { strcpy(app_name, log_app_name); strcpy(cls, log_message); level = log_level; } void unit_test_newline(void * cls, const char * log_app_name, const time_t date, const unsigned long log_level, const char * log_message) { int * count = (int *)cls; ck_assert_int_gt(o_strlen(log_message), 0); (*count)++; } START_TEST(test_yder_init_console) { ck_assert_int_eq(y_init_logs("test_yder_console", Y_LOG_MODE_CONSOLE, Y_LOG_LEVEL_DEBUG, NULL, "first test"), 1); y_close_logs(); } END_TEST START_TEST(test_yder_init_file) { ck_assert_int_eq(y_init_logs("test_yder_file", Y_LOG_MODE_FILE, Y_LOG_LEVEL_DEBUG, "/tmp/test.log", "second test"), 1); y_close_logs(); } END_TEST START_TEST(test_yder_init_syslog) { #ifndef _WIN32 ck_assert_int_eq(y_init_logs("test_yder_syslog", Y_LOG_MODE_SYSLOG, Y_LOG_LEVEL_DEBUG, NULL, "third test"), 1); y_close_logs(); #else ck_assert_int_eq(y_init_logs("test_yder_syslog", Y_LOG_MODE_SYSLOG, Y_LOG_LEVEL_DEBUG, NULL, "third test"), 0); #endif } END_TEST START_TEST(test_yder_init_journald) { #if !defined(_WIN32) && !defined(Y_DISABLE_JOURNALD) ck_assert_int_eq(y_init_logs("test_yder_journald", Y_LOG_MODE_JOURNALD, Y_LOG_LEVEL_DEBUG, NULL, "fourth test"), 1); y_close_logs(); #else ck_assert_int_eq(y_init_logs("test_yder_journald", Y_LOG_MODE_JOURNALD, Y_LOG_LEVEL_DEBUG, NULL, "fourth test"), 0); #endif } END_TEST START_TEST(test_yder_init_error_file) { ck_assert_int_eq(y_init_logs("test_yder_file_fail", Y_LOG_MODE_FILE, Y_LOG_LEVEL_DEBUG, "/nope/nope", "second test"), 0); ck_assert_int_eq(y_init_logs("test_yder_file_fail", Y_LOG_MODE_FILE, Y_LOG_LEVEL_DEBUG, "", "second test"), 0); ck_assert_int_eq(y_init_logs("test_yder_file_fail", Y_LOG_MODE_FILE, Y_LOG_LEVEL_DEBUG, NULL, "second test"), 0); } END_TEST START_TEST(test_yder_callback) { message[0] = '\0'; app_name[0] = '\0'; ck_assert_int_eq(y_init_logs("test_yder_callback", Y_LOG_MODE_CALLBACK, Y_LOG_LEVEL_DEBUG, NULL, "test_yder_callback"), 1); ck_assert_int_eq(y_set_logs_callback(NULL, NULL, NULL), 0); level = Y_LOG_LEVEL_NONE; ck_assert_int_eq(y_set_logs_callback(&unit_test_callback, message, "Start callback unit tests"), 1); ck_assert_str_eq(message, "Start callback unit tests"); ck_assert_str_eq(app_name, "test_yder_callback"); ck_assert_int_eq(level, Y_LOG_LEVEL_INFO); message[0] = '\0'; app_name[0] = '\0'; level = Y_LOG_LEVEL_NONE; y_log_message(Y_LOG_LEVEL_DEBUG, "first test"); ck_assert_str_eq(message, "first test"); ck_assert_str_eq(app_name, "test_yder_callback"); ck_assert_int_eq(level, Y_LOG_LEVEL_DEBUG); message[0] = '\0'; app_name[0] = '\0'; level = Y_LOG_LEVEL_NONE; y_log_message(Y_LOG_LEVEL_DEBUG, "second test with parameter: %d", 42); ck_assert_str_eq(message, "second test with parameter: 42"); ck_assert_str_eq(app_name, "test_yder_callback"); ck_assert_int_eq(level, Y_LOG_LEVEL_DEBUG); y_close_logs(); } END_TEST START_TEST(test_yder_init_multiple_error) { ck_assert_int_eq(y_init_logs("test_yder_console", Y_LOG_MODE_CONSOLE, Y_LOG_LEVEL_DEBUG, NULL, "first test"), 1); ck_assert_int_eq(y_init_logs("test_yder_console", Y_LOG_MODE_CONSOLE, Y_LOG_LEVEL_DEBUG, NULL, "first test"), 0); y_close_logs(); } END_TEST START_TEST(test_yder_init_multiple_ok) { ck_assert_int_eq(y_init_logs("test_yder_console", Y_LOG_MODE_CONSOLE, Y_LOG_LEVEL_DEBUG, NULL, "first test"), 1); ck_assert_int_eq(y_close_logs(), 1); ck_assert_int_eq(y_init_logs("test_yder_console", Y_LOG_MODE_CONSOLE, Y_LOG_LEVEL_DEBUG, NULL, "first test"), 1); ck_assert_int_eq(y_close_logs(), 1); } END_TEST START_TEST(test_yder_init_close_multiple) { ck_assert_int_eq(y_close_logs(), 1); ck_assert_int_eq(y_init_logs("test_yder_console", Y_LOG_MODE_CONSOLE, Y_LOG_LEVEL_DEBUG, NULL, "first test"), 1); ck_assert_int_eq(y_close_logs(), 1); ck_assert_int_eq(y_close_logs(), 1); } END_TEST START_TEST(test_yder_level_debug) { ck_assert_int_eq(y_init_logs("test_yder_level_debug", Y_LOG_MODE_CALLBACK, Y_LOG_LEVEL_DEBUG, NULL, "test_yder_level_debug"), 1); ck_assert_int_eq(y_set_logs_callback(&unit_test_callback, message, "Start callback unit tests"), 1); message[0] = '\0'; y_log_message(Y_LOG_LEVEL_DEBUG, "first test"); ck_assert_str_eq(message, "first test"); message[0] = '\0'; y_log_message(Y_LOG_LEVEL_INFO, "second test"); ck_assert_str_eq(message, "second test"); message[0] = '\0'; y_log_message(Y_LOG_LEVEL_WARNING, "third test"); ck_assert_str_eq(message, "third test"); message[0] = '\0'; y_log_message(Y_LOG_LEVEL_ERROR, "fourth test"); ck_assert_str_eq(message, "fourth test"); y_close_logs(); } END_TEST START_TEST(test_yder_level_info) { ck_assert_int_eq(y_init_logs("test_yder_level_info", Y_LOG_MODE_CALLBACK, Y_LOG_LEVEL_INFO, NULL, "test_yder_level_info"), 1); ck_assert_int_eq(y_set_logs_callback(&unit_test_callback, message, "Start callback unit tests"), 1); message[0] = '\0'; y_log_message(Y_LOG_LEVEL_DEBUG, "first test"); ck_assert_str_eq(message, ""); message[0] = '\0'; y_log_message(Y_LOG_LEVEL_INFO, "second test"); ck_assert_str_eq(message, "second test"); message[0] = '\0'; y_log_message(Y_LOG_LEVEL_WARNING, "third test"); ck_assert_str_eq(message, "third test"); message[0] = '\0'; y_log_message(Y_LOG_LEVEL_ERROR, "fourth test"); ck_assert_str_eq(message, "fourth test"); y_close_logs(); } END_TEST START_TEST(test_yder_level_warning) { ck_assert_int_eq(y_init_logs("test_yder_level_warning", Y_LOG_MODE_CALLBACK, Y_LOG_LEVEL_WARNING, NULL, "test_yder_level_warning"), 1); ck_assert_int_eq(y_set_logs_callback(&unit_test_callback, message, "Start callback unit tests"), 1); message[0] = '\0'; y_log_message(Y_LOG_LEVEL_DEBUG, "first test"); ck_assert_str_eq(message, ""); message[0] = '\0'; y_log_message(Y_LOG_LEVEL_INFO, "second test"); ck_assert_str_eq(message, ""); message[0] = '\0'; y_log_message(Y_LOG_LEVEL_WARNING, "third test"); ck_assert_str_eq(message, "third test"); message[0] = '\0'; y_log_message(Y_LOG_LEVEL_ERROR, "fourth test"); ck_assert_str_eq(message, "fourth test"); y_close_logs(); } END_TEST START_TEST(test_yder_level_error) { ck_assert_int_eq(y_init_logs("test_yder_level_error", Y_LOG_MODE_CALLBACK, Y_LOG_LEVEL_ERROR, NULL, "test_yder_level_error"), 1); ck_assert_int_eq(y_set_logs_callback(&unit_test_callback, message, "Start callback unit tests"), 1); message[0] = '\0'; y_log_message(Y_LOG_LEVEL_DEBUG, "first test"); ck_assert_str_eq(message, ""); message[0] = '\0'; y_log_message(Y_LOG_LEVEL_INFO, "second test"); ck_assert_str_eq(message, ""); message[0] = '\0'; y_log_message(Y_LOG_LEVEL_WARNING, "third test"); ck_assert_str_eq(message, ""); message[0] = '\0'; y_log_message(Y_LOG_LEVEL_ERROR, "fourth test"); ck_assert_str_eq(message, "fourth test"); y_close_logs(); } END_TEST START_TEST(test_yder_date_format) { ck_assert_int_eq(y_init_logs("test_yder_date_format", Y_LOG_MODE_CONSOLE, Y_LOG_LEVEL_DEBUG, NULL, "date format test"), 1); ck_assert_int_eq(y_set_date_format(NULL, "error"), 0); ck_assert_int_eq(y_set_date_format("TEST %Y - :%S", "success"), 1); y_log_message(Y_LOG_LEVEL_DEBUG, "first test"); y_close_logs(); } END_TEST START_TEST(test_yder_newline_split) { int count = 0; ck_assert_int_eq(y_init_logs("test_yder_newline_split", Y_LOG_MODE_CALLBACK, Y_LOG_LEVEL_DEBUG, NULL, "yder_newline_split"), 1); ck_assert_int_eq(y_set_logs_callback(&unit_test_newline, &count, "Start newline unit tests"), 1); ck_assert_int_eq(y_set_split_message_newline(1, "Set newline"), 1); count = 0; y_log_message(Y_LOG_LEVEL_DEBUG, "first test, one line"); ck_assert_int_eq(count, 1); count = 0; y_log_message(Y_LOG_LEVEL_DEBUG, "second test\ntwo lines"); ck_assert_int_eq(count, 2); count = 0; y_log_message(Y_LOG_LEVEL_DEBUG, "third test\nfour\nlines\nahead"); ck_assert_int_eq(count, 4); y_close_logs(); } END_TEST static Suite *yder_suite(void) { Suite *s; TCase *tc_core; s = suite_create("Yder tests functions"); tc_core = tcase_create("test_yder"); tcase_add_test(tc_core, test_yder_init_console); tcase_add_test(tc_core, test_yder_init_file); tcase_add_test(tc_core, test_yder_init_syslog); tcase_add_test(tc_core, test_yder_init_journald); tcase_add_test(tc_core, test_yder_init_error_file); tcase_add_test(tc_core, test_yder_init_multiple_error); tcase_add_test(tc_core, test_yder_init_multiple_ok); tcase_add_test(tc_core, test_yder_init_close_multiple); tcase_add_test(tc_core, test_yder_callback); tcase_add_test(tc_core, test_yder_level_debug); tcase_add_test(tc_core, test_yder_level_info); tcase_add_test(tc_core, test_yder_level_warning); tcase_add_test(tc_core, test_yder_level_error); tcase_add_test(tc_core, test_yder_date_format); tcase_add_test(tc_core, test_yder_newline_split); tcase_set_timeout(tc_core, 30); suite_add_tcase(s, tc_core); return s; } int main(int argc, char *argv[]) { int number_failed; Suite *s; SRunner *sr; s = yder_suite(); sr = srunner_create(s); srunner_run_all(sr, CK_VERBOSE); number_failed = srunner_ntests_failed(sr); srunner_free(sr); return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; }