kirill-konshin / next-redux-wrapper

Redux wrapper for Next.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Optionally delegate logging to user provided method

kriswuollett opened this issue · comments

Problem

Debug logging uses console.log. It prevents the usage of a logging library like pino in order to implement structured logging like when using GCP's Structured Logging. This makes it more difficult to query logs and set a proper debug log level when deploying into a remotely deployed development environment. It can be an issue when redux is using real APIs instead of local fakes as stand-ins.

Possible Solution

Update the Config interface to something like:

export interface Config<S extends Store> {
    serializeState?: (state: ReturnType<S['getState']>) => any;
    deserializeState?: (state: any) => ReturnType<S['getState']>;
    debug?: boolean | (message: string, obj?: any);
}

Which would enable users setting debug like:

const logger = pino({ /* ... */ });

const wrapper = createWrapper<AppStore>(makeStore, {
 debug: (message, obj, args) => logger.debug({...obj, tags: ["someContext"]}, message, ...args);
});

Such that the log entry "in the cloud" could be the following provided that the message doesn't explicitly include the "with ..." part:

{
  "message": "4. 'Display Name' created store",
  "jsonPayload":  {
    "tags": ["someContext"],
    "initialSate": {},
    "initialStateFromGSPorGSSR": {},
  }
}

Alternatives

Use patch-package to implement the above.

Additional context

Clearly this is a nice to have, but would be great for the more enterprise-level environments.

Feel free to submit a PR