Move syslog logic from libc/misc and libc/stdio to libc/syslog

This commit is contained in:
Gregory Nutt 2014-10-08 17:16:41 -06:00
parent 176491ce75
commit a8399d5c6b
12 changed files with 240 additions and 80 deletions

View File

@ -124,7 +124,6 @@ extern "C"
#if 0 /* Not supported */
void openlog(FAR const char *ident, int option, int facility);
void closelog(void);
int setlogmask(int mask);
#endif
/* These low-level debug APIs are provided by the NuttX library. These are
@ -162,6 +161,12 @@ int lowvsyslog(int priority, FAR const char *format, va_list ap);
# define lowvsyslog(p,f,a) vsyslog(p,f,a)
#endif
/* The setlogmask() function sets the logmask and returns the previous
* mask. If the mask argument is 0, the current logmask is not modified.
*/
int setlogmask(int mask);
/* Enable or disable syslog output */
#ifdef CONFIG_SYSLOG_ENABLE /* Non-standard */

View File

@ -65,6 +65,7 @@ include stdio/Make.defs
include stdlib/Make.defs
include unistd/Make.defs
include sched/Make.defs
include syslog/Make.defs
include string/Make.defs
include aio/Make.defs
include pthread/Make.defs

View File

@ -137,12 +137,6 @@ extern "C"
#define EXTERN extern
#endif
/* Debug output is initially disabled */
#ifdef CONFIG_SYSLOG_ENABLE
EXTERN bool g_syslogenable;
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/

View File

@ -59,9 +59,11 @@ endif
# Add the miscellaneous C files to the build
CSRCS += lib_match.c
CSRCS += lib_crc32.c lib_crc16.c
CSRCS += lib_dbg.c lib_dumpbuffer.c
CSRCS += lib_match.c lib_crc32.c lib_crc16.c lib_dumpbuffer.c
ifeq ($(CONFIG_DEBUG),y)
CSRCS += lib_dbg.c
endif
# Keyboard driver encoder/decoder

View File

@ -44,35 +44,16 @@
#include "lib_internal.h"
/****************************************************************************
* Global Variables
****************************************************************************/
/* Debug output is initially disabled */
#ifdef CONFIG_SYSLOG_ENABLE
bool g_syslogenable;
#endif
#ifndef CONFIG_CPP_HAVE_VARARGS
/****************************************************************************
* Global Functions
* Public Data
****************************************************************************/
/****************************************************************************
* Name: syslog_enable
*
* Description:
* Enable or disable debug output.
*
* Public Functions
****************************************************************************/
#ifdef CONFIG_SYSLOG_ENABLE
void syslog_enable(bool enable)
{
g_syslogenable = enable;
}
#endif
/****************************************************************************
* Name: dbg, lldbg, vdbg
*
@ -82,22 +63,15 @@ void syslog_enable(bool enable)
*
****************************************************************************/
#ifndef CONFIG_CPP_HAVE_VARARGS
#ifdef CONFIG_DEBUG
int dbg(const char *format, ...)
{
va_list ap;
int ret;
#ifdef CONFIG_SYSLOG_ENABLE
ret = 0;
if (g_syslogenable)
#endif
{
va_start(ap, format);
ret = vsyslog(LOG_DEBUG, format, ap);
va_end(ap);
}
va_start(ap, format);
ret = vsyslog(LOG_DEBUG, format, ap);
va_end(ap);
return ret;
}
@ -108,15 +82,9 @@ int lldbg(const char *format, ...)
va_list ap;
int ret;
#ifdef CONFIG_SYSLOG_ENABLE
ret = 0;
if (g_syslogenable)
#endif
{
va_start(ap, format);
ret = lowvsyslog(LOG_DEBUG, format, ap);
va_end(ap);
}
va_start(ap, format);
ret = lowvsyslog(LOG_DEBUG, format, ap);
va_end(ap);
return ret;
}
@ -128,15 +96,9 @@ int vdbg(const char *format, ...)
va_list ap;
int ret;
#ifdef CONFIG_SYSLOG_ENABLE
ret = 0;
if (g_syslogenable)
#endif
{
va_start(ap, format);
ret = vsyslog(LOG_DEBUG, format, ap);
va_end(ap);
}
va_start(ap, format);
ret = vsyslog(LOG_DEBUG, format, ap);
va_end(ap);
return ret;
}
@ -147,15 +109,9 @@ int llvdbg(const char *format, ...)
va_list ap;
int ret;
#ifdef CONFIG_SYSLOG_ENABLE
ret = 0;
if (g_syslogenable)
#endif
{
va_start(ap, format);
ret = lowvsyslog(LOG_DEBUG, format, ap);
va_end(ap);
}
va_start(ap, format);
ret = lowvsyslog(LOG_DEBUG, format, ap);
va_end(ap);
return ret;
}

