From b6410136b7a825feee918d925463514114ea4249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20=C5=81yszczek?= Date: Sun, 6 May 2018 15:34:45 -0600 Subject: [PATCH] apps/system/embedlog: Support for embedlog data loggin package from https://embedlog.kurwinet.pl/ --- system/embedlog/.gitignore | 1 + system/embedlog/Kconfig | 160 +++++++++++++++++++++++++ system/embedlog/Make.defs | 38 ++++++ system/embedlog/Makefile | 239 +++++++++++++++++++++++++++++++++++++ 4 files changed, 438 insertions(+) create mode 100644 system/embedlog/.gitignore create mode 100644 system/embedlog/Kconfig create mode 100644 system/embedlog/Make.defs create mode 100644 system/embedlog/Makefile diff --git a/system/embedlog/.gitignore b/system/embedlog/.gitignore new file mode 100644 index 000000000..ceaa4d01d --- /dev/null +++ b/system/embedlog/.gitignore @@ -0,0 +1 @@ +/embedlog* diff --git a/system/embedlog/Kconfig b/system/embedlog/Kconfig new file mode 100644 index 000000000..aede08263 --- /dev/null +++ b/system/embedlog/Kconfig @@ -0,0 +1,160 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +menuconfig SYSTEM_EMBEDLOG + bool "embedlog library" + default n + ---help--- + Highly configurable logger for embedded devices. Documentation and + more info available on: https://embedlog.kurwinet.pl (don't worry, + it's in english). Note: none of the options define how embedlog + will behave, it will simply configure whether given feature can be + enabled in runtime or no. So enabling CONFIG_EMBEDLOG_ENABLE_TIMESTAMP + won't make logger to add timestamp to every message - you will have to + also enable timestamp in runtime object. But when + CONFIG_EMBEDLOG_ENABLE_TIMESTAMP is disabled, setting timestamp print + in runtime will make no difference and timestamp still will not be + printed. + + Library is licensed under BSD 2-clause license. See LICENSE file in + the downloaded code for license details + +if SYSTEM_EMBEDLOG + +config EMBEDLOG_ENABLE_OUT_FILE + bool "Enable logging to file" + default n + ---help--- + If enabled, you will be able to store logs in a file (like on + sdcard). Log rotation is available as well. LIbrary automatically + handles cases when files are deleted or mountpoint disappears and + appear again (like sd card switch). Disabling this will result in + smaller code. + +if EMBEDLOG_ENABLE_OUT_FILE + +config EMBEDLOG_ENABLE_BINARY_LOGS + bool "Enable binary logs" + default n + ---help--- + When enabled, you will be able to print binary data into file + to save space (on block device). Note: you will not be able to + read such logs with tools like 'less' or 'grep'. You will need to + create own reader or use 'hexdump'. + +endif + +config EMBEDLOG_ENABLE_OUT_STDERR + bool "Enable logging to standard error" + default y + ---help--- + If enabled, you will be able to log messages to standard error. + +config EMBEDLOG_ENABLE_OUT_TTY + bool "Enable printing to tty device" + default y + ---help--- + If enabled, you will be able to configure logger to print directly + to tty serial device (like /dev/ttyS1). This might be usefull if you + want to have nsh in one tty and logs on the other. This is suitable + if only one task will be printing logs to one tty, if you want + multiple tasks to print into one tty, it's better to enable syslog + printing and the syslog handle it. + +config EMBEDLOG_ENABLE_OUT_CUSTOM + bool "Enable custom logging function" + default n + ---help--- + When enabled, you will be able to define own function that accepts + fully constructed log message as 'const char *' + +config EMBEDLOG_ENABLE_TIMESTAMP + bool "Enable timestamp in messages" + default y + ---help--- + If enabled, you will be able to configure logger to add timestamp to + every loged message. + +if EMBEDLOG_ENABLE_TIMESTAMP + +config EMBEDLOG_ENABLE_FRACTIONS + bool "Enable fractions of seconds" + default y + ---help--- + If enabled, you will be able to configure logger to add fractions of + seconds to timestamp + +endif + +config EMBEDLOG_ENABLE_PREFIX + bool "Enable prefix" + default n + ---help--- + If enabled, you will be able to set prefix that will be added to + each message logged by embedlog. Usefull when multiple tasks print + to one tty (via syslog) and you need an easy way to know which program + printed given log message. + +if EMBEDLOG_ENABLE_PREFIX + +config EMBEDLOG_PREFIX_MAX + int "Max prefix length" + default 16 + ---help--- + Maximum length of prefix that can be printed. If prefix exceeds this + value it will be truncated. + +endif #EMBEDLOG_ENABLE_PREFIX + +config EMBEDLOG_ENABLE_FINFO + bool "Enable file info" + default y + ---help--- + If enabled, you will be able to turn on information about location + of the log. This uses __FILE__ and __LINE__ macros. + +if EMBEDLOG_ENABLE_FINFO + +config EMBEDLOG_FLEN_MAX + int "max file name in finfo" + default 16 + ---help--- + finfo look like this + + [filename.c:123] + + this parameter defines how long "filename.c" can be, if file name + exceeds this value it will be truncated. + +endif # EMBEDLOG_ENABLE_FINFO + +config EMBEDLOG_ENABLE_COLORS + bool "Enable output colors" + default n + ---help--- + If enabled, you will be able to turn on ANSI colors for messages + with different log severities. Disabling this will result in smaller + code. + +config EMBEDLOG_LOG_MAX + int "Max length of log message" + default 128 + ---help--- + Maximum length of single log message. This defines length of finall + message, so message "foo() returned %s" may consume for example + 200 bytes since '%s' may be a long string. Metadata like timestamp + or file info uses this space too. Output log will be truncated if + it exceeds this value. Lowering/increasing will result in + apropriate higher/lower stack usage. + +config EMBEDLOG_MEM_LINE_SIZE + int "Number of bytes in line" + default 16 + ---help--- + How many bytes of memory to print in a single line of el_pmemory call. + Check https://embedlog.kurwinet.pl/manuals/el_pmemory.3.html + for more information about this. + +endif # SYSTEM_EMBEDLOG diff --git a/system/embedlog/Make.defs b/system/embedlog/Make.defs new file mode 100644 index 000000000..f539b7905 --- /dev/null +++ b/system/embedlog/Make.defs @@ -0,0 +1,38 @@ +############################################################################ +# apps/system/embedlog/Make.defs +# +# Copyright (C) 2018 Michał Łyszczek. All rights reserved. +# Author: Michał Łyszczek +# +# 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 NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# 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 OWNER 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. +# +############################################################################ + +ifeq ($(CONFIG_SYSTEM_EMBEDLOG),y) +CONFIGURED_APPS += system/embedlog +endif diff --git a/system/embedlog/Makefile b/system/embedlog/Makefile new file mode 100644 index 000000000..56c750ec3 --- /dev/null +++ b/system/embedlog/Makefile @@ -0,0 +1,239 @@ +############################################################################ +# apps/system/embedlog/Makefile +# +# Copyright (C) Michał Łyszczek. All rights reserved. +# Author: Michał Łyszczek +# +# 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 NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# 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 OWNER 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. +# +############################################################################ + +-include $(TOPDIR)/.config +-include $(TOPDIR)/Make.defs +include $(APPDIR)/Make.defs + +ROOTDEPPATH = --dep-path . + +WGET = wget +CP = cp -R +UNPACK = tar -xzf +PACKEXT = .tar.gz + +EMBEDLOG_URL = https://distfiles.kurwinet.pl/embedlog +EMBEDLOG_VERSION = 0.3.0 +EMBEDLOG_EXT = tar.gz +EMBEDLOG_SOURCES = embedlog-$(EMBEDLOG_VERSION) +EMBEDLOG_TARBALL = $(EMBEDLOG_SOURCES).$(EMBEDLOG_EXT) + +CFLAGS += -I$(APPDIR)/include/system + +SRCS = embedlog/src/el-options.c \ + embedlog/src/el-perror.c \ + embedlog/src/el-pmemory.c \ + embedlog/src/el-print.c \ + embedlog/src/el-puts.c \ + embedlog/src/el-ts.c + +# compile-time configuration of embedlog + +ifeq ($(CONFIG_EMBEDLOG_ENABLE_TIMESTAMP),y) + CFLAGS += -DENABLE_TIMESTAMP + CFLAGS += -DENABLE_REALTIME + +ifeq ($(CONFIG_CLOCK_MONOTONIC),y) + CFLAGS += -DENABLE_MONOTONIC +else + CFLAGS += -DENABLE_MONOTONIC=0 +endif +endif + +ifeq ($(CONFIG_EMBEDLOG_ENABLE_FRACTIONS),y) + CFLAGS += -DENABLE_FRACTIONS +else + CFLAGS += -DENABLE_FRACTIONS=0 +endif + +ifeq ($(CONFIG_EMBEDLOG_ENABLE_COLORS),y) + CFLAGS += -DENABLE_COLORS +else + CFLAGS += -DENABLE_COLORS=0 +endif + +ifeq ($(CONFIG_EMBEDLOG_ENABLE_PREFIX),y) + CFLAGS += -DENABLE_PREFIX + CFLAGS += -DEL_PREFIX_MAX=$(CONFIG_EMBEDLOG_PREFIX_MAX) +else + CFLAGS += -DENABLE_PREFIX=0 + CFLAGS += -DEL_PREFIX_MAX=0 +endif + +ifeq ($(CONFIG_EMBEDLOG_ENABLE_FINFO),y) + CFLAGS += -DENABLE_FINFO + CFLAGS += -DNOFINFO=0 + CFLAGS += -DEL_FLEN_MAX=$(CONFIG_EMBEDLOG_FLEN_MAX) +else + CFLAGS += -DENABLE_FINFO=0 + CFLAGS += -DNOFINFO + CFLAGS += -DEL_FLEN_MAX=0 +endif + +ifeq ($(CONFIG_EMBEDLOG_ENABLE_OUT_CUSTOM),y) + CFLAGS += -DENABLE_OUT_CUSTOM +else + CFLAGS += -DENABLE_OUT_CUSTOM=0 +endif + +ifeq ($(CONFIG_EMBEDLOG_ENABLE_OUT_STDERR),y) + CFLAGS += -DENABLE_OUT_STDERR +else + CFLAGS += -DENABLE_OUT_STDERR=0 +endif + +ifeq ($(CONFIG_EMBEDLOG_ENABLE_OUT_FILE),y) + CFLAGS += -DENABLE_OUT_FILE + SRCS += embedlog/src/el-file.c +else + CFLAGS += -DENABLE_OUT_FILE=0 +endif + +ifeq ($(CONFIG_EMBEDLOG_ENABLE_BINARY_LOGS),y) + CFLAGS += -DENABLE_BINARY_LOGS + SRCS += embedlog/src/el-pbinary.c + SRCS += embedlog/src/el-encode-number.c +else + CFLAGS += -DENABLE_BINARY_LOGS=0 +endif + +ifeq ($(CONFIG_EMBEDLOG_ENABLE_OUT_TTY),y) + CFLAGS += -DENABLE_OUT_TTY + SRCS += embedlog/src/el-tty.c +else + CFLAGS += -DENABLE_OUT_TTY=0 +endif + +ifeq ($(CONFIG_SERIAL_TERMIOS),y) + CFLAGS += -DHAVE_TERMIOS_H +else + CFLAGS += -DHAVE_TERMIOS_H=0 +endif + +# config.h is available only when building with autotools + +CFLAGS += -DHAVE_CONFIG_H=0 + +# embedlog uses access(path, F_OK) to determin if file exists or not and since +# nuttx always returns OK here, we mark access as not working and make embedlog +# to use stat() for that purpose + +CFLAGS += -DHAVE_ACCESS=0 +CFLAGS += -DEL_LOG_MAX=$(CONFIG_EMBEDLOG_LOG_MAX) +CFLAGS += -DEL_MEM_LINE_SIZE=$(CONFIG_EMBEDLOG_MEM_LINE_SIZE) +CFLAGS += -DENABLE_REENTRANT +CFLAGS += -DENABLE_OUT_SYSLOG +CFLAGS += -DHAVE_STAT +CFLAGS += -DHAVE_SNPRINTF +CFLAGS += -DHAVE_UNISTD_H +CFLAGS += -DHAVE_FSYNC +CFLAGS += -DHAVE_FILENO +CFLAGS += -DENABLE_COLORS_EXTENDED=0 + +# not yet implemented features - silent compiler warnings + +CFLAGS += -DENABLE_OUT_NET=0 + +# nuttx does not implement clock() function + +CFLAGS += -DENABLE_CLOCK=0 + +# building of embedlog + +CCEXT = .c +COBJS = $(SRCS:$(CCEXT)=$(OBJEXT)) + +ifeq ($(WINTOOL),y) + BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}" +else + BIN = $(APPDIR)/libapps$(LIBEXT) +endif +DEPBIN = $(APPDIR)/libapps$(LIBEXT) + +all: .built +.PHONY: clean depend distclean preconfig context + +$(EMBEDLOG_TARBALL): + @echo "Downloading: $@" + $(Q) $(WGET) -O $@ $(EMBEDLOG_URL)/$@ + $(Q) touch $@ + +$(EMBEDLOG_SOURCES): $(EMBEDLOG_TARBALL) + @echo "Unpacking $< -> $@" + $(Q) $(call DELDIR, $@) + $(Q) $(UNPACK) $< + $(Q) touch $@ + +embedlog: $(EMBEDLOG_SOURCES) + $(call DELDIR, $@) + $(Q) $(CP) $< $@ + $(Q) touch $@ + +create_includes: + $(Q) $(CP) $(EMBEDLOG_SOURCES)/include/embedlog.h $(APPDIR)/include/system + +$(COBJS): %$(OBJEXT): %$(CCEXT) + $(Q) $(call COMPILE, $<, $@) + +.built: $(COBJS) + $(Q) $(call ARCHIVE, $(BIN), $(COBJS)) + $(Q) touch $@ + +context: embedlog + $(Q) $(MAKE) create_includes + +.depend: Makefile $(SRCS) + $(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(CSRCS) >Make.dep + $(Q) touch $@ + +depend: .depend + +install: + +clean: + $(Q) $(call DELFILE, .built) + $(Q) $(call DELFILE, $(APPDIR)/include/system/embedlog.h) + $(Q) $(foreach COBJ, $(COBJS), $(call DELFILE, $(COBJ))) + +distclean: clean + $(Q) $(call DELFILE, Make.dep) + $(Q) $(call DELFILE, .depend) + $(Q) $(call DELDIR, embedlog) + $(Q) $(call DELDIR, $(EMBEDLOG_SOURCES)) + $(Q) $(call DELDIR, $(EMBEDLOG_TARBALL)) + +preconfig: + +-include Make.dep