Commit b9699471 authored by Ulrich Huber's avatar Ulrich Huber Committed by Oliver Horst
Browse files

[add] Initial syslog code with lwIP impl

parents
cmake_minimum_required(VERSION 3.7 FATAL_ERROR)
option(ENABLE_INSTALL "Enable target installation possibility" ON)
option(WITH_HEADERS "Enable the installation of header files" ON)
project(
toki-syslog
#
VERSION 0.1
LANGUAGES C
)
find_package(
toki-syslog-headers 0.1
REQUIRED
)
find_package(
toki-libc-repl 0.1
REQUIRED
)
add_library(
toki-syslog
#
STATIC
"" # The sources are added in the respective sub-folders
)
target_link_libraries(
toki-syslog
PUBLIC toki-syslog-headers
PRIVATE toki-libc-repl
)
add_subdirectory(src)
if (WITH_HEADERS)
add_subdirectory(include)
endif()
if (ENABLE_INSTALL)
# Configure and install the following files:
# - ${PROJECT_NAME}-config.cmake,
# - ${PROJECT_NAME}-config-version.cmake,
include(CMakePackageConfigHelpers)
set(ConfigPackageLocation lib/cmake/${PROJECT_NAME}-${PROJECT_VERSION})
# ${PROJECT_NAME}-config.cmake
configure_package_config_file(
${PROJECT_NAME}-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
INSTALL_DESTINATION ${ConfigPackageLocation}
)
# ${PROJECT_NAME}-config-config-version.cmake
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
COMPATIBILITY SameMajorVersion
)
# Install exported CMake target files
install(
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION lib
)
install(
EXPORT ${PROJECT_NAME}-targets
DESTINATION ${ConfigPackageLocation}
EXPORT_LINK_INTERFACE_LIBRARIES
)
# Install package/module configuration files
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
DESTINATION ${ConfigPackageLocation}
)
endif()
BSD with Attribution License
Copyright (c) 2015-2020 fortiss GmbH - Research Institute of the
Free State of Bavaria, Guerickestr. 25, 80805 Munich, Germany
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
4. Redistributions of any form whatsoever must retain the following
acknowledgment: 'This product includes software developed by the
fortiss GmbH -- Research Institute of the Free State of Bavaria,
Munich, Germany (https://www.fortiss.org/).'
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
SPDX-License-Identifier: BSD-3-Clause-Attribution
cmake_minimum_required(VERSION 3.7 FATAL_ERROR)
option(ENABLE_INSTALL "Enable target installation possibility" ON)
project(
toki-syslog-headers
#
VERSION 0.1
LANGUAGES C ASM
)
find_package(
toki-syslog-config-headers 0.1
REQUIRED
)
add_library(
toki-syslog-headers
#
INTERFACE
)
target_include_directories(
toki-syslog-headers
#
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>
INTERFACE $<INSTALL_INTERFACE:include>
)
target_link_libraries(
toki-syslog-headers
#
INTERFACE toki-syslog-config-headers
)
if (ENABLE_INSTALL)
# Configure and install the following files:
# - ${PROJECT_NAME}-config.cmake,
# - ${PROJECT_NAME}-config-version.cmake,
include(CMakePackageConfigHelpers)
set(ConfigPackageLocation lib/cmake/${PROJECT_NAME}-${PROJECT_VERSION})
# ${PROJECT_NAME}-config.cmake
configure_package_config_file(
${PROJECT_NAME}-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
INSTALL_DESTINATION ${ConfigPackageLocation}
)
# ${PROJECT_NAME}-config-config-version.cmake
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
COMPATIBILITY SameMajorVersion
)
# Install exported CMake target files
install(
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION lib
)
install(
EXPORT ${PROJECT_NAME}-targets
DESTINATION ${ConfigPackageLocation}
EXPORT_LINK_INTERFACE_LIBRARIES
)
# Install package/module configuration files
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
DESTINATION ${ConfigPackageLocation}
)
# Install all header files of the current project
get_target_property(PROJECT_INCLUDE_DIRECTORIES ${PROJECT_NAME} INTERFACE_INCLUDE_DIRECTORIES)
foreach(DIR ${PROJECT_INCLUDE_DIRECTORIES})
string(REGEX MATCH "^.<BUILD_INTERFACE:(.*)>$" EXTRACTED_DIR ${DIR})
if (CMAKE_MATCH_1)
set(EXTRACTED_DIR "${CMAKE_MATCH_1}")
file(
GLOB_RECURSE
#
HEADER_FILES
#
FOLLOW_SYMLINKS
LIST_DIRECTORIES FALSE
RELATIVE "${EXTRACTED_DIR}"
#
"${EXTRACTED_DIR}/*.h"
"${EXTRACTED_DIR}/*.hpp"
)
foreach(FILE ${HEADER_FILES})
get_filename_component(INSTALL_PATH ${FILE} DIRECTORY)
install(
FILES ${EXTRACTED_DIR}/${FILE}
DESTINATION include/${INSTALL_PATH}
)
endforeach()
endif()
endforeach()
endif()
@PACKAGE_INIT@
include(CMakeFindDependencyMacro)
find_dependency(toki-syslog-config-headers)
# Import targets
include(${CMAKE_CURRENT_LIST_DIR}/toki-syslog-headers-targets.cmake)
check_required_components(toki-syslog-headers)
#ifndef TOKI_SYSLOG_LWIP_H_IN
#define TOKI_SYSLOG_LWIP_H_IN
#include "../syslog.h"
#include <toki/syslog/configs/components/lwip.h>
#if TOKI_SYSLOG_COMPONENT_LWIP_ENABLED && defined(TOKI_SYSLOG_COMPONENT_LWIP_LEVEL)
#if TOKI_SYSLOG_COMPONENT_LWIP_LEVEL <= 7
# define lwip_log_emergency(format, ...) toki_log_emergency(TOKI_SYSLOG_COMPONENT_LWIP_FACILITY, format, ##__VA_ARGS__)
#else
# define lwip_log_emergency(...)
#endif
#if TOKI_SYSLOG_COMPONENT_LWIP_LEVEL <= 6
# define lwip_log_alert(format, ...) toki_log_alert(TOKI_SYSLOG_COMPONENT_LWIP_FACILITY, format, ##__VA_ARGS__)
#else
# define lwip_log_alert(...)
#endif
#if TOKI_SYSLOG_COMPONENT_LWIP_LEVEL <= 5
# define lwip_log_critical(format, ...) toki_log_critical(TOKI_SYSLOG_COMPONENT_LWIP_FACILITY, format, ##__VA_ARGS__)
#else
# define lwip_log_critical(...)
#endif
#if TOKI_SYSLOG_COMPONENT_LWIP_LEVEL <= 4
# define lwip_log_error(format, ...) toki_log_error(TOKI_SYSLOG_COMPONENT_LWIP_FACILITY, format, ##__VA_ARGS__)
#else
# define lwip_log_error(...)
#endif
#if TOKI_SYSLOG_COMPONENT_LWIP_LEVEL <= 3
# define lwip_log_warning(format, ...) toki_log_warning(TOKI_SYSLOG_COMPONENT_LWIP_FACILITY, format, ##__VA_ARGS__)
#else
# define lwip_log_warning(...)
#endif
#if TOKI_SYSLOG_COMPONENT_LWIP_LEVEL <= 2
# define lwip_log_notice(format, ...) toki_log_notice(TOKI_SYSLOG_COMPONENT_LWIP_FACILITY, format, ##__VA_ARGS__)
#else
# define lwip_log_notice(...)
#endif
#if TOKI_SYSLOG_COMPONENT_LWIP_LEVEL <= 1
# define lwip_log_info(format, ...) toki_log_info(TOKI_SYSLOG_COMPONENT_LWIP_FACILITY, format, ##__VA_ARGS__)
#else
# define lwip_log_info(...)
#endif
#if TOKI_SYSLOG_COMPONENT_LWIP_LEVEL == 0
# define lwip_log_debug(format, ...) toki_log_debug(TOKI_SYSLOG_COMPONENT_LWIP_FACILITY, format, ##__VA_ARGS__)
#else
# define lwip_log_debug(...)
#endif
#else
#define lwip_log_emergency(...)
#define lwip_log_alert(...)
#define lwip_log_critical(...)
#define lwip_log_error(...)
#define lwip_log_warning(...)
#define lwip_log_notice(...)
#define lwip_log_info(...)
#define lwip_log_debug(...)
#endif
#endif
\ No newline at end of file
//
// Created by ulrich on 17.06.20.
//
#pragma once
#ifndef TOKI_SYSLOG_H_IN
#define TOKI_SYSLOG_H_IN
#include "toki/syslog/configs/config.h"
void toki_log(const char* severity, const char* facility, const char* format, ...);
/*
* Do not directly use these defines for logging. Instead create a component header in the subdirectory!
*/
#if TOKI_SYSLOG
#define toki_log_emergency(facility, format, ...) toki_log("EMER", facility, format, ##__VA_ARGS__)
#define toki_log_alert(facility, format, ...) toki_log("ALRT", facility, format, ##__VA_ARGS__)
#define toki_log_critical(facility, format, ...) toki_log("CRIT", facility, format, ##__VA_ARGS__)
#define toki_log_error(facility, format, ...) toki_log("ERR ", facility, format, ##__VA_ARGS__)
#define toki_log_warning(facility, format, ...) toki_log("WARN", facility, format, ##__VA_ARGS__)
#define toki_log_notice(facility, format, ...) toki_log("NOTE", facility, format, ##__VA_ARGS__)
#define toki_log_info(facility, format, ...) toki_log("INFO", facility, format, ##__VA_ARGS__)
#define toki_log_debug(facility, format, ...) toki_log("DBG ", facility, format, ##__VA_ARGS__)
#else
#define toki_log_emergency(...)
#define toki_log_alert(...)
#define toki_log_critical(...)
#define toki_log_error(...)
#define toki_log_warning(...)
#define toki_log_notice(...)
#define toki_log_info(...)
#define toki_log_debug(...)
#endif
#endif
\ No newline at end of file
cmake_minimum_required(VERSION 3.7 FATAL_ERROR)
target_sources(
toki-syslog
#
PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/syslog.c"
)
#include <stdarg.h>
#include <stdio.h>
void toki_log(const char* severity, const char* facility, const char* format, ...) {
// TODO print time information - We are currently still missing the syscall for this feature
/*
* // Print the timestamp based on offset from epoch in secs and usecs
* struct timeval tval;
* gettimeofday(&tval, NULL);
* printf(%ld.%06ld\t", (long int) tval.tv_sec, (long int)tval.tv_usec);
*/
// Print the facility and severity
printf("%s\t%s", facility, severity);
// Print the actual message
va_list va;
va_start(va, format);
printf(format, va);
va_end(va);
}
\ No newline at end of file
@PACKAGE_INIT@
include(CMakeFindDependencyMacro)
find_dependency(toki-syslog-headers)
find_dependency(toki-libc-repl)
# Import targets
include(${CMAKE_CURRENT_LIST_DIR}/toki-syslog-targets.cmake)
check_required_components(toki-syslog)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment