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
This commit is contained in:
patacongo 2012-02-11 14:20:40 +00:00
parent e69cbad010
commit 7b343bf7fe
30 changed files with 541 additions and 117 deletions

View File

@ -2453,4 +2453,7 @@
* drivers/ramlog.c: Add a character driver that can substitute * drivers/ramlog.c: Add a character driver that can substitute
for /dev/console and or be used for logging debug output when there for /dev/console and or be used for logging debug output when there
is no serial port available (such as when a telnet console is used). is no serial port available (such as when a telnet console is used).
* lib/stdio/lib_syslogstream: Add a stream object that will be used to
re-direct all debug output to the RAM log if CONFIG_SYSLOG and
CONFIG_RAMLOG_SYSLOG are defined.

View File

@ -3941,6 +3941,49 @@ build
</li> </li>
</ul> </ul>
<p>
System Logging:
</p>
<ul>
<li>
<code>CONFIG_SYSLOG</code>: Enables general system logging support.
</li>
<p>
At present, the only system loggin device is a circular buffer in RAM.
If <code>CONFIG_SYSLOG</code> is selected, then these options are also available.
</p>
<li>
<code>CONFIG_RAMLOG</code>: Enables the RAM logging feature
</li>
<li>
<code>CONFIG_RAMLOG_CONSOLE</code>: Use the RAM logging device as a system console.
If this feature is enabled (along with <code>CONFIG_DEV_CONSOLE</code>), 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.
</li>
<li>
<code>CONFIG_RAMLOG_SYSLOG</code>: Use the RAM logging device for the syslogging
interface. If this feature is enabled (along with <code>CONFIG_SYSLOG</code>),
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.
</li>
<li>
<code>CONFIG_RAMLOG_NPOLLWAITERS</code>: The number of threads than can be waiting
for this driver on poll(). Default: 4
</li>
<p>
If <code>CONFIG_RAMLOG_CONSOLE</code> or <code>CONFIG_RAMLOG_SYSLOG</code> is selected, then the
following may also be provided:
</p>
</li>
<li>
<code>CONFIG_RAMLOG_CONSOLE_BUFSIZE</code>: Size of the console RAM log. Default: 1024
</li>
</ul>
<p> <p>
Kernel build options: Kernel build options:
</p> </p>

View File

@ -43,6 +43,8 @@
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/fs.h> #include <nuttx/fs.h>
#include <nuttx/ramlog.h>
#include <arch/board/board.h> #include <arch/board/board.h>
#include "up_arch.h" #include "up_arch.h"
@ -159,6 +161,12 @@ void up_initialize(void)
ramlog_consoleinit(); ramlog_consoleinit();
#endif #endif
/* Initialize the system logging device */
#ifdef CONFIG_RAMLOG_SYSLOG
ramlog_sysloginit();
#endif
/* Initialize the netwok */ /* Initialize the netwok */
up_netinitialize(); up_netinitialize();

View File

@ -81,6 +81,12 @@
# endif # endif
#endig #endig
/* Determine which device to use as the system loggin device */
#ifndef CONFIG_SYSLOG
# undef CONFIG_RAMLOG_SYSLOG
#endif
/* Check if an interrupt stack size is configured */ /* Check if an interrupt stack size is configured */
#ifndef CONFIG_ARCH_INTERRUPTSTACK #ifndef CONFIG_ARCH_INTERRUPTSTACK
@ -297,14 +303,6 @@ extern void lowconsole_init(void);
# define lowconsole_init() # define lowconsole_init()
#endif #endif
/* Defined in drivers/ramlog.c */
#ifdef CONFIG_RAMLOG_CONSOLE
extern void ramlog_consoleinit(void);
#else
# define ramlog_consoleinit()
#endif
/* DMA **********************************************************************/ /* DMA **********************************************************************/
#ifdef CONFIG_ARCH_DMA #ifdef CONFIG_ARCH_DMA

View File

@ -168,6 +168,12 @@
# endif # endif
#endig #endig
/* Determine which device to use as the system loggin device */
#ifndef CONFIG_SYSLOG
# undef CONFIG_RAMLOG_SYSLOG
#endif
/* If GPIO IRQ support is defined, then a set of GPIOs must all be included */ /* If GPIO IRQ support is defined, then a set of GPIOs must all be included */
#if CONFIG_AVR32_GPIOIRQSETA == 0 && CONFIG_AVR32_GPIOIRQSETB == 0 #if CONFIG_AVR32_GPIOIRQSETA == 0 && CONFIG_AVR32_GPIOIRQSETB == 0

View File

@ -87,6 +87,12 @@
# endif # endif
#endig #endig
/* Determine which device to use as the system loggin device */
#ifndef CONFIG_SYSLOG
# undef CONFIG_RAMLOG_SYSLOG
#endif
/************************************************************************************ /************************************************************************************
* Public Types * Public Types
************************************************************************************/ ************************************************************************************/

