Logging API
Last modified by Manuel Leduc on 2024/03/11 14:39
Description
A logging API is useful for accurate error reporting. Especially as the logs won't be on the server, but on the user's client (i.e., browser or electron instance).
API Requirements
The minimal need is to have the following logging levels:
- Debug
- Info
- Warning
- Error
Existing Libraries
Architecture
The suggested architecture is to define our own logging API, but to delegate the actual implementation to the selected library.
That was, we can more easily switch from one library to another if needed.
The main constraint is that we need to be careful not to define our API with operations specific to a given implementation
Design decisions
- While browsers have the ability to filter logs, do we have the possibility to also skip at log time:
- based on the logger location (e.g., its module)?
- based on the log level?
Criteria
- Library size
- Maintainers
- Support for browsers (i.e., not node only)
- Can log in a human-readable format (i.e., not json only)
- Support for typescript
- Support for named loggers (i.e., ability to create new logger with specific log levels)
- Support for formatting. Excluded as Javascript/Typescript have support for formatting at language level.
Choice
Library | Conclusion | Size | Maintainer | License | For Browser | Human-Readable | Typescript | Support for Named Logger |
---|---|---|---|---|---|---|---|---|
Pino | 12k | 2 main maintainers, last release on Feb. 2024 | MIT | yes | yes | yes | we would need to implement it ourselves | |
LogLevel | 8k (minified) | Mainly one contributor, last release Jan. 2024 Looks well documented and stable. | MIT | yes | yes | yes | yes | |
Browser API | 0 (bundled) | supported by all browsers we support | bundled in browsers | yes | yes | yes | We would need to implement it ourselves | |
Roarr | Not free Does very little as the concrete way to log is to be defined manually, the library is mostly providing high-level abstractions that we probably don't need, or would redefine in our own API | 20k (minified) | Mainly one contributor, last release on Nov. 2023. | not free | yes | yes | yes | partial, can be custom-made using the “context” metadata |
Winston | No Good support for browsers | MIT | no | |||||
Bunyan | No good support for browsers | MIT | no | |||||
Npmlog | No browser support | |