summaryrefslogtreecommitdiff
path: root/nuttx/lib/stdio
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-02-11 14:20:40 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-02-11 14:20:40 +0000
commit75e67f05d4b97efc32d95b478ec1c1f959992a4b (patch)
tree8cf471347f767130a152b249bafd7de1a6017757 /nuttx/lib/stdio
parent4a62de545bf87610c2415218e144ddef4dd0e75c (diff)
downloadpx4-nuttx-75e67f05d4b97efc32d95b478ec1c1f959992a4b.tar.gz
px4-nuttx-75e67f05d4b97efc32d95b478ec1c1f959992a4b.tar.bz2
px4-nuttx-75e67f05d4b97efc32d95b478ec1c1f959992a4b.zip
Add logic to re-direct debug output to a sysloggin device
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4381 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/lib/stdio')
-rw-r--r--nuttx/lib/stdio/Make.defs4
-rw-r--r--nuttx/lib/stdio/lib_lowprintf.c16
-rw-r--r--nuttx/lib/stdio/lib_rawprintf.c17
-rw-r--r--nuttx/lib/stdio/lib_syslogstream.c103
4 files changed, 130 insertions, 10 deletions
diff --git a/nuttx/lib/stdio/Make.defs b/nuttx/lib/stdio/Make.defs
index 7bffb2340..690c83641 100644
--- a/nuttx/lib/stdio/Make.defs
+++ b/nuttx/lib/stdio/Make.defs
@@ -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
diff --git a/nuttx/lib/stdio/lib_lowprintf.c b/nuttx/lib/stdio/lib_lowprintf.c
index 576402d61..0314a27f0 100644
--- a/nuttx/lib/stdio/lib_lowprintf.c
+++ b/nuttx/lib/stdio/lib_lowprintf.c
@@ -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*/
diff --git a/nuttx/lib/stdio/lib_rawprintf.c b/nuttx/lib/stdio/lib_rawprintf.c
index 915fd833b..d738b212a 100644
--- a/nuttx/lib/stdio/lib_rawprintf.c
+++ b/nuttx/lib/stdio/lib_rawprintf.c
@@ -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;
diff --git a/nuttx/lib/stdio/lib_syslogstream.c b/nuttx/lib/stdio/lib_syslogstream.c
new file mode 100644
index 000000000..0b5a95144
--- /dev/null
+++ b/nuttx/lib/stdio/lib_syslogstream.c
@@ -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 */
+
+