View File

@ -92,6 +92,12 @@
# endif # endif
#endig #endig
/* Determine which device to use as the system loggin device */
#ifndef CONFIG_SYSLOG
# undef CONFIG_RAMLOG_SYSLOG
#endif
/************************************************************************************ /************************************************************************************
* Public Types * Public Types
************************************************************************************/ ************************************************************************************/

View File

@ -43,6 +43,8 @@
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/fs.h> #include <nuttx/fs.h>
#include <nuttx/ramlog.h>
#include <arch/board/board.h> #include <arch/board/board.h>
#include "up_arch.h" #include "up_arch.h"
@ -76,6 +78,12 @@
# endif # endif
#endig #endig
/* Determine which device to use as the system loggin device */
#ifndef CONFIG_SYSLOG
# undef CONFIG_RAMLOG_SYSLOG
#endif
/**************************************************************************** /****************************************************************************
* Private Types * Private Types
****************************************************************************/ ****************************************************************************/
@ -183,6 +191,12 @@ void up_initialize(void)
ramlog_consoleinit(); ramlog_consoleinit();
#endif #endif
/* Initialize the system logging device */
#ifdef CONFIG_RAMLOG_SYSLOG
ramlog_sysloginit();
#endif
/* Initialize the netwok */ /* Initialize the netwok */
up_netinitialize(); up_netinitialize();

View File

@ -172,14 +172,6 @@ extern void lowconsole_init(void);
# define lowconsole_init() # define lowconsole_init()
#endif #endif
/* Defined in drivers/ramlog.c */
#ifdef CONFIG_RAMLOG_CONSOLE
extern void ramlog_consoleinit(void);
#else
# define ramlog_consoleinit()
#endif
/* Defined in chip/xxx_timerisr.c */ /* Defined in chip/xxx_timerisr.c */
extern void up_timerinit(void); extern void up_timerinit(void);

View File

@ -43,6 +43,7 @@
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/fs.h> #include <nuttx/fs.h>
#include <nuttx/ramlog.h>
#include "up_arch.h" #include "up_arch.h"
#include "up_internal.h" #include "up_internal.h"
@ -158,6 +159,12 @@ void up_initialize(void)
ramlog_consoleinit(); ramlog_consoleinit();
#endif #endif
/* Initialize the system logging device */
#ifdef CONFIG_RAMLOG_SYSLOG
ramlog_sysloginit();
#endif
/* Initialize the netwok */ /* Initialize the netwok */
up_netinitialize(); up_netinitialize();

View File

@ -81,6 +81,12 @@
# endif # endif
#endig #endig
/* Determine which device to use as the system loggin device */
#ifndef CONFIG_SYSLOG
# undef CONFIG_RAMLOG_SYSLOG
#endif
/* Check if an interrupt stack size is configured */ /* Check if an interrupt stack size is configured */
#ifndef CONFIG_ARCH_INTERRUPTSTACK #ifndef CONFIG_ARCH_INTERRUPTSTACK
@ -178,12 +184,6 @@ extern void lowconsole_init(void);
# define lowconsole_init() # define lowconsole_init()
#endif #endif
#ifdef CONFIG_RAMLOG_CONSOLE
extern void ramlog_consoleinit(void);
#else
# define ramlog_consoleinit()
#endif
extern void up_lowputc(char ch); extern void up_lowputc(char ch);
extern void up_puts(const char *str); extern void up_puts(const char *str);
extern void up_lowputs(const char *str); extern void up_lowputs(const char *str);

View File

@ -43,6 +43,8 @@
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/fs.h> #include <nuttx/fs.h>
#include <nuttx/ramlog.h>
#include <arch/board/board.h> #include <arch/board/board.h>
#include "up_arch.h" #include "up_arch.h"
@ -159,6 +161,12 @@ void up_initialize(void)
ramlog_consoleinit(); ramlog_consoleinit();
#endif #endif
/* Initialize the system logging device */
#ifdef CONFIG_RAMLOG_SYSLOG
ramlog_sysloginit();
#endif
/* Initialize the netwok */ /* Initialize the netwok */
up_netinitialize(); up_netinitialize();

View File

