pax_global_header00006660000000000000000000000064133651277030014521gustar00rootroot0000000000000052 comment=c64f1e3ec982c5e99a7ac3717327a96ec41371e7 yder-1.4.4/000077500000000000000000000000001336512770300124725ustar00rootroot00000000000000yder-1.4.4/.gitignore000066400000000000000000000001671336512770300144660ustar00rootroot00000000000000*.o *.so *.so.*.* *.a log_combined log_console log_file log_syslog log_journald test/yder_test valgrind.txt yder-cfg.h yder-1.4.4/.travis.yml000066400000000000000000000012721336512770300146050ustar00rootroot00000000000000# travis configuration file # Copyright 2018 Ilya Shipitsin # Nicolas Mora sudo: required language: c addons: apt: packages: [ libjansson-dev, check, libsubunit-dev, cppcheck ] matrix: include: - os: linux compiler: gcc - os: linux compiler: clang - env: LABEL=cppcheck os: linux script: - cppcheck --force --enable=warning,missingInclude --error-exitcode=1 . >build.log 2>&1 || (cat build.log && exit 1) script: - mkdir build && cd build - cmake -DBUILD_YDER_TESTING=on -DWITH_JOURNALD=off .. - make test package - sudo make install - cd ../src - make Y_DISABLE_JOURNALD=1 yder-1.4.4/CHANGELOG.md000066400000000000000000000015311336512770300143030ustar00rootroot00000000000000# Yder Changelog ## 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.4/CMakeLists.txt000066400000000000000000000215351336512770300152400ustar00rootroot00000000000000# # Yder library # # CMake file used to build all programs # # 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 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) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror") # 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 "4") set(PROJECT_VERSION "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}") set(LIBRARY_VERSION "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}") set(LIBRARY_SOVERSION "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}") set(ORCANIA_VERSION_DOWNLOAD "1.2.8") # cmake modules set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules) include(GNUInstallDirs) include(CheckSymbolExists) # 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 option(WITH_JOURNALD "Check journald." ON) if (WITH_JOURNALD) include(FindSystemd) find_package(Systemd REQUIRED) if (SYSTEMD_FOUND) set(SYSTEMD_LIBRARIES systemd) include_directories(${SYSTEMD_INCLUDE_DIRS}) set(DISABLE_JOURNALD OFF) endif () else() add_definitions(-DY_DISABLE_JOURNALD) set(DISABLE_JOURNALD ON) endif () # shared library add_library(yder SHARED ${LIB_SRC}) set_target_properties(yder PROPERTIES COMPILE_OPTIONS -Wextra PUBLIC_HEADER "${INC_DIR}/yder.h;${PROJECT_BINARY_DIR}/yder-cfg.h" VERSION "${LIBRARY_VERSION}" SOVERSION "${LIBRARY_SOVERSION}") if (WIN32) set_target_properties(yder PROPERTIES SUFFIX "-${LIBRARY_VERSION_MAJOR}.dll") endif () target_link_libraries(yder ${LIBS} ${ORCANIA_LIBRARIES} ${SYSTEMD_LIBRARIES}) # static library option(BUILD_STATIC "Build static library." OFF) if (BUILD_STATIC) add_library(yder_static STATIC ${LIB_SRC}) target_compile_definitions(yder_static PUBLIC -DO_STATIC_LIBRARY) set_target_properties(yder_static PROPERTIES OUTPUT_NAME yder) endif () option (SEARCH_ORCANIA "Search for Orcania library" ON) if (SEARCH_ORCANIA) set(Orcania_FIND_QUIETLY ON) # force to find Orcania quietly include(FindOrcania) find_package(Orcania 1.1 QUIET) # try to find orcania if (NOT ORCANIA_FOUND) include(DownloadProject) download_project(PROJ orcania # ... otherwise, download archive URL "https://github.com/babelouest/orcania/archive/v${ORCANIA_VERSION_DOWNLOAD}.tar.gz" QUIET) add_subdirectory(${orcania_SOURCE_DIR} ${orcania_BINARY_DIR}) include_directories(${orcania_SOURCE_DIR}/include) include_directories(${orcania_BINARY_DIR}) add_dependencies(yder orcania) set(ORCANIA_LIBRARIES orcania) set(LIBS ${LIBS} ${ORCANIA_LIBRARIES}) else() set(LIBS ${LIBS} ${ORCANIA_LIBRARIES}) include_directories(${ORCANIA_INCLUDE_DIRS}) include_directories(${orcania_BINARY_DIR}) endif () endif () if (WITH_JOURNALD) set(PKGCONF_REQ "") set(PKGCONF_REQ_PRIVATE "libsystemd, liborcania") else () set(PKGCONF_REQ "") set(PKGCONF_REQ_PRIVATE "liborcania") 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) include(FindCheck) find_package(Check) if (CHECK_FOUND) if (NOT WIN32) include(FindSubunit) find_package(Subunit REQUIRED) endif () enable_testing() set(CMAKE_CTEST_COMMAND ctest -V) set(TST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test) set(LIBS yder ${LIBS} ${CHECK_LIBRARIES}) if (NOT WIN32) find_package(Threads REQUIRED) set(LIBS ${LIBS} ${SUBUNIT_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} m rt) endif () set(TESTS yder_test) configure_file( "${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} PUBLIC ${TST_DIR}) target_link_libraries(${t} PUBLIC ${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 configure_file(libyder.pc.in libyder.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libyder.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) set(TARGETS yder) if (BUILD_STATIC) set(TARGETS ${TARGETS} yder_static) endif () if (INSTALL_HEADER) install(TARGETS ${TARGETS} 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} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif () # uninstall target if (NOT TARGET uninstall) configure_file( "${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 (>= 1.2)") if (WITH_SYSTEMD) set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, libsystemd0") 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 static library: ${BUILD_STATIC}") message(STATUS "Build testing tree: ${BUILD_ULFIUS_TESTING}") message(STATUS "Install the header files: ${INSTALL_HEADER}") message(STATUS "Build RPM package: ${BUILD_RPM}") yder-1.4.4/LICENSE000066400000000000000000000635361336512770300135140ustar00rootroot00000000000000 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.4/Makefile000066400000000000000000000021541336512770300141340ustar00rootroot00000000000000# # Example program # # Makefile used to build all programs # # Copyright 2014-2018 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. # LIBYDER_LOCATION=./src EXAMPLE_LOCATION=./examples TEST_LOCATION=./test all: libyder.so 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 run_test: cd $(TEST_LOCATION) && $(MAKE) test libyder.so: 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 yder-1.4.4/README.md000066400000000000000000000155021336512770300137540ustar00rootroot00000000000000# Yder Logging library written in C. [![Build Status](https://travis-ci.com/babelouest/yder.svg?branch=master)](https://travis-ci.com/babelouest/yder) Simple and easy to use logging library. You can log messages to the console, a file, syslog or journald. Yder is mono-thread, which mean that you can use only one instance of yder log at the same time in your program. # 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 [liborcania](https://github.com/babelouest/orcania) first before building libyder. 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 subdirectory, example: ```shell $ git clone https://github.com/babelouest/yder.git $ cd yder/ $ 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 - `-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. ```shell $ git clone https://github.com/babelouest/yder.git $ 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 libyder as a static archive Install byderlibrary 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.4/cmake-modules/000077500000000000000000000000001336512770300152205ustar00rootroot00000000000000yder-1.4.4/cmake-modules/CMakeUninstall.cmake.in000066400000000000000000000020641336512770300215030ustar00rootroot00000000000000if (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.4/cmake-modules/CTestCustom.cmake.in000066400000000000000000000001421336512770300210410ustar00rootroot00000000000000string(REPLACE ";" " " TESTS "@TESTS@") set(CTEST_CUSTOM_PRE_TEST "@CMAKE_MAKE_PROGRAM@ ${TESTS}")yder-1.4.4/cmake-modules/DownloadProject.CMakeLists.cmake.in000066400000000000000000000012041336512770300237200ustar00rootroot00000000000000# Distributed under the OSI-approved MIT License. See accompanying # file LICENSE or https://github.com/Crascit/DownloadProject for details. cmake_minimum_required(VERSION 2.8.2) project(${DL_ARGS_PROJ}-download NONE) include(ExternalProject) ExternalProject_Add(${DL_ARGS_PROJ}-download ${DL_ARGS_UNPARSED_ARGUMENTS} SOURCE_DIR "${DL_ARGS_SOURCE_DIR}" BINARY_DIR "${DL_ARGS_BINARY_DIR}" CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" TEST_COMMAND "" ) yder-1.4.4/cmake-modules/DownloadProject.cmake000066400000000000000000000175531336512770300213330ustar00rootroot00000000000000# Distributed under the OSI-approved MIT License. See accompanying # file LICENSE or https://github.com/Crascit/DownloadProject for details. # # MODULE: DownloadProject # # PROVIDES: # download_project( PROJ projectName # [PREFIX prefixDir] # [DOWNLOAD_DIR downloadDir] # [SOURCE_DIR srcDir] # [BINARY_DIR binDir] # [QUIET] # ... # ) # # Provides the ability to download and unpack a tarball, zip file, git repository, # etc. at configure time (i.e. when the cmake command is run). How the downloaded # and unpacked contents are used is up to the caller, but the motivating case is # to download source code which can then be included directly in the build with # add_subdirectory() after the call to download_project(). Source and build # directories are set up with this in mind. # # The PROJ argument is required. The projectName value will be used to construct # the following variables upon exit (obviously replace projectName with its actual # value): # # projectName_SOURCE_DIR # projectName_BINARY_DIR # # The SOURCE_DIR and BINARY_DIR arguments are optional and would not typically # need to be provided. They can be specified if you want the downloaded source # and build directories to be located in a specific place. The contents of # projectName_SOURCE_DIR and projectName_BINARY_DIR will be populated with the # locations used whether you provide SOURCE_DIR/BINARY_DIR or not. # # The DOWNLOAD_DIR argument does not normally need to be set. It controls the # location of the temporary CMake build used to perform the download. # # The PREFIX argument can be provided to change the base location of the default # values of DOWNLOAD_DIR, SOURCE_DIR and BINARY_DIR. If all of those three arguments # are provided, then PREFIX will have no effect. The default value for PREFIX is # CMAKE_BINARY_DIR. # # The QUIET option can be given if you do not want to show the output associated # with downloading the specified project. # # In addition to the above, any other options are passed through unmodified to # ExternalProject_Add() to perform the actual download, patch and update steps. # The following ExternalProject_Add() options are explicitly prohibited (they # are reserved for use by the download_project() command): # # CONFIGURE_COMMAND # BUILD_COMMAND # INSTALL_COMMAND # TEST_COMMAND # # Only those ExternalProject_Add() arguments which relate to downloading, patching # and updating of the project sources are intended to be used. Also note that at # least one set of download-related arguments are required. # # If using CMake 3.2 or later, the UPDATE_DISCONNECTED option can be used to # prevent a check at the remote end for changes every time CMake is run # after the first successful download. See the documentation of the ExternalProject # module for more information. It is likely you will want to use this option if it # is available to you. Note, however, that the ExternalProject implementation contains # bugs which result in incorrect handling of the UPDATE_DISCONNECTED option when # using the URL download method or when specifying a SOURCE_DIR with no download # method. Fixes for these have been created, the last of which is scheduled for # inclusion in CMake 3.8.0. Details can be found here: # # https://gitlab.kitware.com/cmake/cmake/commit/bdca68388bd57f8302d3c1d83d691034b7ffa70c # https://gitlab.kitware.com/cmake/cmake/issues/16428 # # If you experience build errors related to the update step, consider avoiding # the use of UPDATE_DISCONNECTED. # # EXAMPLE USAGE: # # include(DownloadProject) # download_project(PROJ googletest # GIT_REPOSITORY https://github.com/google/googletest.git # GIT_TAG master # UPDATE_DISCONNECTED 1 # QUIET # ) # # add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR}) # #======================================================================================== set(_DownloadProjectDir "${CMAKE_CURRENT_LIST_DIR}") include(CMakeParseArguments) function(download_project) set(options QUIET) set(oneValueArgs PROJ PREFIX DOWNLOAD_DIR SOURCE_DIR BINARY_DIR # Prevent the following from being passed through CONFIGURE_COMMAND BUILD_COMMAND INSTALL_COMMAND TEST_COMMAND ) set(multiValueArgs "") cmake_parse_arguments(DL_ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) # Hide output if requested if (DL_ARGS_QUIET) set(OUTPUT_QUIET "OUTPUT_QUIET") else() unset(OUTPUT_QUIET) message(STATUS "Downloading/updating ${DL_ARGS_PROJ}") endif() # Set up where we will put our temporary CMakeLists.txt file and also # the base point below which the default source and binary dirs will be. # The prefix must always be an absolute path. if (NOT DL_ARGS_PREFIX) set(DL_ARGS_PREFIX "${CMAKE_BINARY_DIR}") else() get_filename_component(DL_ARGS_PREFIX "${DL_ARGS_PREFIX}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}") endif() if (NOT DL_ARGS_DOWNLOAD_DIR) set(DL_ARGS_DOWNLOAD_DIR "${DL_ARGS_PREFIX}/${DL_ARGS_PROJ}-download") endif() # Ensure the caller can know where to find the source and build directories if (NOT DL_ARGS_SOURCE_DIR) set(DL_ARGS_SOURCE_DIR "${DL_ARGS_PREFIX}/${DL_ARGS_PROJ}-src") endif() if (NOT DL_ARGS_BINARY_DIR) set(DL_ARGS_BINARY_DIR "${DL_ARGS_PREFIX}/${DL_ARGS_PROJ}-build") endif() set(${DL_ARGS_PROJ}_SOURCE_DIR "${DL_ARGS_SOURCE_DIR}" PARENT_SCOPE) set(${DL_ARGS_PROJ}_BINARY_DIR "${DL_ARGS_BINARY_DIR}" PARENT_SCOPE) # The way that CLion manages multiple configurations, it causes a copy of # the CMakeCache.txt to be copied across due to it not expecting there to # be a project within a project. This causes the hard-coded paths in the # cache to be copied and builds to fail. To mitigate this, we simply # remove the cache if it exists before we configure the new project. It # is safe to do so because it will be re-generated. Since this is only # executed at the configure step, it should not cause additional builds or # downloads. file(REMOVE "${DL_ARGS_DOWNLOAD_DIR}/CMakeCache.txt") # Create and build a separate CMake project to carry out the download. # If we've already previously done these steps, they will not cause # anything to be updated, so extra rebuilds of the project won't occur. # Make sure to pass through CMAKE_MAKE_PROGRAM in case the main project # has this set to something not findable on the PATH. configure_file("${_DownloadProjectDir}/DownloadProject.CMakeLists.cmake.in" "${DL_ARGS_DOWNLOAD_DIR}/CMakeLists.txt") execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" -D "CMAKE_MAKE_PROGRAM:FILE=${CMAKE_MAKE_PROGRAM}" . RESULT_VARIABLE result ${OUTPUT_QUIET} WORKING_DIRECTORY "${DL_ARGS_DOWNLOAD_DIR}" ) if(result) message(FATAL_ERROR "CMake step for ${DL_ARGS_PROJ} failed: ${result}") endif() execute_process(COMMAND ${CMAKE_COMMAND} --build . RESULT_VARIABLE result ${OUTPUT_QUIET} WORKING_DIRECTORY "${DL_ARGS_DOWNLOAD_DIR}" ) if(result) message(FATAL_ERROR "Build step for ${DL_ARGS_PROJ} failed: ${result}") endif() endfunction() yder-1.4.4/cmake-modules/FindCheck.cmake000066400000000000000000000050411336512770300200400ustar00rootroot00000000000000#.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}) endif () mark_as_advanced(CHECK_INCLUDE_DIR CHECK_LIBRARY)yder-1.4.4/cmake-modules/FindOrcania.cmake000066400000000000000000000054351336512770300204060ustar00rootroot00000000000000#.rst: # FindOrcania # ----------- # # Find Orcania # # Find Orcania headers and libraries. # # :: # # ORCANIA_FOUND - True if Orcania found. # ORCANIA_INCLUDE_DIRS - Where to find orcania.h. # ORCANIA_LIBRARIES - List of libraries when using Orcania. # ORCANIA_VERSION_STRING - The version of Orcania found. #============================================================================= # 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 . #============================================================================= find_package(PkgConfig QUIET) pkg_check_modules(PC_ORCANIA QUIET liborcania) find_path(ORCANIA_INCLUDE_DIR NAMES orcania.h HINTS ${PC_ORCANIA_INCLUDEDIR} ${PC_ORCANIA_INCLUDE_DIRS}) find_library(ORCANIA_LIBRARY NAMES orcania liborcania HINTS ${PC_ORCANIA_LIBDIR} ${PC_ORCANIA_LIBRARY_DIRS}) set(ORCANIA_VERSION_STRING 0.0.0) if (PC_ORCANIA_VERSION) set(ORCANIA_VERSION_STRING ${PC_ORCANIA_VERSION}) elseif (ORCANIA_INCLUDE_DIR AND EXISTS "${ORCANIA_INCLUDE_DIR}/orcania.h") set(regex_orcania_version "^#define[ \t]+ORCANIA_VERSION[ \t]+([^\"]+).*") file(STRINGS "${ORCANIA_INCLUDE_DIR}/orcania.h" orcania_version REGEX "${regex_orcania_version}") string(REGEX REPLACE "${regex_orcania_version}" "\\1" ORCANIA_VERSION_STRING "${orcania_version}") unset(regex_orcania_version) unset(orcania_version) if (NOT ORCANIA_VERSION_STRING) set(regex_orcania_version "^#define[ \t]+ORCANIA_VERSION[ \t]+([^\"]+).*") file(STRINGS "${ORCANIA_INCLUDE_DIR}/orcania-cfg.h" orcania_version REGEX "${regex_orcania_version}") string(REGEX REPLACE "${regex_orcania_version}" "\\1" ORCANIA_VERSION_STRING "${orcania_version}") unset(regex_orcania_version) unset(orcania_version) endif () endif () include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Orcania REQUIRED_VARS ORCANIA_LIBRARY ORCANIA_INCLUDE_DIR VERSION_VAR ORCANIA_VERSION_STRING) if (ORCANIA_FOUND) set(ORCANIA_LIBRARIES ${ORCANIA_LIBRARY}) set(ORCANIA_INCLUDE_DIRS ${ORCANIA_INCLUDE_DIR}) endif () mark_as_advanced(ORCANIA_INCLUDE_DIR ORCANIA_LIBRARY) yder-1.4.4/cmake-modules/FindSubunit.cmake000066400000000000000000000036421336512770300204610ustar00rootroot00000000000000#.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}) endif () mark_as_advanced(SUBUNIT_INCLUDE_DIR SUBUNIT_LIBRARY)yder-1.4.4/cmake-modules/FindSystemd.cmake000066400000000000000000000034411336512770300204550ustar00rootroot00000000000000#.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}) endif () mark_as_advanced(SYSTEMD_INCLUDE_DIR SYSTEMD_LIBRARY) yder-1.4.4/examples/000077500000000000000000000000001336512770300143105ustar00rootroot00000000000000yder-1.4.4/examples/Makefile000066400000000000000000000112271336512770300157530ustar00rootroot00000000000000# # Example program # # Makefile used to build the software # # Copyright 2014-2015 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 ifndef Y_DISABLE_JOURNALD TARGET+= log_journald endif all: libyder.so $(TARGET) clean: rm -f *.o log_console log_syslog log_file log_combined log_journald log_callback 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) 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 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 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 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 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 endif yder-1.4.4/examples/log_callback.c000066400000000000000000000052761336512770300170630ustar00rootroot00000000000000#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.4/examples/log_combined.c000066400000000000000000000027761336512770300171110ustar00rootroot00000000000000#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.4/examples/log_console.c000066400000000000000000000027051336512770300167630ustar00rootroot00000000000000#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.4/examples/log_file.c000066400000000000000000000024661336512770300162440ustar00rootroot00000000000000#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: console, 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: console, 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: console, 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: console, logs level: debug")) { write_logs("debug"); y_close_logs(); } return 0; } yder-1.4.4/examples/log_journald.c000066400000000000000000000024641336512770300171410ustar00rootroot00000000000000#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: console, 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: console, 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: console, 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: console, logs level: debug")) { write_logs("debug"); y_close_logs(); } return 0; } yder-1.4.4/examples/log_syslog.c000066400000000000000000000023511336512770300166360ustar00rootroot00000000000000#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: console, 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: console, 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: console, 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: console, logs level: debug")) { write_logs("debug"); y_close_logs(); } return 0; } yder-1.4.4/include/000077500000000000000000000000001336512770300141155ustar00rootroot00000000000000yder-1.4.4/include/yder-cfg.h.in000066400000000000000000000016231336512770300163750ustar00rootroot00000000000000/** * * Yder Framework * * Logging framework library * * yder-cfg.h: configuration file * * 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 . * */ #ifndef _YDER_CFG_H_ #define _YDER_CFG_H_ #define YDER_VERSION ${PROJECT_VERSION} #cmakedefine DISABLE_JOURNALD #endif /* _YDER_CFG_H_ */ yder-1.4.4/include/yder.h000066400000000000000000000042531336512770300152350ustar00rootroot00000000000000/** * * Yder Framework * * Logging framework library * * yder.h: structures and functions declarations * * Copyright 2015-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 . * */ #ifndef __YDER_H__ #define __YDER_H__ #include "yder-cfg.h" #include #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 /** * 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); /** * 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); /** * Close the logs */ int y_close_logs(); /** * Log a message using current parameters */ void y_log_message(const unsigned long type, const char * message, ...); #endif // __YDER_H__ yder-1.4.4/libyder.pc.in000066400000000000000000000006021336512770300150530ustar00rootroot00000000000000prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=@CMAKE_INSTALL_PREFIX@ libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ 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 Cflags: -I${includedir} yder-1.4.4/src/000077500000000000000000000000001336512770300132615ustar00rootroot00000000000000yder-1.4.4/src/Makefile000066400000000000000000000051451336512770300147260ustar00rootroot00000000000000# # Yder Framework # # Makefile used to build the software # # Copyright 2015-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 . # DESTDIR=/usr/local YDER_INCLUDE=../include CONFIG_TEMPLATE=$(YDER_INCLUDE)/yder-cfg.h.in CONFIG_FILE=$(YDER_INCLUDE)/yder-cfg.h CC=gcc CFLAGS+=-c -fPIC -Wall -D_REENTRANT -I$(YDER_INCLUDE) $(ADDITIONALFLAGS) $(CPPFLAGS) LIBS=-lc -lorcania $(ADDITIONALLIBS) OUTPUT=libyder.so VERSION=1.4.4 ifndef Y_DISABLE_JOURNALD DISABLE_JOURNALD=0 LIBS+=-lsystemd else DISABLE_JOURNALD=1 endif all: release $(CONFIG_FILE): @cp $(CONFIG_TEMPLATE) $(CONFIG_FILE) @sed -i -e 's/$${PROJECT_VERSION}/$(VERSION)/g' $(CONFIG_FILE) @if [ "$(DISABLE_JOURNALD)" = "1" ]; then \ sed -i -e 's/\#cmakedefine DISABLE_JOURNALD/\#define Y_DISABLE_JOURNALD/g' $(CONFIG_FILE); \ else \ sed -i -e 's/\#cmakedefine DISABLE_JOURNALD/\/* #undef Y_DISABLE_JOURNALD *\//g' $(CONFIG_FILE); \ fi @echo Config file $(CONFIG_FILE) generated libyder.so: $(CONFIG_FILE) yder.o $(CC) -shared -fPIC -Wl,-soname,$(OUTPUT) -o $(OUTPUT).$(VERSION) yder.o $(LIBS) $(LDFLAGS) ln -sf $(OUTPUT).$(VERSION) $(OUTPUT) libyder.a: $(CONFIG_FILE) yder.o ar rcs libyder.a yder.o yder.o: $(YDER_INCLUDE)/yder.h yder.c $(CC) $(CFLAGS) $(CPPFLAGS) yder.c clean: rm -f *.o *.so *.a $(OUTPUT) $(OUTPUT).* $(YDER_INCLUDE)/yder-cfg.h install: all install $(OUTPUT).$(VERSION) $(DESTDIR)/lib install -m644 $(YDER_INCLUDE)/yder.h $(DESTDIR)/include install -m644 $(CONFIG_FILE) $(DESTDIR)/include -ldconfig static-install: static install libyder.a $(DESTDIR)/lib 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/yder-cfg.h 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 yder-1.4.4/src/yder.c000066400000000000000000000224251336512770300143750ustar00rootroot00000000000000/** * * Yder Framework * * Logging framework library * * yder.h: structures and functions declarations * * Copyright 2015-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 . * */ #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 time_t date, const unsigned long level, const char * message) { char * level_name = NULL, date_stamp[20]; FILE * output = NULL; 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; } if (level & Y_LOG_LEVEL_WARNING || level & Y_LOG_LEVEL_ERROR) { // Write to stderr output = stderr; } else { // Write to stdout output = stdout; } 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 time_t date, FILE * log_file, const unsigned long level, const char * message) { char * level_name = NULL, date_stamp[20]; struct tm * tm_stamp; if (log_file != NULL) { tm_stamp = localtime (&date); strftime (date_stamp, sizeof(date_stamp), "%Y-%m-%d %H:%M:%S", 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; } 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 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; time_t now; // 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); 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 (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) { cur_log_file_path = init_log_file; } if (app_name != NULL) { cur_app_name = o_strdup(app_name); } if (cur_log_file_path != NULL) { if ((cur_log_file = fopen(cur_log_file_path, "a+")) == NULL) { perror("Error opening log file"); 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, now, level, message); } #ifndef _WIN32 if (cur_mode & Y_LOG_MODE_SYSLOG) { y_write_log_syslog(cur_app_name, level, message); } #ifndef Y_DISABLE_JOURNALD if (cur_mode & Y_LOG_MODE_JOURNALD) { y_write_log_journald(cur_app_name, level, message); } #endif #endif if (cur_mode & Y_LOG_MODE_FILE) { y_write_log_file(cur_app_name, now, cur_log_file, level, message); } if (cur_mode & Y_LOG_MODE_CALLBACK && cur_callback_log_message != NULL) { 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; } /** * Initialize logs */ 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; } else if (init_mode & Y_LOG_MODE_JOURNALD) { perror("journald mode not supported on your architecture"); return 0; } else { return y_write_log(app, init_mode, init_level, init_log_file, NULL, NULL, Y_LOG_LEVEL_INFO, message); } #else return y_write_log(app, init_mode, init_level, init_log_file, NULL, NULL, Y_LOG_LEVEL_INFO, message); #endif } /** * 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) { 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, Y_LOG_LEVEL_INFO, message); } else { return 0; } } /** * Close logs */ int y_close_logs() { return y_write_log(NULL, 0, 0, NULL, NULL, NULL, 0, NULL); } /** * Write the message given in parameters to the current outputs if the current level matches */ 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 = 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, level, out); o_free(out); } va_end(args); va_end(args_cpy); } yder-1.4.4/test/000077500000000000000000000000001336512770300134515ustar00rootroot00000000000000yder-1.4.4/test/Makefile000066400000000000000000000023311336512770300151100ustar00rootroot00000000000000# # Glewlwyd OAuth2 Authorization Server # # Makefile used to build the software # # Copyright 2016 Nicolas Mora # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU GENERAL PUBLIC LICENSE # License as published by the Free Software Foundation; # version 3 of the License. # # This program 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 program. If not, see . # CC=gcc CFLAGS=-Wall -D_REENTRANT -DDEBUG -g -O0 -I$(INCLUDE_LOCATION) YDER_LOCATION=../src INCLUDE_LOCATION=../include LIBS=-lc -lorcania -lyder -lcheck -lpthread -lm -lrt -lsubunit -L$(YDER_LOCATION) all: test clean: rm -f *.o yder_test valgrind.txt libyder.so: cd $(YDER_LOCATION) && $(MAKE) debug yder_test: yder_test.c $(CC) $(CFLAGS) yder_test.c -o yder_test $(LIBS) test_yder_test: libyder.so yder_test -LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./yder_test test: test_yder_test yder-1.4.4/test/yder_test.c000066400000000000000000000144061336512770300156240ustar00rootroot00000000000000/* Public domain, no copyright. Use at your own risk. */ #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; } START_TEST(test_yder_init) { 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(); 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(); 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(); 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(); ck_assert_int_eq(y_init_logs("test_yder_file_fail", Y_LOG_MODE_FILE, Y_LOG_LEVEL_DEBUG, "/nope/nope", "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_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 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); 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_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; }