All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Wang <wangzhiqiang8906@gmail.com>
To: Andrew Jeffery <andrew@aj.id.au>
Cc: vishwa <vishwa@linux.vnet.ibm.com>,
	OpenBMC Maillist <openbmc@lists.ozlabs.org>,
	 Mine <mine260309@gmail.com>,
	Patrick Venture <venture@google.com>,
	 Matt Spinler <mspinler@linux.ibm.com>
Subject: Re: How to ideally fix the log function
Date: Fri, 26 Jul 2019 11:03:36 +0800	[thread overview]
Message-ID: <CAHkHK0-_rKUd5EbyUtcgYttpZoy1-md8AG7f-8Er075pgObqBQ@mail.gmail.com> (raw)
In-Reply-To: <2f7ad2ea-7717-4f9b-bdd5-b6efc131cf4e@www.fastmail.com>

On Fri, Jul 26, 2019 at 10:08 AM Andrew Jeffery <andrew@aj.id.au> wrote:
>
>
>
> On Thu, 25 Jul 2019, at 20:52, vishwa wrote:
> > Hi John,
> >
> > Just some background; The goal is not to have func() pass in CODE_LINE
> > and CODE_FUNC since it would be a huge change all over in the code.
>
> There's no way this is really going to work. It turns out sd_journal_print()
> is actually a macro that adds the CODE_* properties via __LINE__ etc when
> SD_JOURNAL_SUPPRESS_LOCATION is not defined[1], so we either get
> the misleading information or force the caller to provide it.
>
> A hack approach that almost immediately falls short is that you could try
> macro over log() and adjust the actual log function prototype to take in the
> location parameters so we can call sd_journal_send_with_location()
> directly. However macro-ing over log won't handle namespaces correctly,
> and log() seems to parameterise the level with a template so we can't
> define the hypothetical log macro as a macro function (which we need to
> do in order to adjust the parameter list).
>
> Having said all that I'm not really a C++ person, but it appears the API has
> trapped itself in a C++ corner. Maybe people more experienced and creative
> than I can come up with something, but I think the best thing we can do
> is three-fold:
>
> 1. Build libsystemd with `CFLAGS=-DSD_JOURNAL_SUPPRESS_LOCATION`
> 2. Add a new log macro that allows us to capture the info properly
Maybe something like below:
```
struct traceLog
{
    traceLog(const source_location location = source_location::current()) :
        location(location)
    {
    }
    template <level L, typename Msg, typename... Entry>
    void log(Msg msg, Entry... e)
    {
        phosphor::logging::log<L>(msg, entry("CODE_LINE=%d", location.line()),
                                  entry("CODE_FILE=%s", location.file_name()),
                                  e...);
    }

  private:
    source_location location;
};

int main()
{
    traceLog{}.log<level::INFO>("xxxxx", entry("entry=%s", "xxxx"));
}
```

> 3. Change callsites to the new macro function over time.
>
> With 1 we remove the misleading information from the journal, and 2 and 3
> get us to the right place, eventually at the expense of CPP macros.
>
> Andrew
>
> [1] https://github.com/systemd/systemd/blob/master/src/systemd/sd-journal.h#L53

  reply	other threads:[~2019-07-26  3:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-25  1:05 How to ideally fix the log function John Wang
2019-07-25 11:21 ` vishwa
2019-07-26  2:08   ` Andrew Jeffery
2019-07-26  3:03     ` John Wang [this message]
2019-07-29  0:26       ` Andrew Jeffery
2019-07-29  7:53         ` John Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHkHK0-_rKUd5EbyUtcgYttpZoy1-md8AG7f-8Er075pgObqBQ@mail.gmail.com \
    --to=wangzhiqiang8906@gmail.com \
    --cc=andrew@aj.id.au \
    --cc=mine260309@gmail.com \
    --cc=mspinler@linux.ibm.com \
    --cc=openbmc@lists.ozlabs.org \
    --cc=venture@google.com \
    --cc=vishwa@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.