blitz-js / blitz-js/legacy-framework
Reroute next logger to blitz
- Dominant language
- JavaScript
- Stars
- 3
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
### What do you want and why?
Reroute next logger to blitz. The next.js logger is pretty terrible and we can't add our own transport. The blitz logger lets us add transports (cool!) this lets me do more things with my logs!
### Possible implementation(s)
I can do this currently by hacking the next.js logger like so in my blitz.config.js file:
```js
const { baseLogger } = require("@blitzjs/display")
const logger = require("next/dist/build/output/log.js")
const log = baseLogger();
if (!logger["__blitz_was_here__"]) {
const nextLoggerMap = {
warn: "warn",
error: "error",
}
Object.entries(logger).forEach(([key, value]) => {
if (typeof value === "function") {
log.info("Mapping " + key + " from next to blitz")
logger[key] = (message) => log[nextLoggerMap[key] ?? "info"](message)
}
})
logger["__blitz_was_here__"] = true
}
```
However this means the trace tells me the log line came from blitz.config.js, and the following doesn't work (it yells, and I don't have time to investigate further):
```js
logger[key] = log[nextLoggerMap[key] ?? "info"]
```
### Additional context
I need my server-side logs to go into Sumo Logic, so I added a transport to the base logger like so in blitz.config.js:
```js
function logToSumo(logObject) {
// do some magic with logObject to send to the sumo logic deamon
}
const { baseLogger } = require("@blitzjs/display")
const log = baseLogger()
log.attachTransport(
{
silly: logToSumo,
debug: logToSumo,
trace: logToSumo,
info: logToSumo,
warn: logToSumo,
error: logToSumo,
fatal: logToSumo,
}
)
```
Contributor guide
Assessment
This issue has not been assessed yet.