How to ideally fix the log function

Andrew Jeffery andrew at aj.id.au
Mon Jul 29 10:26:58 AEST 2019



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


More information about the openbmc mailing list