@ -81,6 +81,12 @@
# endif # endif
#endig #endig
/* Determine which device to use as the system loggin device */
#ifndef CONFIG_SYSLOG
# undef CONFIG_RAMLOG_SYSLOG
#endif
/* Check if an interrupt stack size is configured */ /* Check if an interrupt stack size is configured */
#ifndef CONFIG_ARCH_INTERRUPTSTACK #ifndef CONFIG_ARCH_INTERRUPTSTACK
@ -188,14 +194,6 @@ extern void lowconsole_init(void);
# define lowconsole_init() # define lowconsole_init()
#endif #endif
/* Defined in drivers/ramlog.c */
#ifdef CONFIG_RAMLOG_CONSOLE
extern void ramlog_consoleinit(void);
#else
# define ramlog_consoleinit()
#endif
/* Debug */ /* Debug */
#ifdef CONFIG_ARCH_STACKDUMP #ifdef CONFIG_ARCH_STACKDUMP

View File

@ -43,6 +43,7 @@
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/fs.h> #include <nuttx/fs.h>
#include <nuttx/ramlog.h>
#include "up_arch.h" #include "up_arch.h"
#include "up_internal.h" #include "up_internal.h"
@ -150,6 +151,12 @@ void up_initialize(void)
ramlog_consoleinit(); ramlog_consoleinit();
#endif #endif
/* Initialize the system logging device */
#ifdef CONFIG_RAMLOG_SYSLOG
ramlog_sysloginit();
#endif
/* Initialize the netwok */ /* Initialize the netwok */
up_netinitialize(); up_netinitialize();

View File

@ -85,6 +85,12 @@
# endif # endif
#endig #endig
/* Determine which device to use as the system loggin device */
#ifndef CONFIG_SYSLOG
# undef CONFIG_RAMLOG_SYSLOG
#endif
/* Check if an interrupt stack size is configured */ /* Check if an interrupt stack size is configured */
#ifndef CONFIG_ARCH_INTERRUPTSTACK #ifndef CONFIG_ARCH_INTERRUPTSTACK
@ -177,14 +183,6 @@ extern void lowconsole_init(void);
# define lowconsole_init() # define lowconsole_init()
#endif #endif
/* Defined in drivers/ramlog.c */
#ifdef CONFIG_RAMLOG_CONSOLE
extern void ramlog_consoleinit(void);
#else
# define ramlog_consoleinit()
#endif
/* Defined in up_watchdog.c */ /* Defined in up_watchdog.c */
extern void up_wdtinit(void); extern void up_wdtinit(void);

View File

@ -1,8 +1,8 @@
/**************************************************************************** /****************************************************************************
* up_initialize.c * up_initialize.c
* *
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -43,6 +43,7 @@
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/fs.h> #include <nuttx/fs.h>
#include <nuttx/ramlog.h>
#include "up_internal.h" #include "up_internal.h"
@ -50,6 +51,12 @@
* Private Definitions * Private Definitions
****************************************************************************/ ****************************************************************************/
/* Determine which device to use as the system loggin device */
#ifndef CONFIG_SYSLOG
# undef CONFIG_RAMLOG_SYSLOG
#endif
/**************************************************************************** /****************************************************************************
* Private Data * Private Data
****************************************************************************/ ****************************************************************************/
@ -99,6 +106,10 @@ void up_initialize(void)
devzero_register(); /* Standard /dev/zero */ devzero_register(); /* Standard /dev/zero */
up_devconsole(); /* Our private /dev/console */ up_devconsole(); /* Our private /dev/console */
#ifdef CONFIG_RAMLOG_SYSLOG
ramlog_sysloginit(); /* System logging device */
#endif
#if defined(CONFIG_FS_FAT) && !defined(CONFIG_DISABLE_MOUNTPOINT) #if defined(CONFIG_FS_FAT) && !defined(CONFIG_DISABLE_MOUNTPOINT)
up_registerblockdevice(); /* Our FAT ramdisk at /dev/ram0 */ up_registerblockdevice(); /* Our FAT ramdisk at /dev/ram0 */
#endif #endif

View File

@ -43,6 +43,8 @@
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/fs.h> #include <nuttx/fs.h>
#include <nuttx/ramlog.h>
#include <arch/board/board.h> #include <arch/board/board.h>
#include "up_arch.h" #include "up_arch.h"
@ -159,6 +161,12 @@ void up_initialize(void)
ramlog_consoleinit(); ramlog_consoleinit();
#endif #endif
/* Initialize the system logging device */
#ifdef CONFIG_RAMLOG_SYSLOG
ramlog_sysloginit();
#endif
/* Initialize the netwok */ /* Initialize the netwok */
up_netinitialize(); up_netinitialize();

View File

@ -80,6 +80,12 @@
# endif # endif
#endig #endig
/* Determine which device to use as the system loggin device */
#ifndef CONFIG_SYSLOG
# undef CONFIG_RAMLOG_SYSLOG
#endif
/* Check if an interrupt stack size is configured */ /* Check if an interrupt stack size is configured */
#ifndef CONFIG_ARCH_INTERRUPTSTACK #ifndef CONFIG_ARCH_INTERRUPTSTACK
@ -203,14 +209,6 @@ extern void lowconsole_init(void);
# define lowconsole_init() # define lowconsole_init()
#endif #endif
/* Defined in drivers/ramlog.c */
#ifdef CONFIG_RAMLOG_CONSOLE
extern void ramlog_consoleinit(void);
#else
# define ramlog_consoleinit()
#endif
/* Defined in up_watchdog.c */ /* Defined in up_watchdog.c */
extern void up_wdtinit(void); extern void up_wdtinit(void);

