Replies: 2 comments 1 reply
-
Really like the solution. Regarding creating a I also personally don't see a need for using something like wintson or adze. We could probably accomplish the basic customization needs just with tslog (ie.
I think this could be useful
This can also be very helpful Any way, this is a great writeup. Very curious on the communities opinion on this. |
Beta Was this translation helpful? Give feedback.
-
Well, it's not about us but the community as a whole. There are people who are already using winston or adze or something else and would like to continue using it and blitz. I wrote this based on the feedback and considering multiple use cases. |
Beta Was this translation helpful? Give feedback.
-
Improved and customizable logging system for Blitz
Problems & considerations
log
property tosetupBlitzServer
:Though, long term, it's not configurable enough. It still relies on the logger that Blitz uses internally and doesn't provide with a way to bring your own logger.
There's no easy way to disable logging unless you patch package particular modules.
Currently, internally, we're using
tslog
, and we should provide a way to customize it fully. Whether we stick totslog
or not, we should expose a way to configure whatever logging tool we use.tslog
allows to attach a transport. We should expose a way to support this.Goals
Solution
I was initially thinking about having a logging plugin. Something like this:
However, that kind of forces to always have it
blitz-server.ts
. You may not want to see it if you don't want to change anything in the logging configuration. The advantage ofLoggingPlugin
is that we could have all the logging setup within theLogginPlugin
function. That would be slightly similar to how auth DB adapters work. Ie:But we can also do it on the
setupBlitzServer
level:Action point: currently, the logger is being created in
log.ts
file in Blitz package, and it's independent from the modules/plugins concept. We should move the initialization somewhere so that the config can be passed fromsetupBlitzServer
. Possiblyblitz
could expose a function to handle that, and this new function could be used insidesetupBlitzServer
.createLogger
(or however we decide to call it) would store the logger on context or global or somewhere else. It can also return the logger.Default API
By default, you don't have to provide any configuration. Blitz will use tslog with Blitz's own config.
Configuration
If you want to configure tslog, you can do it inside
setupBlitzServer
:Custom logging
Example of custom logging with winston:
Now, what about types? What should the
logger
property's type be? Firstly, it should satisfy an object with the following methods:For example, winston's logger does have these methods. In case a different tool has a different API, it would be required to cover that manually:
Example with adze:
Questions
logger
? I wonder whether there aren't too many conceptual differences between e.g. winston and adze to make it agnostic.destinations
? E.g. [stdout
, new-relic, ...]. Or should we let users deal with that when they are creating/declaring custom loggers? Or should we do both in case someone uses a default Blitz logger (tslog)? Is this solved by tslog'sattachTransport
?setupBlitzServer
so that people can use it somewhere else, e.g. inside queries?setupBlitzServer
? So that people can reuse it in their code? Or is that redundant?Beta Was this translation helpful? Give feedback.
All reactions