How to ideally fix the log function

John Wang wangzhiqiang8906 at gmail.com
Mon Jul 29 17:53:54 AEST 2019


On Mon, Jul 29, 2019 at 8:26 AM Andrew Jeffery <andrew at aj.id.au> wrote:
>
>
>
> On Fri, 26 Jul 2019, at 12:33, John Wang wrote:
> > On Fri, Jul 26, 2019 at 10:08 AM Andrew Jeffery <andrew at aj.id.au> wrote:
> > >
> > > 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"));
> > }
> > ```
>
> My immediate thought is "pretty ugly" :D

I tried my best to make those codes  "pretty" ...    sad.gif..


More information about the openbmc mailing list