View File

@ -44,6 +44,8 @@
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/fs.h> #include <nuttx/fs.h>
#include <nuttx/mm.h> #include <nuttx/mm.h>
#include <nuttx/ramlog.h>
#include <arch/board/board.h> #include <arch/board/board.h>
#include "up_internal.h" #include "up_internal.h"
@ -174,6 +176,12 @@ void up_initialize(void)
ramlog_consoleinit(); ramlog_consoleinit();
#endif #endif
/* Initialize the system logging device */
#ifdef CONFIG_RAMLOG_SYSLOG
ramlog_sysloginit();
#endif
/* Initialize the netwok */ /* Initialize the netwok */
up_netinitialize(); up_netinitialize();

View File

@ -71,6 +71,12 @@
# define USE_EARLYSERIALINIT 1 # define USE_EARLYSERIALINIT 1
#endif #endif
/* Determine which device to use as the system loggin device */
#ifndef CONFIG_SYSLOG
# undef CONFIG_RAMLOG_SYSLOG
#endif
/* Macros for portability */ /* Macros for portability */
#define IN_INTERRUPT (current_regs != NULL) #define IN_INTERRUPT (current_regs != NULL)
@ -140,12 +146,6 @@ extern void up_serialinit(void);
extern void lowconsole_init(void); extern void lowconsole_init(void);
#endif #endif
/* Defined in drivers/ramlog.c */
#ifdef CONFIG_RAMLOG_CONSOLE
extern void ramlog_consoleinit(void);
#endif
/* Defined in up_timerisr.c */ /* Defined in up_timerisr.c */
extern void up_timerinit(void); extern void up_timerinit(void);

View File