View File

@ -37,10 +37,9 @@
# This first group of C files do not depend on having file descriptors or
# C streams.
CSRCS += lib_fileno.c lib_printf.c lib_syslog.c lib_lowsyslog.c
CSRCS += lib_sprintf.c lib_asprintf.c lib_snprintf.c lib_libsprintf.c
CSRCS += lib_vsprintf.c lib_avsprintf.c lib_vsnprintf.c lib_libvsprintf.c
CSRCS += lib_dprintf.c lib_vdprintf.c
CSRCS += lib_fileno.c lib_printf.c lib_sprintf.c lib_asprintf.c
CSRCS += lib_snprintf.c lib_libsprintf.c lib_vsprintf.c lib_avsprintf.c
CSRCS += lib_vsnprintf.c lib_libvsprintf.c lib_dprintf.c lib_vdprintf.c
CSRCS += lib_meminstream.c lib_memoutstream.c lib_memsistream.c
CSRCS += lib_memsostream.c lib_lowinstream.c lib_lowoutstream.c
CSRCS += lib_zeroinstream.c lib_nullinstream.c lib_nulloutstream.c
@ -71,10 +70,6 @@ endif
# Other support that depends on specific, configured features.
ifeq ($(CONFIG_SYSLOG),y)
CSRCS += lib_syslogstream.c
endif
ifeq ($(CONFIG_LIBC_FLOATINGPOINT),y)
CSRCS += lib_dtoa.c
endif

51
libc/syslog/Make.defs Normal file
View File

@ -0,0 +1,51 @@
############################################################################
# libc/syslog/Make.defs
#
# Copyright (C) 2014 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
# 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.
#
############################################################################
# Add the internal C files to the build
CSRCS += lib_syslog.c lib_lowsyslog.c
ifeq ($(CONFIG_SYSLOG),y)
CSRCS += lib_syslogstream.c
endif
ifeq ($(CONFIG_SYSLOG_ENABLE),y)
CSRCS += lib_syslogenable.c
endif
# Add the syslog directory to the build
DEPPATH += --dep-path syslog
VPATH += :syslog

View File

@ -1,5 +1,5 @@
/****************************************************************************
* libc/stdio/lib_lowsyslog.c
* libc/syslog/lib_lowsyslog.c
*
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>

View File

@ -1,5 +1,5 @@
/****************************************************************************
* libc/stdio/lib_syslog.c
* libc/syslog/lib_syslog.c
*
* Copyright (C) 2007-2009, 2011-2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@ -43,6 +43,7 @@
#include <syslog.h>
#include "lib_internal.h"
#include "syslog/syslog.h"
/****************************************************************************
* Pre-processor Definitions

View File

@ -0,0 +1,73 @@
/****************************************************************************
* libc/syslog/lib_syslogenable.c
*
* 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
* 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 <stdbool.h>
#include "lib_internal.h"
#ifdef CONFIG_SYSLOG_ENABLE
/****************************************************************************
* Public Data
****************************************************************************/
/* Debug output is initially disabled */
bool g_syslogenable;
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: syslog_enable
*
* Description:
* Enable or disable debug output.
*
****************************************************************************/
void syslog_enable(bool enable)
{
g_syslogenable = enable;
}
#endif /* CONFIG_SYSLOG_ENABLE */

View File

@ -1,5 +1,5 @@
/****************************************************************************
* libc/stdio/lib_syslogstream.c
* libc/syslog/lib_syslogstream.c
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@ -46,6 +46,7 @@
#include <nuttx/syslog/syslog.h>
#include "lib_internal.h"
#include "syslog/syslog.h"
#ifdef CONFIG_SYSLOG

81
libc/syslog/syslog.h Normal file
View File

@ -0,0 +1,81 @@
/****************************************************************************
* libc/syslog/syslog.h
*
* Copyright (C) 2014 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
* 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.
*
****************************************************************************/
#ifndef __LIBC_SYSLOG_SYSLOG_H
#define __LIBC_SYSLOG_SYSLOG_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/* Debug output is initially disabled */
#ifdef CONFIG_SYSLOG_ENABLE
EXTERN bool g_syslogenable;
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __LIBC_SYSLOG_SYSLOG_H */