Ability to add a transport to Blitz's logger
What do you want and why?
blitz-js/legacy-framework#220 added the ability to set Blitz's log output to JSON. I'd like to go a step further and support tslog's transports system because I'm trying to send intelligable logs to logtail. I think the same goes for a lot of other log systems.
Possible implementation(s)
Exposing the logger instance as an import from blitz might help, or adding a method within which you can configure that instance in blitz.config.ts
How about a callback in the blitz.config.ts under log.custom that takes the default config and the instantiated logger. You could then modify what you'd like of the default config, attach transports, etc and return the logger for use. Would default to using the built in logger.
Tradeoffs:
- PRO: Let's you do basically whatever you want, including overriding config and attaching custom transports
- CON: Without custom interfaces, config would be coupled to tslog (are we ok with this?)
- CON: May confuse some devs using the current config options (
levelandtype) as there's two possible places for that
Example: Attaching transport
function logToTransport(logObject: ILogObject) {
// TODO: implement
}
const config: BlitzConfig = {
log: {
custom: ({ logger }) => {
logger.attachTransport(
{
silly: logToTransport,
debug: logToTransport,
trace: logToTransport,
info: logToTransport,
warn: logToTransport,
error: logToTransport,
fatal: logToTransport,
},
"debug"
)
return logger
}
}
}
Example: Patching default config or implementing a custom logger
import { Logger } from "tslog"
const config: BlitzConfig = {
log: {
custom: ({ settings }) => {
return new Logger({...settings, minLevel: "info"})
}
}
}
If we're cool with this proposal and the tradeoffs, I think implementation would be pretty easy. Thoughts @beerose / @tmcw?
The final API/implementation aside, I just wanted to mention that we're pivoting Blitz to a toolkit (https://github.com/blitz-js/blitz/discussions/3075), so that's where most focus currently is. We plan to fix major bugs, but won't be implementing new features. However, we're open to accepting PRs!
I have this working locally with patch-package for now. Here's the diff: https://gist.github.com/nakleiderer/ff68347fe87d3434a28c723fc34c41b3