You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nuttx.apache.org by Lwazi Dube <lw...@gmail.com> on 2023/04/05 23:02:59 UTC

Unavoidable newline in debug printfs

Hi,

I don't have a newline in my format string but it gets added anyway.
This is a bug. I need to use a loop to print several bytes on the same
line.

Is there a reason why this is forced on everyone ?

  if (stream.last_ch != '\n')
    {
      lib_stream_putc(&stream.public, '\n');
      ret++;
    }

(drivers/syslog/vsyslog.c: around line 252)

It was added by this change:

commit 275b2e70a47c1d8e2bfd1797a7a283c1ba14d8c4
Author: yinshengkai <yi...@xiaomi.com>
Date:   Fri Dec 30 17:09:45 2022 +0800

   syslog: fix extra line breaks in syslog when SYSLOG_COLOR_OUTPUT is enabled

Re: Unavoidable newline in debug printfs

Posted by Xiang Xiao <xi...@gmail.com>.
The spec require to append the newline if the caller doesn't add one:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/syslog.html
https://www.man7.org/linux/man-pages/man3/syslog.3.html
The original patch is here:
https://github.com/apache/nuttx/pull/8004
In your cae, you have to buffer the output before calling syslog. You have
to do this even without this change since other thread may call syslog
between yours.

On Thu, Apr 6, 2023 at 7:03 AM Lwazi Dube <lw...@gmail.com> wrote:

> Hi,
>
> I don't have a newline in my format string but it gets added anyway.
> This is a bug. I need to use a loop to print several bytes on the same
> line.
>
> Is there a reason why this is forced on everyone ?
>
>   if (stream.last_ch != '\n')
>     {
>       lib_stream_putc(&stream.public, '\n');
>       ret++;
>     }
>
> (drivers/syslog/vsyslog.c: around line 252)
>
> It was added by this change:
>
> commit 275b2e70a47c1d8e2bfd1797a7a283c1ba14d8c4
> Author: yinshengkai <yi...@xiaomi.com>
> Date:   Fri Dec 30 17:09:45 2022 +0800
>
>    syslog: fix extra line breaks in syslog when SYSLOG_COLOR_OUTPUT is
> enabled
>