Choice of Logging API

Hello all,

This proposal concerns the choice of a Logging API.

The design page: https://design.xwiki.org/xwiki/bin/view/Proposal/LoggingAPI

The way I see it we have three options:

  1. Directly use one of the available logging API.
  2. Define our own logging API:
    1. And delegate the implementation to an available logging API
    2. And define our own implementation.

Requirements

I’m heavily inspiring from what we have in XWiki. The main difference being that here we are only concerned about client-side logs, which adds a few additional constraints:

Also, I’m excluding the support for formatted string as JavaScript and Typescript support template literals .

Being able to log on the following levels:

  • Trace
  • Debug
  • Info
  • Warn
  • Error (with log line number + stracktrace)

Being able to define a logging level per logger, and to be able to discard printing a given log (in addition to browser debugger allowing users to define their own filters)

Optional: Being able to define several “transports” (i.e., logging to the browser console, or in a file when running in an electron environment).

Option 1

There is no broadly accepted logging API standard in JavaScript. Therefore, the risks are high that by picking a library, we would get stuck with it.
Additionally, those libraries make an extra effort to support legacy browsers (e.g., IE). Which is not required for us as all the browsers we support provides a standardized console.*.
They also often support server-side specific feature such as aggregating metadata to feed a logging aggregator.

Option 2.1 vs Option 2.2

Note 1: I won’t go into the details of the API itself in this first message, and will propose it later once we agree on the right option.
Note 2: you can find a comparison matrix of logging libraries here https://design.xwiki.org/xwiki/bin/view/Proposal/LoggingAPI#HChoice

Pino, and LogLevel are two good candidates but:

  • are only maintained by one or two contributors
  • would both require some sort of customization to fit our requirements

Therefore, I believe providing our own API and implementation is the way to go.

Conclusion

I’m +1 for Option 2.2 as I believe we need to have our own API, and relying on a given library would not be an advantage.
WDYT?
Thanks!

+1 for 2.1 too. Feels a bit too dangerous for the long term run to directly rely on an API without having our own wrapping API. And AFAICS LogLevel could be a good fit to start with. Now I’m +0 for 2.2 if really an important feature is missing.