-
|
Was having trouble setting up the logger plugin, anyone has any idea? // hanlder
import { LoggingHandlerPlugin } from '@orpc/experimental-pino';
import { OpenAPIHandler } from '@orpc/openapi/fetch';
import { onError } from '@orpc/server';
import { CORSPlugin } from '@orpc/server/plugins';
import pino from 'pino';
import { apiRouter } from '../modules/api-router';
const logger = pino();
export const apiHandler = new OpenAPIHandler(apiRouter, {
plugins: [
new LoggingHandlerPlugin({
logger,
generateId: ({ request }) => crypto.randomUUID(),
logRequestResponse: true,
logRequestAbort: true,
}),
new CORSPlugin(),
],
interceptors: [
onError((error) => {
// console.error(error);
}),
],
});
// router
import { LoggerContext } from '@orpc/experimental-pino';
import { os } from '@orpc/server';
import { authMiddleware } from './better-auth';
interface BaseContext {
headers: Headers;
db: D1Database;
}
export type Context = BaseContext;
interface ORPCContext extends LoggerContext, BaseContext {}
export const apiRouter = {
index: os
.$context<ORPCContext>()
.route({
method: 'GET',
path: '/',
})
.use(authMiddleware)
.handler(async ({ context }) => {
return { ok: true };
}),
};
//cloudflare fetch
export default {
async fetch(request, env, ctx): Promise<Response> {
const { matched, response } = await apiHandler.handle(request, {
context: { headers: request.headers },
prefix: '/api',
});
if (matched) {
return response;
}
return new Response('Not found');
},
} satisfies ExportedHandler<Env>;Error : [wrangler:error] TypeError: logger3.bindings is not a function
at null.<anonymous> (file:///.../backend/node_modules/@orpc/experimental-pino/dist/index.mjs:29:19)
at next (file:///.../backend/node_modules/@orpc/shared/dist/index.mjs:518:12)
at Object.next (file:///.../backend/node_modules/@orpc/shared/dist/index.mjs:520:40)
at null.<anonymous> (file:///.../backend/node_modules/@orpc/server/dist/plugins/index.mjs:156:33)
at next (file:///.../backend/node_modules/@orpc/shared/dist/index.mjs:518:12)
at Object.next (file:///.../backend/node_modules/@orpc/shared/dist/index.mjs:520:40)
at null.<anonymous> (file:///.../backend/node_modules/@orpc/server/dist/plugins/index.mjs:159:47)
at next (file:///.../backend/node_modules/@orpc/shared/dist/index.mjs:518:12)
at intercept (file:///.../backend/node_modules/@orpc/shared/dist/index.mjs:523:10)
at StandardOpenAPIHandler.handle (file:///.../backend/node_modules/@orpc/server/dist/shared/server.Bxx6tqNe.mjs:38:12) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
The error happens because the LoggingHandlerPlugin expects the logger you pass in to have both bindings() and setBindings() methods, but the standard Pino logger in Cloudflare Workers does not provide these methods. This is because the plugin is designed to work with a Node.js-style Pino logger or a compatible wrapper, not the minimal or browser/worker builds of Pino, which lack these APIs see source. To work around this, you can either:
If you want to keep structured logging, you could create a custom logger object like: function makeWorkerLogger() {
let _bindings = {};
return {
info: console.info,
error: console.error,
child: () => makeWorkerLogger(),
bindings: () => _bindings,
setBindings: (b) => { _bindings = { ..._bindings, ...b }; },
};
}Then pass makeWorkerLogger() instead of pino() to the plugin. This will satisfy the plugin’s expectations and avoid the error. If you need more advanced logging, you’ll need to adapt a logger that works in the Worker environment and implements those methods. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
|
Can you help me create minimal repro include only wrangler + pino + orpc? @SSam0419 |
Beta Was this translation helpful? Give feedback.

@SSam0419 Thanks for the reproduction. After looking into it, I believe this issue comes from Cloudflare or Pino itself. According to Pino's types,
.bindingsshould exist, and it does exist in both Bun and Node runtimes. However, on Cloudflare, this method appears to be missing.