2023-05-23 16:41:10 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* libs/libc/stream/lib_syslogstream.c
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
|
|
|
|
#include <nuttx/streams.h>
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: syslogstream_putc
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-09-10 21:32:34 +02:00
|
|
|
static void syslogstream_putc(FAR struct lib_outstream_s *self, int ch)
|
2023-05-23 16:41:10 +02:00
|
|
|
{
|
|
|
|
FAR struct lib_syslogstream_s *stream =
|
2023-09-10 21:32:34 +02:00
|
|
|
(FAR struct lib_syslogstream_s *)self;
|
2023-05-23 16:41:10 +02:00
|
|
|
|
|
|
|
DEBUGASSERT(stream != NULL);
|
|
|
|
syslog(stream->priority, "%c", ch);
|
2023-09-10 21:32:34 +02:00
|
|
|
stream->common.nput++;
|
2023-05-23 16:41:10 +02:00
|
|
|
}
|
|
|
|
|
2023-09-10 21:32:34 +02:00
|
|
|
static int syslogstream_puts(FAR struct lib_outstream_s *self,
|
2023-05-23 16:41:10 +02:00
|
|
|
FAR const void *buff, int len)
|
|
|
|
{
|
|
|
|
FAR struct lib_syslogstream_s *stream =
|
2023-09-10 21:32:34 +02:00
|
|
|
(FAR struct lib_syslogstream_s *)self;
|
2023-05-23 16:41:10 +02:00
|
|
|
|
|
|
|
DEBUGASSERT(stream != NULL);
|
|
|
|
if (len <= 0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
syslog(stream->priority, "%.*s", len, (FAR const char *)buff);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: lib_syslogstream
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Initializes syslog stream
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* stream - User allocated, uninitialized instance of struct
|
|
|
|
* lib_syslogstream_s to be initialized.
|
|
|
|
* priority - log priority.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None (User allocated instance initialized).
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void lib_syslogstream(FAR struct lib_syslogstream_s *stream, int priority)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(stream != NULL);
|
|
|
|
|
|
|
|
/* Initialize the common fields */
|
|
|
|
|
2023-09-10 21:32:34 +02:00
|
|
|
stream->common.nput = 0;
|
|
|
|
stream->common.putc = syslogstream_putc;
|
|
|
|
stream->common.puts = syslogstream_puts;
|
|
|
|
stream->common.flush = lib_noflush;
|
2023-05-23 16:41:10 +02:00
|
|
|
stream->priority = priority;
|
|
|
|
}
|