From 30e820d86135f14ae495598cf5c4e236a4de36b7 Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 2 Aug 2012 17:09:25 +0000 Subject: The initial SYLOG device logic was valiant but yet still not enough git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4998 7fd9a85b-ad96-42d3-883c-3090e2eb8679 --- nuttx/drivers/syslog/Kconfig | 73 +++++++++++++++++ nuttx/drivers/syslog/Make.defs | 7 +- nuttx/drivers/syslog/README.txt | 12 ++- nuttx/drivers/syslog/syslog.c | 177 ---------------------------------------- 4 files changed, 88 insertions(+), 181 deletions(-) create mode 100644 nuttx/drivers/syslog/Kconfig delete mode 100644 nuttx/drivers/syslog/syslog.c (limited to 'nuttx/drivers') diff --git a/nuttx/drivers/syslog/Kconfig b/nuttx/drivers/syslog/Kconfig new file mode 100644 index 000000000..3ec8c7490 --- /dev/null +++ b/nuttx/drivers/syslog/Kconfig @@ -0,0 +1,73 @@ +# +# For a description of the syntax of this configuration file, +# see misc/tools/kconfig-language.txt. +# + +comment "System Logging" + +config RAMLOG + bool "RAM log device support" + default n + ---help--- + This is a driver that was intended to support debugging output, + aka syslogging, when the normal serial output is not available. + For example, if you are using a telnet or USB serial console, + the debug output will get lost. However, the RAMLOG device should + be usable even if system logging is disabled. + + This driver is similar to a pipe in that it saves the debugging + output in a FIFO in RAM. It differs from a pipe in numerous + details as needed to support logging. + +if RAMLOG +config RAMLOG_SYSLOG + bool "Use RAMLOG for SYSLOG" + default n + depends on SYSLOG + ---help--- + Use the RAM logging device for the syslogging interface. If this feature + is enabled (along with SYSLOG), then all debug output (only) will be re-directed + to the circular buffer in RAM. This RAM log can be view from NSH using the + 'dmesg'command. + + Do not enable more than one SYSLOG device. + +config RAMLOG_CONSOLE + bool "Use RAMLOG for /dev/console" + default n + depends on DEV_CONSOLE + ---help--- + Use the RAM logging device as a system console. If this feature is enabled (along + with DEV_CONSOLE), then all console output will be re-directed to a circular + buffer in RAM. This is useful, for example, if the only console is a Telnet + console. Then in that case, console output from non-Telnet threads will go to + the circular buffer and can be viewed using the NSH 'dmesg' command. + +config RAMLOG_CONSOLE_BUFSIZE + int "RAMLOG buffer size" + default 1024 + depends on RAMLOG_SYSLOG || RAMLOG_CONSOLE + ---help--- + Size of the console RAM log. Default: 1024 + +config RAMLOG_CRLF + bool "RAMLOG CR/LF" + default n + ---help--- + Pre-pend a carriage return before every linefeed that goes into the RAM log. + +config RAMLOG_NONBLOCKING + bool "RAMLOG non-block reads" + default y + ---help--- + Reading from the RAMLOG will never block if the RAMLOG is empty. If the RAMLOG + is empty, then zero is returned (usually interpreted as end-of-file). + +config RAMLOG_NPOLLWAITERS + int "RAMLOG number of poll waiters" + default 4 + depends on !DISABLE_POLL + ---help--- + The maximum number of threads that may be waiting on the poll method. + +endif diff --git a/nuttx/drivers/syslog/Make.defs b/nuttx/drivers/syslog/Make.defs index 9826beb01..aa0ab19b8 100644 --- a/nuttx/drivers/syslog/Make.defs +++ b/nuttx/drivers/syslog/Make.defs @@ -38,9 +38,10 @@ ifeq ($(CONFIG_SYSLOG),y) -ifeq ($(CONFIG_SYSLOG_CHAR),y) - CSRCS += syslog.c -endif +# If no special loggin devices are implemented, then the default SYSLOG +# logic at fs/fs_syslog.c will be used + +# (Add other SYSLOG drivers here) ifeq ($(CONFIG_RAMLOG),y) CSRCS += ramlog.c diff --git a/nuttx/drivers/syslog/README.txt b/nuttx/drivers/syslog/README.txt index c034b49b6..611f43567 100644 --- a/nuttx/drivers/syslog/README.txt +++ b/nuttx/drivers/syslog/README.txt @@ -7,7 +7,17 @@ debug output and, therefore, the syslogging interfaces are defined in the header file include/debug.h. By default, all system log output goes to console (/dev/console). But that -behavior can be changed by the drivers in this directory. +behavior can be changed by the defining CONFIG_SYSLOG in the NuttX +configuration. In that, case all low-level debug output will go through +syslog_putc(). + +One version of syslog_putc() is defined in fs/fs_syslog.c; that version is +used when CONFIG_SYSLOG_CHAR is defined. That version of syslog_putc() +just integrates with the file system to re-direct debug output to a +character device or to a file. + +If CONFIG_SYSLOG_CHAR is not defined, then other custom SYSLOG drivers +can be used. Those custom SYSLOG drivers reside in this directory. ramlog.c -------- diff --git a/nuttx/drivers/syslog/syslog.c b/nuttx/drivers/syslog/syslog.c deleted file mode 100644 index 60e9cffcb..000000000 --- a/nuttx/drivers/syslog/syslog.c +++ /dev/null @@ -1,177 +0,0 @@ -/**************************************************************************** - * drivers/syslog/syslog.c - * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include -#include -#include -#include - -#include - -#if defined(CONFIG_SYSLOG) && defined(CONFIG_SYSLOG_CHAR) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct syslog_dev_s -{ - int fd; /* File descriptor of the opened SYSLOG character device */ -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* This is the device structure for the console or syslogging function. It - * must be statically initialized because the RAMLOG syslog_putc function - * could be called before the driver initialization logic executes. - */ - -static struct syslog_dev_s g_sysdev = { -1 }; -static const uint8_t g_syscrlf[2] = { '\r', '\n' }; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: syslog_initialize - * - * Description: - * Initialize to use the character device at CONFIG_SYSLOG_DEVPATH as the - * SYSLOG. - * - ****************************************************************************/ - -int syslog_initialize(void) -{ - /* Has the device been opened yet */ - - if (g_sysdev.fd < 0) - { - /* No, try to open the device now: write-only, try to create it if - * it doesn't exist (it might be a file), if it is a file that already - * exists, then append new log data to the file. - */ - - g_sysdev.fd = open(CONFIG_SYSLOG_DEVPATH, O_WRONLY | O_CREAT | O_APPEND, 0644); - if (g_sysdev.fd < 0) - { - return -get_errno(); - } - } - - /* The SYSLOG device is open and ready for writing. */ - - return OK; -} - -/**************************************************************************** - * Name: syslog_putc - * - * Description: - * This is the low-level system logging interface. The debugging/syslogging - * interfaces are lib_rawprintf() and lib_lowprinf(). The difference is - * the lib_rawprintf() writes to fd=1 (stdout) and lib_lowprintf() uses - * a lower level interface that works from interrupt handlers. This - * function is a a low-level interface used to implement lib_lowprintf(). - * - ****************************************************************************/ - -int syslog_putc(int ch) -{ - ssize_t nbytes; - int ret; - - /* Try to initialize the device. We do this repeatedly because the log - * device might be something that was not ready the first time that - * syslog_intialize() was called (such as a USB serial device or a file - * in an NFS mounted file system. - */ - - ret = syslog_initialize(); - if (ret < 0) - { - return ret; - } - - /* Ignore carriage returns */ - - if (ch == '\r') - { - return ch; - } - - /* Pre-pend a newline with a carriage return */ - - if (ch == '\n') - { - nbytes = write(g_sysdev.fd, g_syscrlf, 2); - } - else - { - nbytes = write(g_sysdev.fd, &ch, 1); - } - - if (nbytes < 0) - { - return nbytes; - } - - return ch; -} - -#endif /* CONFIG_SYSLOG && CONFIG_SYSLOG_CHAR */ -- cgit v1.2.3