@ -357,6 +357,32 @@ defconfig -- This is a configuration file similar to the Linux
CONFIG_SIG_SIGWORK - The signal number that will be used to wake-up CONFIG_SIG_SIGWORK - The signal number that will be used to wake-up
the worker thread. Default: 4 the worker thread. Default: 4
System Logging:
CONFIG_SYSLOG enables general system logging support.
At present, the only system loggin device is a circular buffer in RAM.
If CONFIG_SYSLOG is selected, then these options are also available.
CONFIG_RAMLOG - Enables the RAM logging feature
CONFIG_RAMLOG_CONSOLE - Use the RAM logging device as a system console.
If this feature is enabled (along with CONFIG_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_SYSLOG - Use the RAM logging device for the syslogging
interface. If this feature is enabled (along with CONFIG_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.
CONFIG_RAMLOG_NPOLLWAITERS - The number of threads than can be waiting
for this driver on poll(). Default: 4
If CONFIG_RAMLOG_CONSOLE or CONFIG_RAMLOG_SYSLOG is selected, then the
following may also be provided:
CONFIG_RAMLOG_CONSOLE_BUFSIZE - Size of the console RAM log. Default: 1024
Kernel build options: Kernel build options:
CONFIG_NUTTX_KERNEL - Builds NuttX as a separately compiled kernel. CONFIG_NUTTX_KERNEL - Builds NuttX as a separately compiled kernel.
CONFIG_SYS_RESERVED - Reserved system call values for use CONFIG_SYS_RESERVED - Reserved system call values for use

View File

@ -93,6 +93,15 @@ struct ramlog_dev_s
/**************************************************************************** /****************************************************************************
* Private Function Prototypes * Private Function Prototypes
****************************************************************************/ ****************************************************************************/
/* Helper functions */
#ifndef CONFIG_DISABLE_POLL
static void ramlog_pollnotify(FAR struct ramlog_dev_s *priv,
pollevent_t eventset);
#endif
static ssize_t ramlog_addchar(FAR struct ramlog_dev_s *priv, char ch);
/* Character driver methods */
static ssize_t ramlog_read(FAR struct file *, FAR char *, size_t); static ssize_t ramlog_read(FAR struct file *, FAR char *, size_t);
static ssize_t ramlog_write(FAR struct file *, FAR const char *, size_t); static ssize_t ramlog_write(FAR struct file *, FAR const char *, size_t);
@ -118,10 +127,13 @@ static const struct file_operations g_ramlogfops =
#endif #endif
}; };
/* This is the pre-allocated buffer used for the console RAM log */ /* This is the pre-allocated buffer used for the console RAM log and/or
* for the syslogging function.
*/
#ifdef CONFIG_RAMLOG_CONSOLE #if defined(CONFIG_RAMLOG_CONSOLE) || defined(CONFIG_RAMLOG_SYSLOG)
static char g_consoleramlog[CONFIG_RAMLOG_CONSOLE_BUFSIZE]; static struct ramlog_dev_s g_sysdev;
static char g_sysbuffer[CONFIG_RAMLOG_CONSOLE_BUFSIZE];
#endif #endif
/**************************************************************************** /****************************************************************************
@ -133,7 +145,8 @@ static char g_consoleramlog[CONFIG_RAMLOG_CONSOLE_BUFSIZE];
****************************************************************************/ ****************************************************************************/
#ifndef CONFIG_DISABLE_POLL #ifndef CONFIG_DISABLE_POLL
static void ramlog_pollnotify(FAR struct ramlog_dev_s *priv, pollevent_t eventset) static void ramlog_pollnotify(FAR struct ramlog_dev_s *priv,
pollevent_t eventset)
{ {
FAR struct pollfd *fds; FAR struct pollfd *fds;
irqstate_t flags; irqstate_t flags;
@ -160,6 +173,46 @@ static void ramlog_pollnotify(FAR struct ramlog_dev_s *priv, pollevent_t eventse
# define ramlog_pollnotify(priv,event) # define ramlog_pollnotify(priv,event)
#endif #endif
/****************************************************************************
* Name: ramlog_addchar
****************************************************************************/
static int ramlog_addchar(FAR struct ramlog_dev_s *priv, char ch)
{
irqstate_t flags;
int nexthead;
/* Disable interrupts (in case we are NOT called from interrupt handler) */
flags = irqsave();
/* Calculate the write index AFTER the next byte is written */
nexthead = priv->rl_head + 1;
if (nexthead >= priv->rl_bufsize)
{
nexthead = 0;
}
/* Would the next write overflow the circular buffer? */
if (nexthead == priv->rl_tail)
{
/* Yes... then break out of the loop to return an indication that
* nothing was saved in the buffer.
*/
return -EBUSY;
}
/* No... copy the byte and re-enable interrupts */
priv->rl_buffer[priv->rl_head] = ch;
priv->rl_head = nexthead;
irqrestore(flags);
return OK;
}
/**************************************************************************** /****************************************************************************
* Name: ramlog_read * Name: ramlog_read
****************************************************************************/ ****************************************************************************/
@ -310,10 +363,12 @@ static ssize_t ramlog_read(FAR struct file *filep, FAR char *buffer, size_t len)
/* Notify all poll/select waiters that they can write to the FIFO */ /* Notify all poll/select waiters that they can write to the FIFO */
errout_without_sem: errout_without_sem:
#ifndef CONFIG_DISABLE_POLL
if (nread > 0) if (nread > 0)
{ {
ramlog_pollnotify(priv, POLLOUT); ramlog_pollnotify(priv, POLLOUT);
} }
#endif
return nread; return nread;
} }
@ -327,7 +382,6 @@ static ssize_t ramlog_write(FAR struct file *filep, FAR const char *buffer, size
struct ramlog_dev_s *priv; struct ramlog_dev_s *priv;
irqstate_t flags; irqstate_t flags;
ssize_t nwritten; ssize_t nwritten;
int nexthead;
int i; int i;
/* Some sanity checking */ /* Some sanity checking */
@ -346,34 +400,16 @@ static ssize_t ramlog_write(FAR struct file *filep, FAR const char *buffer, size
for (nwritten = 0; nwritten < len; nwritten++) for (nwritten = 0; nwritten < len; nwritten++)
{ {
/* Disable interrupts (in case we are NOT called from interrupt handler) */ int ret = ramlog_addchar(priv, buffer[nwritten]);
if (ret < 0)
flags = irqsave();
/* Calculate the write index AFTER the next byte is written */
nexthead = priv->rl_head + 1;
if (nexthead >= priv->rl_bufsize)
{ {
nexthead = 0; /* The buffer is full and nothing was saved. Break out of the
} * loop to return the number of bytes written up to this point.
* The data to be written is dropped on the floor.
/* Would the next write overflow the circular buffer? */
if (nexthead == priv->rl_tail)
{
/* Yes... then break out of the loop to return the number of bytes
* written. The data to be written is dropped on the floor.
*/ */
return nwritten; break;
} }
/* No... copy the byte and re-enable interrupts */
priv->rl_buffer[priv->rl_head] = buffer[nwritten];
priv->rl_head = nexthead;
irqrestore(flags);
} }
/* Was anything written? */ /* Was anything written? */
@ -393,6 +429,7 @@ static ssize_t ramlog_write(FAR struct file *filep, FAR const char *buffer, size
/* Notify all poll/select waiters that they can write to the FIFO */ /* Notify all poll/select waiters that they can write to the FIFO */
ramlog_pollnotify(priv, POLLIN); ramlog_pollnotify(priv, POLLIN);
irqrestore(flags);
} }
/* Return the number of bytes written */ /* Return the number of bytes written */
@ -526,6 +563,7 @@ errout:
* *
****************************************************************************/ ****************************************************************************/
#if !defined(CONFIG_RAMLOG_CONSOLE) && !defined(CONFIG_RAMLOG_SYSLOG)
int ramlog_register(FAR const char *devpath, FAR char *buffer, size_t buflen) int ramlog_register(FAR const char *devpath, FAR char *buffer, size_t buflen)
{ {
FAR struct ramlog_dev_s *priv; FAR struct ramlog_dev_s *priv;
@ -558,6 +596,7 @@ int ramlog_register(FAR const char *devpath, FAR char *buffer, size_t buflen)
return ret; return ret;
} }
#endif
/**************************************************************************** /****************************************************************************
* Name: ramlog_consoleinit * Name: ramlog_consoleinit
@ -571,10 +610,57 @@ int ramlog_register(FAR const char *devpath, FAR char *buffer, size_t buflen)
#ifdef CONFIG_RAMLOG_CONSOLE #ifdef CONFIG_RAMLOG_CONSOLE
int ramlog_consoleinit(void) int ramlog_consoleinit(void)
{ {
/* Register a RAM log as the console device */ FAR struct ramlog_dev_s *priv = &g_sysdev;
int ret;
return ramlog_register("/dev/console", g_consoleramlog, /* Initialize the RAM loggin device structure */
CONFIG_RAMLOG_CONSOLE_BUFSIZE);
sem_init(&priv->rl_exclsem, 0, 1);
sem_init(&priv->rl_waitsem, 0, 0);
priv->rl_bufsize = g_sysbuffer;
priv->rl_buffer = CONFIG_RAMLOG_CONSOLE_BUFSIZE;
/* Register the console character driver */
ret = register_driver("/dev/console", &g_ramlogfops, 0666, priv);
/* Register the syslog character driver */
#ifdef CONFIG_RAMLOG_SYSLOG
if (ret >= 0)
{
ret = register_driver("/dev/syslog", &g_ramlogfops, 0666, priv);
}
#endif
return ret;
}
#endif
/****************************************************************************
* Name: ramlog_sysloginit
*
* Description:
* Create the RAM logging device and register it at the specified path.
* Mostly likely this path will be /dev/syslog
*
* If CONFIG_RAMLOG_CONSOLE is also defined, then this functionality is
* performed when ramlog_consoleinit() is called.
*
****************************************************************************/
#if !defined(CONFIG_RAMLOG_CONSOLE) && defined(CONFIG_RAMLOG_SYSLOG)
int ramlog_sysloginit(void)
{
FAR struct ramlog_dev_s *priv = &g_sysdev;
/* Initialize the RAM loggin device structure */
sem_init(&priv->rl_exclsem, 0, 1);
sem_init(&priv->rl_waitsem, 0, 0);
priv->rl_bufsize = g_sysbuffer;
priv->rl_buffer = CONFIG_RAMLOG_CONSOLE_BUFSIZE;
return register_driver("/dev/syslog", &g_ramlogfops, 0666, priv);
} }
#endif #endif
@ -591,8 +677,13 @@ int ramlog_consoleinit(void)
* *
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_RAMLOG_SYSLOG #if defined(CONFIG_RAMLOG_CONSOLE) || defined(CONFIG_RAMLOG_SYSLOG)
# warning "Missing logic" int ramlog_putc(int ch)
{
FAR struct ramlog_dev_s *priv = &g_sysdev;
(void)ramlog_addchar(priv, ch)
return ch;
}
#endif #endif
#endif /* CONFIG_RAMLOG */ #endif /* CONFIG_RAMLOG */

View File

@ -2,8 +2,8 @@
* include/nuttx/lib.h * include/nuttx/lib.h
* Non-standard, internal APIs available in lib/. * Non-standard, internal APIs available in lib/.
* *
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2009, 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -34,8 +34,8 @@
* *
****************************************************************************/ ****************************************************************************/
#ifndef __LIB_H #ifndef __INCLUDE_NUTTX_LIB_H
#define __LIB_H #define __INCLUDE_NUTTX_LIB_H
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
@ -80,4 +80,4 @@ EXTERN void lib_releaselist(FAR struct streamlist *list);
#endif #endif
#endif /* __ASSEMBLY__ */ #endif /* __ASSEMBLY__ */
#endif /* __LIB_H */ #endif /* __INCLUDE_NUTTX_LIB_H */

View File

@ -63,18 +63,33 @@
/* Configuration ************************************************************/ /* Configuration ************************************************************/
/* CONFIG_RAMLOG - Enables the RAM logging feature /* CONFIG_RAMLOG - Enables the RAM logging feature
* CONFIG_RAMLOG_CONSOLE - Use the RAM logging device as a system console. * CONFIG_RAMLOG_CONSOLE - Use the RAM logging device as a system console.
* If this feature is enabled (along with CONFIG_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_SYSLOG - Use the RAM logging device for the syslogging * CONFIG_RAMLOG_SYSLOG - Use the RAM logging device for the syslogging
* interface. This should have: * interface. If this feature is enabled (along with CONFIG_SYSLOG),
* CONFIG_SYSLOG=ramlog * 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.
* CONFIG_RAMLOG_NPOLLWAITERS - The number of threads than can be waiting * CONFIG_RAMLOG_NPOLLWAITERS - The number of threads than can be waiting
* for this driver on poll(). Default: 4 * for this driver on poll(). Default: 4
* *
* If CONFIG_RAMLOG_CONSOLE is selected, then the following may also be * If CONFIG_RAMLOG_CONSOLE or CONFIG_RAMLOG_SYSLOG is selected, then the
* provided: * following may also be provided:
* *
* CONFIG_RAMLOG_CONSOLE_BUFSIZE - Size of the console RAM log. Default: 1024 * CONFIG_RAMLOG_CONSOLE_BUFSIZE - Size of the console RAM log. Default: 1024
*/ */
#ifndef CONFIG_DEV_CONSOLE
# undef CONFIG_RAMLOG_CONSOLE
#endif
#ifndef CONFIG_SYSLOG
# undef CONFIG_RAMLOG_SYSLOG
#endif
#ifndef CONFIG_RAMLOG_NPOLLWAITERS #ifndef CONFIG_RAMLOG_NPOLLWAITERS
# define CONFIG_RAMLOG_NPOLLWAITERS 4 # define CONFIG_RAMLOG_NPOLLWAITERS 4
#endif #endif
@ -104,19 +119,31 @@ extern "C" {
* *
* Description: * Description:
* Create the RAM logging device and register it at the specified path. * Create the RAM logging device and register it at the specified path.
* Mostly likely this path will be /dev/console * Mostly likely this path will be /dev/console.
*
* This interface is not normally used but can be made available is
* someone just wants to tinker with the RAM log as a generic character
* device. Normally both CONFIG_RAMLOG_CONSOLE and CONFIG_RAMLOG_SYSLOG
* would be set (to capture all output in the log) -OR- just
* CONFIG_RAMLOG_SYSLOG would be set to capture debug output only
* in the log.
* *
****************************************************************************/ ****************************************************************************/
#if !defined(CONFIG_RAMLOG_CONSOLE) && !defined(CONFIG_RAMLOG_SYSLOG)
EXTERN int ramlog_register(FAR const char *devpath, FAR char *buffer, EXTERN int ramlog_register(FAR const char *devpath, FAR char *buffer,
size_t buflen); size_t buflen);
#endif
/**************************************************************************** /****************************************************************************
* Name: ramlog_consoleinit * Name: ramlog_consoleinit
* *
* Description: * Description:
* Create the RAM logging device and register it at the specified path. * Create the RAM logging device and register it at the specified path.
* Mostly likely this path will be /dev/console * Mostly likely this path will be /dev/console.
*
* If CONFIG_RAMLOG_SYSLOG is also defined, then the same RAM logging
* device is also registered at /dev/syslog
* *
****************************************************************************/ ****************************************************************************/
@ -124,6 +151,22 @@ EXTERN int ramlog_register(FAR const char *devpath, FAR char *buffer,
EXTERN int ramlog_consoleinit(void) EXTERN int ramlog_consoleinit(void)
#endif #endif
/****************************************************************************
* Name: ramlog_sysloginit
*
* Description:
* Create the RAM logging device and register it at the specified path.
* Mostly likely this path will be /dev/syslog
*
* If CONFIG_RAMLOG_CONSOLE is also defined, then this functionality is
* performed when ramlog_consoleinit() is called.
*
****************************************************************************/
#if !defined(CONFIG_RAMLOG_CONSOLE) && defined(CONFIG_RAMLOG_SYSLOG)
EXTERN int ramlog_sysloginit(void)
#endif
/**************************************************************************** /****************************************************************************
* Name: ramlog * Name: ramlog
* *
@ -137,8 +180,8 @@ EXTERN int ramlog_consoleinit(void)
* *
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_RAMLOG_SYSLOG #if defined(CONFIG_RAMLOG_CONSOLE) || defined(CONFIG_RAMLOG_SYSLOG)
# warning "Missing logic" EXTERN int ramlog_putc(int ch);
#endif #endif
#undef EXTERN #undef EXTERN

View File

@ -1,8 +1,8 @@
/**************************************************************************** /****************************************************************************
* include/nuttx/streams.h * include/nuttx/streams.h
* *
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. * Copyright (C) 2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -268,6 +268,25 @@ EXTERN void lib_zeroinstream(FAR struct lib_instream_s *zeroinstream);
EXTERN void lib_nullinstream(FAR struct lib_instream_s *nullinstream); EXTERN void lib_nullinstream(FAR struct lib_instream_s *nullinstream);
EXTERN void lib_nulloutstream(FAR struct lib_outstream_s *nulloutstream); EXTERN void lib_nulloutstream(FAR struct lib_outstream_s *nulloutstream);
/****************************************************************************
* Name: lib_sylogstream
*
* Description:
* Initializes a stream for use with the configured syslog interface.
*
* Input parameters:
* lowoutstream - User allocated, uninitialized instance of struct
* lib_lowoutstream_s to be initialized.
*
* Returned Value:
* None (User allocated instance initialized).
*
****************************************************************************/
#ifdef CONFIG_SYSLOG
EXTERN void lib_sylogstream(FAR struct lib_outstream_s *stream);
#endif
#undef EXTERN #undef EXTERN
#if defined(__cplusplus) #if defined(__cplusplus)
} }

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
endif endif
ifdef ($(CONFIG_SYSLOG)
STDIO_SRCS += lib_syslogstream.c
endif
ifeq ($(CONFIG_LIBC_FLOATINGPOINT),y) ifeq ($(CONFIG_LIBC_FLOATINGPOINT),y)
STDIO_SRCS += lib_dtoa.c STDIO_SRCS += lib_dtoa.c
endif endif

View File

@ -1,8 +1,8 @@
/**************************************************************************** /****************************************************************************
* lib/stdio/lib_lowprintf.c * lib/stdio/lib_lowprintf.c
* *
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -82,17 +82,19 @@
* Name: lib_lowvprintf * Name: lib_lowvprintf
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_ARCH_LOWPUTC #if defined(CONFIG_ARCH_LOWPUTC) || defined(CONFIG_SYSLOG)
int lib_lowvprintf(const char *fmt, va_list ap) int lib_lowvprintf(const char *fmt, va_list ap)
{ {
struct lib_outstream_s stream; struct lib_outstream_s stream;
/* Wrap the stdout in a stream object and let lib_vsprintf /* Wrap the stdout in a stream object and let lib_vsprintf do the work. */
* 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); lib_lowoutstream((FAR struct lib_outstream_s *)&stream);
#endif
return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap); return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap);
} }
@ -111,4 +113,4 @@ int lib_lowprintf(const char *fmt, ...)
return ret; return ret;
} }
#endif /* CONFIG_ARCH_LOWPUTC */ #endif /* CONFIG_ARCH_LOWPUTC || CONFIG_SYSLOG*/

