mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-06-05 18:30:23 +08:00
Default syslog priority to INFO. Add rtems_setlogpriority to configure the priority.
The rc.conf has 'syslog_priority' where the priority is the name, eg syslog_priority="debug" sets the priority to "debug".
This commit is contained in:
parent
90873cc802
commit
4a2b84469e
@ -221,6 +221,15 @@ void rtems_bsd_set_vprintf_handler(int (*new_vprintf_handler)
|
|||||||
*/
|
*/
|
||||||
int rtems_bsd_vprintf(int level, const char *fmt, va_list ap);
|
int rtems_bsd_vprintf(int level, const char *fmt, va_list ap);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the syslog priority. See syslog.h for the names.
|
||||||
|
*
|
||||||
|
* @param priority One of the standard names.
|
||||||
|
* @retval 0 Priority set.
|
||||||
|
* @retval errno Otherwise.
|
||||||
|
*/
|
||||||
|
int rtems_bsd_setlogpriority(const char* priority);
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -37,25 +37,35 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <strings.h>
|
||||||
|
|
||||||
|
#define SYSLOG_NAMES
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
#include <rtems/bsd/bsd.h>
|
#include <rtems/bsd/bsd.h>
|
||||||
|
|
||||||
|
static int syslog_priority = LOG_NOTICE;
|
||||||
|
|
||||||
void
|
void
|
||||||
syslog(int priority, const char *format, ...)
|
syslog(int priority, const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
if (priority <= syslog_priority) {
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
vsyslog(priority, format, ap);
|
vsyslog(priority, format, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
vsyslog(int priority, const char *format, va_list ap)
|
vsyslog(int priority, const char *format, va_list ap)
|
||||||
{
|
{
|
||||||
|
if (priority <= syslog_priority) {
|
||||||
rtems_bsd_vprintf(priority, format, ap);
|
rtems_bsd_vprintf(priority, format, ap);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -75,3 +85,18 @@ setlogmask(int mask)
|
|||||||
{
|
{
|
||||||
/* TODO */
|
/* TODO */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
rtems_bsd_setlogpriority(const char* priority)
|
||||||
|
{
|
||||||
|
CODE* c = &prioritynames[0];
|
||||||
|
while (c->c_name != NULL) {
|
||||||
|
if (strcasecmp(c->c_name, priority) == 0) {
|
||||||
|
syslog_priority = c->c_val;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
++c;
|
||||||
|
}
|
||||||
|
errno = ENOENT;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user