xiaoxiang781216 commented on code in PR #21128:
URL: https://github.com/apache/nuttx/pull/21128#discussion_r4429591890
##########
drivers/syslog/syslog.h:
##########
@@ -53,6 +59,58 @@ const
#endif
g_syslog_channel[CONFIG_SYSLOG_MAX_CHANNELS];
+/****************************************************************************
+ * Inline Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: syslog_add_openlog
+ *
+ * Description:
+ * Output the ident that the task group set with openlog() and, with
+ * LOG_PID, its process ID: "ident: " or "ident[pid]: ". The caller is
+ * in a syslog() call of that task group, so its task information is in
+ * memory. openlog() does not lock out this reader: the ident is read up
+ * to its maximum length. Nothing in an interrupt handler.
+ *
+ ****************************************************************************/
+
+static inline int syslog_add_openlog(FAR struct lib_outstream_s *stream)
+{
+ FAR struct task_info_s *info;
+ FAR struct tcb_s *tcb;
+ int option;
+
+ if (up_interrupt_context())
+ {
+ return 0;
+ }
+
+ tcb = nxsched_self();
+ if (tcb == NULL || tcb->group == NULL || tcb->group->tg_info == NULL)
+ {
+ return 0;
+ }
+
+ info = tcb->group->tg_info;
+ option = info->ta_openlog.ol_option;
+ if ((option & LOG_PID) != 0)
+ {
+ return lib_sprintf_internal(stream, "%.*s[%d]: ",
+ OPENLOG_IDENT_SIZE - 1,
+ info->ta_openlog.ol_ident,
+ (int)tcb->group->tg_pid);
+ }
+
+ if (info->ta_openlog.ol_ident[0] != '\0')
+ {
+ return lib_sprintf_internal(stream, "%.*s: ", OPENLOG_IDENT_SIZE - 1,
Review Comment:
could we ensure ol_ident end with '\0'
##########
drivers/syslog/syslog.h:
##########
@@ -53,6 +59,58 @@ const
#endif
g_syslog_channel[CONFIG_SYSLOG_MAX_CHANNELS];
+/****************************************************************************
+ * Inline Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: syslog_add_openlog
+ *
+ * Description:
+ * Output the ident that the task group set with openlog() and, with
+ * LOG_PID, its process ID: "ident: " or "ident[pid]: ". The caller is
+ * in a syslog() call of that task group, so its task information is in
+ * memory. openlog() does not lock out this reader: the ident is read up
+ * to its maximum length. Nothing in an interrupt handler.
+ *
+ ****************************************************************************/
+
+static inline int syslog_add_openlog(FAR struct lib_outstream_s *stream)
+{
+ FAR struct task_info_s *info;
+ FAR struct tcb_s *tcb;
+ int option;
+
+ if (up_interrupt_context())
+ {
+ return 0;
+ }
+
+ tcb = nxsched_self();
+ if (tcb == NULL || tcb->group == NULL || tcb->group->tg_info == NULL)
+ {
+ return 0;
+ }
+
+ info = tcb->group->tg_info;
+ option = info->ta_openlog.ol_option;
+ if ((option & LOG_PID) != 0)
+ {
+ return lib_sprintf_internal(stream, "%.*s[%d]: ",
+ OPENLOG_IDENT_SIZE - 1,
+ info->ta_openlog.ol_ident,
Review Comment:
why not merge to
https://github.com/apache/nuttx/pull/21128/changes/94dc99d156b403a0e75cd32cdc83e81e64f40e14#r4429625636
##########
drivers/syslog/syslog.h:
##########
@@ -53,6 +59,58 @@ const
#endif
g_syslog_channel[CONFIG_SYSLOG_MAX_CHANNELS];
+/****************************************************************************
+ * Inline Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: syslog_add_openlog
+ *
+ * Description:
+ * Output the ident that the task group set with openlog() and, with
+ * LOG_PID, its process ID: "ident: " or "ident[pid]: ". The caller is
+ * in a syslog() call of that task group, so its task information is in
+ * memory. openlog() does not lock out this reader: the ident is read up
+ * to its maximum length. Nothing in an interrupt handler.
+ *
+ ****************************************************************************/
+
+static inline int syslog_add_openlog(FAR struct lib_outstream_s *stream)
+{
+ FAR struct task_info_s *info;
+ FAR struct tcb_s *tcb;
+ int option;
+
+ if (up_interrupt_context())
+ {
+ return 0;
+ }
+
+ tcb = nxsched_self();
+ if (tcb == NULL || tcb->group == NULL || tcb->group->tg_info == NULL)
+ {
+ return 0;
+ }
+
+ info = tcb->group->tg_info;
+ option = info->ta_openlog.ol_option;
+ if ((option & LOG_PID) != 0)
Review Comment:
pid already print, why not guard that place?
##########
libs/libc/syslog/lib_syslog.c:
##########
@@ -27,12 +27,89 @@
#include <nuttx/config.h>
#include <stdarg.h>
+#include <stdio.h>
#include <syslog.h>
+#include <unistd.h>
#include <nuttx/syslog/syslog.h>
+#include <nuttx/tls.h>
#include "syslog/syslog.h"
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* A message of a program: the OS adds the ident of openlog() */
+
+#ifdef __KERNEL__
+# define VSYSLOG_FLAGS 0
+#else
+# define VSYSLOG_FLAGS SYSLOG_OPENLOG
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if !defined(__KERNEL__) && defined(va_copy)
+/****************************************************************************
+ * Name: vsyslog_perror
+ *
+ * Description:
+ * With LOG_PERROR of openlog(), write the message to stderr too, with the
+ * ident and the process ID before it and a newline after it.
+ *
+ ****************************************************************************/
+
+static void vsyslog_perror(FAR const IPTR char *fmt, va_list ap)
+{
+ FAR struct task_info_s *info = task_get_info();
+ FAR const IPTR char *end;
+ va_list copy;
+ int option;
+
+ if (info == NULL
+#ifdef CONFIG_BUILD_FLAT
+ || up_interrupt_context()
+#endif
+ )
+ {
+ return;
+ }
+
+ option = info->ta_openlog.ol_option;
+ if ((option & LOG_PERROR) == 0)
Review Comment:
why not modify lib_syslograwstream_open to return a stream which output to
both syslog channel and stdout for this case?
##########
drivers/syslog/vsyslog.c:
##########
Review Comment:
why not add ident here directly?
##########
drivers/syslog/vsyslog_rfc5424.c:
##########
@@ -106,6 +106,10 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR
va_list *ap)
char hostname_buf[HOST_NAME_MAX + 1];
#endif
+ bool ident = (priority & SYSLOG_OPENLOG) != 0;
Review Comment:
why not access the flag in task tls, but pass through priority argument?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]