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:
Chris Johns 2016-06-30 09:14:55 +10:00
parent 90873cc802
commit 4a2b84469e
2 changed files with 40 additions and 6 deletions

View File

@ -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);
/**
* @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

View File

@ -37,25 +37,35 @@
* SUCH DAMAGE.
*/
#include <errno.h>
#include <stddef.h>
#include <strings.h>
#define SYSLOG_NAMES
#include <syslog.h>
#include <rtems/bsd/bsd.h>
static int syslog_priority = LOG_NOTICE;
void
syslog(int priority, const char *format, ...)
{
va_list ap;
if (priority <= syslog_priority) {
va_list ap;
va_start(ap, format);
vsyslog(priority, format, ap);
va_end(ap);
va_start(ap, format);
vsyslog(priority, format, ap);
va_end(ap);
}
}
void
vsyslog(int priority, const char *format, va_list ap)
{
rtems_bsd_vprintf(priority, format, ap);
if (priority <= syslog_priority) {
rtems_bsd_vprintf(priority, format, ap);
}
}
void
@ -75,3 +85,18 @@ setlogmask(int mask)
{
/* 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;
}