linguini1 commented on code in PR #16493: URL: https://github.com/apache/nuttx/pull/16493#discussion_r2143242089
########## drivers/syslog/vsyslog_rfc5424.c: ########## @@ -0,0 +1,258 @@ +/**************************************************************************** + * drivers/syslog/vsyslog_rfc5424.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 <nuttx/config.h> + +#include <errno.h> +#include <stdio.h> +#include <syslog.h> + +#include <nuttx/arch.h> +#include <nuttx/clock.h> +#include <nuttx/init.h> +#include <nuttx/streams.h> +#include <nuttx/syslog/syslog.h> + +#include "syslog.h" + +/**************************************************************************** + * Preprocessor definitions + ****************************************************************************/ + +/* RFC5424 NILVALUE encoding */ + +#define NILVALUE "-" +#define NILVALUE_SPACE NILVALUE " " + +/* RFC5424 timestamp format string (fractional seconds and 'Z' added by + * appending to format string) + */ + +#define RFC_STRFTIME "%Y-%m-%dT%H:%M:%S" + +/* RFC5424 structured data options were selected */ + +#if defined(CONFIG_SYSLOG_RFC5424_TIMEQUALITY) +#define HAVE_RFC5424_SDATA 1 +#else +#define HAVE_RFC5424_SDATA 0 +#endif /* defined(CONFIG_SYSLOG_RFC5424_TIMEQUALITY) || ... */ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_vsyslog + * + * Description: + * nx_vsyslog() handles the system logging system calls. It is functionally + * equivalent to vsyslog() except that (1) the per-process priority + * filtering has already been performed and the va_list parameter is + * passed by reference. That is because the va_list is a structure in + * some compilers and passing of structures in the NuttX sycalls does + * not work. + * + ****************************************************************************/ + +int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap) +{ + struct lib_syslograwstream_s stream; + int ret = 0; +#ifdef CONFIG_SYSLOG_PROCESS_NAME + FAR struct tcb_s *tcb = nxsched_self(); +#endif +#ifdef CONFIG_SYSLOG_TIMESTAMP + struct timespec ts = + { + 0 + }; + + struct tm tm = + { + 0 + }; + + char date_buf[64]; +#endif +#ifdef CONFIG_SYSLOG_RFC5424_HOSTNAME + char hostname_buf[HOST_NAME_MAX + 1]; +#endif + + /* Wrap the low-level output in a stream object and let lib_vsprintf + * do the work. + */ + + lib_syslograwstream_open(&stream); + +#ifdef CONFIG_SYSLOG_TIMESTAMP + + /* Get the current time. Since debug output may be generated very early + * in the start-up sequence, hardware timer support may not yet be + * available. + */ + + if (OSINIT_HW_READY()) + { + /* Use CLOCK_REALTIME if so configured */ + + clock_gettime(CLOCK_REALTIME, &ts); + + /* Prepend the message with the current time, if available */ + + gmtime_r(&ts.tv_sec, &tm); + } + + /* Generate the timestamp string */ + + date_buf[0] = '\0'; Review Comment: Copied from original implementation, not needed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org