camunda / camunda-8-js-sdk

The Camunda 8 JavaScript SDK for Node.js
https://camunda.github.io/camunda-8-js-sdk/
Apache License 2.0
19 stars 6 forks source link

Support custom loggers in the Zeebe client configuration #266

Open zalddeve opened 1 month ago

zalddeve commented 1 month ago

The Camunda 8 JavaScript SDK lacks the ability to pass a custom logger to the ZeebeGrpcClient instance.

SDK Component

Zeebe
(The same problem probably affects other modules as well.)

Expected Behavior

In the Zeebe Node.js client it is possible to pass a ZBCustomLogger to the client in the ZBClientOptions object, so we can add custom logic to the logger. For example,

const logger: ILogger

const zeebeClient = new ZBClient({
    loglevel: 'INFO',
    stdout: {
        debug: (message) => customLogger(logger, message),
        info: (message) => customLogger(logger, message),
        error: (message) => customLogger(logger, message),
    },
});

const customLogger = (logger: ILogger, message: string) => {
    const msg: IZeebeLog = JSON.parse(message);

    switch (msg.level) {
        case ZeebeLogLevel.DEBUG:
            logger.debug(msg.message);
            break;
        case ZeebeLogLevel.INFO:
            logger.info(msg.message);
            break;
        case ZeebeLogLevel.ERROR:
            logger.error(msg.message);
            break;
    }
};

It would be nice if I could also change the output format in the Camunda SDK.

Current Behavior

Currently we can only choose between the ZBJsonLogger and ZBSimpleLogger implementations.

camunda/camunda-8-js-sdk/src/zeebe/zb/ZeebeGrpcClient.ts#L125C1-L131C59

Context (Environment)

In our system there are strict requirements for the log message format. To replace the deprecated Zeebe client library with the new SDK, we need the ability to define the shape and extend the content of the output message.
Am I missing something and is this already possible or do you plan to implement it in the near future?

@camunda8/sdk - v8.6.13

jwulf commented 1 month ago

Hi, thanks for raising this issue.

In the upcoming release of the SDK, I have added the Winston logging framework to all of the clients except for the gRPC one, to allow more flexibility for users.

I could additionally add it to the gRPC client. Would that work for your usecase?

zalddeve commented 1 month ago

Hi @jwulf, I've checked your getLogger() implementation in the 8.6 branch.

Perhaps adding a universal logger interface to the Camunda8ClientConfiguration would be a bit more convenient for a wider audience (e.g. those using Pino or something else). In this case anyone can create a wrapper for their logging implementation.

But I agree with you, configuring the logger this way has advantages in many cases. For our use case it's a good fit as we already use Winston for logging.

Could you add this to the gRPC client as well? Thank you very much!

jwulf commented 4 weeks ago

@zalddeve - could you consume an ESM module version of the SDK in your code?

zalddeve commented 4 weeks ago

Although we plan to use ESM modules in our packages in the future, unfortunately we haven't had a chance to migrate them yet, so if possible I prefer the CommonJS one.