Configurable Logging in NodeJS

Release DateFeb 27, 2019
Change Type
Platforms Affected

We’ve added the ability to programmatically configure the logger used in the NodeJS SDK. You can now disable logging or add a custom log handler during runtime.

In order to get this feature, you must generate an updated NodeJS SDK from APIMatic.

Note   In order to use logging in NodeJS, you must turn on the Enable Logging flag in the Code Generation settings.

Logger Instance

The NodeJS SDK now creates and maintains its own instance of the Winston logger. Previously, we were using the default static instance provided by Winston for application logging.

Configuring Logger

The logger can be reconfigured with custom transport:

const DailyRotateFile = require("winston-daily-rotate-file");
sdk.Logger.configure({
  level: "verbose",
  transports: [new DailyRotateFile(opts)]
});

Logging can also be disabled for the SDK:

sdk.Logger.clear();

The sdk.Logger gets the instance of the Winston logger used by the SDK for all logging actions, assuming that the library (SDK) was imported into the sdk variable.

For more configuration options, checkout the documentation for Winston.

Related Links


Have questions? Submit a request.