Add logic to re-direct debug output to a sysloggin device

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4381 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo
2012-02-11 14:20:40 +00:00
parent f03655f43a
commit bdbe8e114c
30 changed files with 541 additions and 117 deletions
+4
View File
@@ -52,6 +52,10 @@ STDIO_SRCS += lib_fopen.c lib_fclose.c lib_fread.c lib_libfread.c lib_fseek.c \
endif
endif
ifdef ($(CONFIG_SYSLOG)
STDIO_SRCS += lib_syslogstream.c
endif
ifeq ($(CONFIG_LIBC_FLOATINGPOINT),y)
STDIO_SRCS += lib_dtoa.c
endif
+9 -7
View File
@@ -1,8 +1,8 @@
/****************************************************************************
* lib/stdio/lib_lowprintf.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -82,17 +82,19 @@
* Name: lib_lowvprintf
****************************************************************************/
#ifdef CONFIG_ARCH_LOWPUTC
#if defined(CONFIG_ARCH_LOWPUTC) || defined(CONFIG_SYSLOG)
int lib_lowvprintf(const char *fmt, va_list ap)
{
struct lib_outstream_s stream;
/* Wrap the stdout in a stream object and let lib_vsprintf
* do the work.
*/
/* Wrap the stdout in a stream object and let lib_vsprintf do the work. */
#if defined(CONFIG_RAMLOG_CONSOLE) || defined(CONFIG_RAMLOG_SYSLOG)
lib_syslogstream((FAR struct lib_outstream_s *)&stream);
#else
lib_lowoutstream((FAR struct lib_outstream_s *)&stream);
#endif
return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap);
}
@@ -111,4 +113,4 @@ int lib_lowprintf(const char *fmt, ...)
return ret;
}
#endif /* CONFIG_ARCH_LOWPUTC */
#endif /* CONFIG_ARCH_LOWPUTC || CONFIG_SYSLOG*/
+14 -3
View File
@@ -1,8 +1,8 @@
/****************************************************************************
* lib/stdio/lib_rawprintf.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -83,7 +83,18 @@
int lib_rawvprintf(const char *fmt, va_list ap)
{
#if CONFIG_NFILE_DESCRIPTORS > 0
#if defined(CONFIG_SYSLOG)
struct lib_outstream_s stream;
/* Wrap the low-level output in a stream object and let lib_vsprintf
* do the work.
*/
lib_syslogstream((FAR struct lib_outstream_s *)&stream);
return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap);
#elif CONFIG_NFILE_DESCRIPTORS > 0
struct lib_rawoutstream_s rawoutstream;
+103
View File
@@ -0,0 +1,103 @@
/****************************************************************************
* lib/stdio/lib_syslogstream.c
*
* Copyright (C) 2023 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* 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 <nuttx/config.h>
#include <unistd.h>
#include <errno.h>
#include <nuttx/ramlog.h>
#include "lib_internal.h"
#ifdef CONFIG_SYSLOG
/****************************************************************************
* Pre-processor definition
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: syslogstream_putc
****************************************************************************/
static void syslogstream_putc(FAR struct lib_outstream_s *this, int ch)
{
/* At present, the RAM log is the only supported logging device */
#ifdef CONFIG_RAMLOG_SYSLOG
(void)ramlog_putc(ch);
this->nput++;
#endif
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: lib_sylogstream
*
* Description:
* Initializes a stream for use with the coinfigured syslog interface.
*
* Input parameters:
* lowoutstream - User allocated, uninitialized instance of struct
* lib_lowoutstream_s to be initialized.
*
* Returned Value:
* None (User allocated instance initialized).
*
****************************************************************************/
void lib_sylogstream(FAR struct lib_outstream_s *stream)
{
stream->put = syslogstream_putc;
#ifdef CONFIG_STDIO_LINEBUFFER
stream->flush = lib_noflush;
#endif
stream->nput = 0;
}
#endif /* CONFIG_SYSLOG */