View File

@ -1,8 +1,8 @@
/**************************************************************************** /****************************************************************************
* lib/stdio/lib_rawprintf.c * lib/stdio/lib_rawprintf.c
* *
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -83,7 +83,18 @@
int lib_rawvprintf(const char *fmt, va_list ap) 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; struct lib_rawoutstream_s rawoutstream;

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 */

View File

@ -1,8 +1,8 @@
/**************************************************************************** /****************************************************************************
* tools/mkconfig.c * tools/mkconfig.c
* *
* Copyright (C) 2007-2011 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -144,7 +144,13 @@ int main(int argc, char **argv, char **envp)
printf("# if CONFIG_NFILE_STREAMS > 0 && CONFIG_NFILE_STREAMS < 3\n"); printf("# if CONFIG_NFILE_STREAMS > 0 && CONFIG_NFILE_STREAMS < 3\n");
printf("# undef CONFIG_NFILE_STREAMS\n"); printf("# undef CONFIG_NFILE_STREAMS\n");
printf("# define CONFIG_NFILE_STREAMS 3\n"); printf("# define CONFIG_NFILE_STREAMS 3\n");
printf("# endif\n"); printf("# endif\n\n");
printf("/* If no console is selected, then disable all console devices */\n\n");
printf("#else\n");
printf("# undef CONFIG_DEV_LOWCONSOLE\n");
printf("# undef CONFIG_RAMLOG_CONSOLE\n");
printf("# undef CONFIG_CDCACM_CONSOLE\n");
printf("# undef CONFIG_PL2303_CONSOLE\n");
printf("#endif\n\n"); printf("#endif\n\n");
printf("/* If priority inheritance is disabled, then do not allocate any\n"); printf("/* If priority inheritance is disabled, then do not allocate any\n");
printf(" * associated resources.\n"); printf(" * associated resources.\n");