Hello community, here is the log from the commit of package yder for openSUSE:Factory checked in at 2019-01-08 12:27:25 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/yder (Old) and /work/SRC/openSUSE:Factory/.yder.new.28833 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "yder" Tue Jan 8 12:27:25 2019 rev:3 rq:662498 version:1.4.4 Changes: -------- --- /work/SRC/openSUSE:Factory/yder/yder.changes 2018-08-27 12:58:58.692791882 +0200 +++ /work/SRC/openSUSE:Factory/.yder.new.28833/yder.changes 2019-01-08 12:30:00.324172233 +0100 @@ -1,0 +2,14 @@ +Fri Dec 28 16:07:40 UTC 2018 - [email protected] + +- Update to version 1.4.4 + * Improve build config file and install headers. + * Add config file yder-cfg.h dynamically built with the options. + * Fix a bug about including time.h in the wrong place. + * Add y_init_callback_logs to redirect all logs in a callback + function. +- Remove patch: + * 0001-Fix-pkg-config-information-add-requires-fields-as-me.patch +- Update patch: + * yder-fix-build.patch + +------------------------------------------------------------------- Old: ---- 0001-Fix-pkg-config-information-add-requires-fields-as-me.patch yder-1.3.4.tar.gz New: ---- yder-1.4.4.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ yder.spec ++++++ --- /var/tmp/diff_new_pack.LlNxPY/_old 2019-01-08 12:30:01.672170765 +0100 +++ /var/tmp/diff_new_pack.LlNxPY/_new 2019-01-08 12:30:01.696170738 +0100 @@ -1,6 +1,7 @@ # # spec file for package yder # +# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. # Copyright (c) 2018, Martin Hauke <[email protected]> # # All modifications and additions to the file contributed by third parties @@ -16,22 +17,21 @@ # -%define sover 1_3 +%define sover 1_4 Name: yder -Version: 1.3.4 +Version: 1.4.4 Release: 0 Summary: Logging library written in C -License: LGPL-2.1+ +License: LGPL-2.1-or-later Group: Development/Languages/C and C++ URL: https://github.com/babelouest/yder Source: https://github.com/babelouest/yder/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz Patch0: yder-fix-build.patch -Patch1: 0001-Fix-pkg-config-information-add-requires-fields-as-me.patch BuildRequires: cmake BuildRequires: gcc-c++ BuildRequires: pkgconfig -BuildRequires: pkgconfig(libsystemd) BuildRequires: pkgconfig(liborcania) +BuildRequires: pkgconfig(libsystemd) %description Yder is a logging library where messages can be logged to console, @@ -62,10 +62,10 @@ %prep %setup -q %patch0 -p1 -%patch1 -p1 %build -%cmake +%cmake \ + -DCMAKE_INSTALL_PREFIX:PATH=/ make %{?_smp_mflags} %install @@ -82,6 +82,7 @@ %files devel %{_includedir}/yder.h +%{_includedir}/yder-cfg.h %{_libdir}/libyder.so %{_libdir}/pkgconfig/libyder.pc ++++++ yder-1.3.4.tar.gz -> yder-1.4.4.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yder-1.3.4/.gitignore new/yder-1.4.4/.gitignore --- old/yder-1.3.4/.gitignore 2018-07-28 01:37:40.000000000 +0200 +++ new/yder-1.4.4/.gitignore 2018-10-27 20:34:43.000000000 +0200 @@ -9,3 +9,4 @@ log_journald test/yder_test valgrind.txt +yder-cfg.h diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yder-1.3.4/.travis.yml new/yder-1.4.4/.travis.yml --- old/yder-1.3.4/.travis.yml 1970-01-01 01:00:00.000000000 +0100 +++ new/yder-1.4.4/.travis.yml 2018-10-27 20:34:43.000000000 +0200 @@ -0,0 +1,25 @@ +# travis configuration file +# Copyright 2018 Ilya Shipitsin <[email protected]> +# Nicolas Mora <[email protected]> +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 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yder-1.3.4/CHANGELOG.md new/yder-1.4.4/CHANGELOG.md --- old/yder-1.3.4/CHANGELOG.md 2018-07-28 01:37:40.000000000 +0200 +++ new/yder-1.4.4/CHANGELOG.md 2018-10-27 20:34:43.000000000 +0200 @@ -1,5 +1,27 @@ # 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 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yder-1.3.4/CMakeLists.txt new/yder-1.4.4/CMakeLists.txt --- old/yder-1.3.4/CMakeLists.txt 2018-07-28 01:37:40.000000000 +0200 +++ new/yder-1.4.4/CMakeLists.txt 2018-10-27 20:34:43.000000000 +0200 @@ -24,14 +24,16 @@ # 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 "3") +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.4") +set(ORCANIA_VERSION_DOWNLOAD "1.2.8") # cmake modules @@ -66,15 +68,21 @@ ${INC_DIR}/yder.h # allow many IDEs to find and edit it ${SRC_DIR}/yder.c) -# static library +# dependencies -option(BUILD_STATIC "Build static library." OFF) +option(WITH_JOURNALD "Check journald." ON) -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) +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 @@ -82,52 +90,67 @@ add_library(yder SHARED ${LIB_SRC}) set_target_properties(yder PROPERTIES COMPILE_OPTIONS -Wextra - PUBLIC_HEADER ${INC_DIR}/yder.h + 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 () -# dependencies +target_link_libraries(yder ${LIBS} ${ORCANIA_LIBRARIES} ${SYSTEMD_LIBRARIES}) -option(WITH_JOURNALD "Check journald." ON) +# static library -if (WITH_JOURNALD) - include(FindSystemd) - find_package(Systemd REQUIRED) - if (SYSTEMD_FOUND) - set(SYSTEMD_LIBRARIES systemd) - include_directories(${SYSTEMD_INCLUDE_DIRS}) - endif () -else() - add_definitions(-DY_DISABLE_JOURNALD) +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 () -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) - add_dependencies(yder orcania) - set(ORCANIA_LIBRARIES orcania) -else() - set(LIBS ${LIBS} ${ORCANIA_LIBRARIES}) - include_directories(${ORCANIA_INCLUDE_DIRS}) +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 () -target_link_libraries(yder ${LIBS} ${ORCANIA_LIBRARIES} ${SYSTEMD_LIBRARIES}) +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_TESTING "Build the testing tree." OFF) # because we don not use include(CTest) +option(BUILD_YDER_TESTING "Build the testing tree." OFF) # because we don not use include(CTest) -if (BUILD_TESTING) +if (BUILD_YDER_TESTING) include(FindCheck) find_package(Check) if (CHECK_FOUND) @@ -172,7 +195,7 @@ configure_file(libyder.pc.in libyder.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libyder.pc - DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig) + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) set(TARGETS yder) if (BUILD_STATIC) @@ -223,12 +246,25 @@ 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_DEBIAN_PACKAGE_NAME "libyder") +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 "[email protected]") -set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${PROJECT_DESCRIPTION}) -set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/babelouest/yder") 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") @@ -239,3 +275,9 @@ 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}") diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yder-1.3.4/README.md new/yder-1.4.4/README.md --- old/yder-1.3.4/README.md 2018-07-28 01:37:40.000000000 +0200 +++ new/yder-1.4.4/README.md 2018-10-27 20:34:43.000000000 +0200 @@ -2,6 +2,8 @@ Logging library written in C. +[](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. @@ -47,8 +49,9 @@ 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_TESTING=[on|off]` (default `off`): Build unit tests +- `-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 @@ -122,6 +125,7 @@ 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. @@ -138,6 +142,34 @@ 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`: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yder-1.3.4/cmake-modules/FindOrcania.cmake new/yder-1.4.4/cmake-modules/FindOrcania.cmake --- old/yder-1.3.4/cmake-modules/FindOrcania.cmake 2018-07-28 01:37:40.000000000 +0200 +++ new/yder-1.4.4/cmake-modules/FindOrcania.cmake 2018-10-27 20:34:43.000000000 +0200 @@ -31,8 +31,6 @@ # License along with this library. If not, see <http://www.gnu.org/licenses/>. #============================================================================= -# Sat Jan 27 15:57:36 -03 2018 - find_package(PkgConfig QUIET) pkg_check_modules(PC_ORCANIA QUIET liborcania) @@ -44,6 +42,7 @@ 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") @@ -52,6 +51,13 @@ 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) @@ -63,4 +69,5 @@ set(ORCANIA_LIBRARIES ${ORCANIA_LIBRARY}) set(ORCANIA_INCLUDE_DIRS ${ORCANIA_INCLUDE_DIR}) endif () -mark_as_advanced(ORCANIA_INCLUDE_DIR ORCANIA_LIBRARY) \ No newline at end of file + +mark_as_advanced(ORCANIA_INCLUDE_DIR ORCANIA_LIBRARY) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yder-1.3.4/examples/Makefile new/yder-1.4.4/examples/Makefile --- old/yder-1.3.4/examples/Makefile 2018-07-28 01:37:40.000000000 +0200 +++ new/yder-1.4.4/examples/Makefile 2018-10-27 20:34:43.000000000 +0200 @@ -14,11 +14,12 @@ # GNU GENERAL PUBLIC LICENSE for more details. # CC=gcc -CFLAGS=-c -Wall -D_REENTRANT $(ADDITIONALFLAGS) +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 +TARGET=log_console log_syslog log_file log_combined log_callback ifndef Y_DISABLE_JOURNALD TARGET+= log_journald @@ -27,7 +28,7 @@ all: libyder.so $(TARGET) clean: - rm -f *.o log_console log_syslog log_file log_combined log_journald + rm -f *.o log_console log_syslog log_file log_combined log_journald log_callback debug: ADDITIONALFLAGS=-DDEBUG -g -O0 @@ -56,21 +57,28 @@ $(CC) -c $(CFLAGS) log_combined.c $(CC) -o log_combined log_combined.o $(LIBS) -test_console: libyder.so $(TARGET) +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 $(TARGET) +test_syslog: libyder.so log_syslog LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./log_syslog -test_file: libyder.so $(TARGET) +test_file: libyder.so log_file LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./log_file -test_combined: libyder.so $(TARGET) +test_combined: libyder.so log_combined LD_LIBRARY_PATH=$(YDER_LOCATION):${LD_LIBRARY_PATH} ./log_combined -test_journald: libyder.so $(TARGET) +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 @@ -78,23 +86,27 @@ 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 log_console log_syslog log_file log_combined log_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 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yder-1.3.4/examples/log_callback.c new/yder-1.4.4/examples/log_callback.c --- old/yder-1.3.4/examples/log_callback.c 1970-01-01 01:00:00.000000000 +0100 +++ new/yder-1.4.4/examples/log_callback.c 2018-10-27 20:34:43.000000000 +0200 @@ -0,0 +1,76 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#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; +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yder-1.3.4/examples/log_combined.c new/yder-1.4.4/examples/log_combined.c --- old/yder-1.3.4/examples/log_combined.c 2018-07-28 01:37:40.000000000 +0200 +++ new/yder-1.4.4/examples/log_combined.c 2018-10-27 20:34:43.000000000 +0200 @@ -1,6 +1,6 @@ #include <stdio.h> #include <stdlib.h> -#include "../include/yder.h" +#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); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yder-1.3.4/examples/log_console.c new/yder-1.4.4/examples/log_console.c --- old/yder-1.3.4/examples/log_console.c 2018-07-28 01:37:40.000000000 +0200 +++ new/yder-1.4.4/examples/log_console.c 2018-10-27 20:34:43.000000000 +0200 @@ -1,7 +1,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "../include/yder.h" +#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); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yder-1.3.4/examples/log_file.c new/yder-1.4.4/examples/log_file.c --- old/yder-1.3.4/examples/log_file.c 2018-07-28 01:37:40.000000000 +0200 +++ new/yder-1.4.4/examples/log_file.c 2018-10-27 20:34:43.000000000 +0200 @@ -1,6 +1,6 @@ #include <stdio.h> #include <stdlib.h> -#include "../include/yder.h" +#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); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yder-1.3.4/examples/log_journald.c new/yder-1.4.4/examples/log_journald.c --- old/yder-1.3.4/examples/log_journald.c 2018-07-28 01:37:40.000000000 +0200 +++ new/yder-1.4.4/examples/log_journald.c 2018-10-27 20:34:43.000000000 +0200 @@ -1,6 +1,6 @@ #include <stdio.h> #include <stdlib.h> -#include "../include/yder.h" +#include "yder.h" #ifdef Y_DISABLE_JOURNALD #error "Journald log disabled" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yder-1.3.4/examples/log_syslog.c new/yder-1.4.4/examples/log_syslog.c --- old/yder-1.3.4/examples/log_syslog.c 2018-07-28 01:37:40.000000000 +0200 +++ new/yder-1.4.4/examples/log_syslog.c 2018-10-27 20:34:43.000000000 +0200 @@ -1,6 +1,6 @@ #include <stdio.h> #include <stdlib.h> -#include "../include/yder.h" +#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); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yder-1.3.4/include/yder-cfg.h.in new/yder-1.4.4/include/yder-cfg.h.in --- old/yder-1.3.4/include/yder-cfg.h.in 1970-01-01 01:00:00.000000000 +0100 +++ new/yder-1.4.4/include/yder-cfg.h.in 2018-10-27 20:34:43.000000000 +0200 @@ -0,0 +1,32 @@ +/** + * + * Yder Framework + * + * Logging framework library + * + * yder-cfg.h: configuration file + * + * Copyright 2018 Nicolas Mora <[email protected]> + * + * 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 <http://www.gnu.org/licenses/>. + * + */ + +#ifndef _YDER_CFG_H_ +#define _YDER_CFG_H_ + +#define YDER_VERSION ${PROJECT_VERSION} +#cmakedefine DISABLE_JOURNALD + +#endif /* _YDER_CFG_H_ */ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yder-1.3.4/include/yder.h new/yder-1.4.4/include/yder.h --- old/yder-1.3.4/include/yder.h 2018-07-28 01:37:40.000000000 +0200 +++ new/yder-1.4.4/include/yder.h 2018-10-27 20:34:43.000000000 +0200 @@ -26,13 +26,16 @@ #ifndef __YDER_H__ #define __YDER_H__ -#define YDER_VERSION 1.3.4 +#include "yder-cfg.h" + +#include <time.h> #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 @@ -49,6 +52,14 @@ 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(); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yder-1.3.4/libyder.pc.in new/yder-1.4.4/libyder.pc.in --- old/yder-1.3.4/libyder.pc.in 2018-07-28 01:37:40.000000000 +0200 +++ new/yder-1.4.4/libyder.pc.in 2018-10-27 20:34:43.000000000 +0200 @@ -7,5 +7,8 @@ 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} + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yder-1.3.4/src/Makefile new/yder-1.4.4/src/Makefile --- old/yder-1.3.4/src/Makefile 2018-07-28 01:37:40.000000000 +0200 +++ new/yder-1.4.4/src/Makefile 2018-10-27 20:34:43.000000000 +0200 @@ -19,44 +19,63 @@ # License along with this library. If not, see <http://www.gnu.org/licenses/>. # 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 $(ADDITIONALFLAGS) +CFLAGS+=-c -fPIC -Wall -D_REENTRANT -I$(YDER_INCLUDE) $(ADDITIONALFLAGS) $(CPPFLAGS) LIBS=-lc -lorcania $(ADDITIONALLIBS) OUTPUT=libyder.so -VERSION=1.3.4 +VERSION=1.4.4 ifndef Y_DISABLE_JOURNALD + DISABLE_JOURNALD=0 LIBS+=-lsystemd +else + DISABLE_JOURNALD=1 endif all: release -libyder.so: yder.o +$(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: yder.o +libyder.a: $(CONFIG_FILE) yder.o ar rcs libyder.a yder.o -yder.o: ../include/yder.h yder.c +yder.o: $(YDER_INCLUDE)/yder.h yder.c $(CC) $(CFLAGS) $(CPPFLAGS) yder.c clean: - rm -f *.o *.so *.a $(OUTPUT) $(OUTPUT).* + rm -f *.o *.so *.a $(OUTPUT) $(OUTPUT).* $(YDER_INCLUDE)/yder-cfg.h install: all - cp $(OUTPUT).$(VERSION) $(DESTDIR)/lib - cp ../include/yder.h $(DESTDIR)/include + install $(OUTPUT).$(VERSION) $(DESTDIR)/lib + install -m644 $(YDER_INCLUDE)/yder.h $(DESTDIR)/include + install -m644 $(CONFIG_FILE) $(DESTDIR)/include -ldconfig static-install: static - cp libyder.a $(DESTDIR)/lib - cp ../include/yder.h $(DESTDIR)/include + 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 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yder-1.3.4/src/yder.c new/yder-1.4.4/src/yder.c --- old/yder-1.3.4/src/yder.c 2018-07-28 01:37:40.000000000 +0200 +++ new/yder-1.4.4/src/yder.c 2018-10-27 20:34:43.000000000 +0200 @@ -27,7 +27,9 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <time.h> + +#include <orcania.h> +#include "yder.h" #ifndef _WIN32 #include <syslog.h> @@ -36,9 +38,6 @@ #endif #endif -#include <orcania.h> -#include "../include/yder.h" - /** * Write log message to console output (stdout or stderr) */ @@ -164,11 +163,20 @@ * 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, const unsigned long level, const char * 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 @@ -193,6 +201,11 @@ 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; @@ -232,6 +245,9 @@ 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); + } } } @@ -257,18 +273,32 @@ perror("journald mode not supported on your architecture"); return 0; } else { - return y_write_log(app, init_mode, init_level, init_log_file, Y_LOG_LEVEL_INFO, message); + 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, Y_LOG_LEVEL_INFO, message); + 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, 0, NULL); + return y_write_log(NULL, 0, 0, NULL, NULL, NULL, 0, NULL); } /** @@ -285,7 +315,7 @@ 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, level, out); + y_write_log(NULL, Y_LOG_MODE_CURRENT, Y_LOG_LEVEL_CURRENT, NULL, NULL, NULL, level, out); o_free(out); } va_end(args); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yder-1.3.4/test/Makefile new/yder-1.4.4/test/Makefile --- old/yder-1.3.4/test/Makefile 2018-07-28 01:37:40.000000000 +0200 +++ new/yder-1.4.4/test/Makefile 2018-10-27 20:34:43.000000000 +0200 @@ -20,8 +20,9 @@ # CC=gcc -CFLAGS=-Wall -D_REENTRANT -DDEBUG -g -O0 +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 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yder-1.3.4/test/yder_test.c new/yder-1.4.4/test/yder_test.c --- old/yder-1.3.4/test/yder_test.c 2018-07-28 01:37:40.000000000 +0200 +++ new/yder-1.4.4/test/yder_test.c 2018-10-27 20:34:43.000000000 +0200 @@ -1,54 +1,201 @@ -/* Public domain, no copyright. Use at your own risk. */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> -#include <time.h> - -#include <check.h> -#include "../include/yder.h" - -START_TEST(test_yder) -{ - 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 - -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); - 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; -} +/* Public domain, no copyright. Use at your own risk. */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <time.h> + +#include <check.h> +#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; +} ++++++ yder-fix-build.patch ++++++ --- /var/tmp/diff_new_pack.LlNxPY/_old 2019-01-08 12:30:01.984170425 +0100 +++ /var/tmp/diff_new_pack.LlNxPY/_new 2019-01-08 12:30:01.996170411 +0100 @@ -1,13 +1,13 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt -index 21a465b..4a08dd9 100644 +index cce6408..77f93df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt -@@ -172,7 +172,7 @@ option(INSTALL_HEADER "Install the header files" ON) # Install yder.h or not - configure_file(libyder.pc.in libyder.pc @ONLY) +@@ -97,7 +97,7 @@ if (WIN32) + set_target_properties(yder PROPERTIES SUFFIX "-${LIBRARY_VERSION_MAJOR}.dll") + endif () - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libyder.pc -- DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig) -+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +-target_link_libraries(yder ${LIBS} ${ORCANIA_LIBRARIES} ${SYSTEMD_LIBRARIES}) ++target_link_libraries(yder ${LIBS} ${ORCANIA_LIBRARIES} orcania ${SYSTEMD_LIBRARIES}) + + # static library - set(TARGETS yder) - if (BUILD_STATIC)
