cloud-sdk-js icon indicating copy to clipboard operation
cloud-sdk-js copied to clipboard

The logger implemented by cloud-sdk by using winston cannot be extended

Open Alexshov opened this issue 4 years ago • 8 comments

Dear Team,

We try to extend our default logging functionality by our custom implementation. We extended CAP and CF loggers but have problems with the logger implemented by cloud-sdk by using winston.

Could you, please, help us to understand better ways how to include cloud-sdk into our implementation. The intention is to change severity level of all log files simultaneously.

Alexshov avatar Sep 15 '21 15:09 Alexshov

Hi @Alexshov , To set the log levels for all loggers simultaneously, you can use the setGlobalLogLevel(level) method from '@sap-cloud-sdk/util'. For more details, you can also refer to our documentation here.

Do let me know if that answers your question. If not, please provide some more details about your custom implementation and we will get back to you.

deekshas8 avatar Sep 16 '21 10:09 deekshas8

Hi @Alexshov , To set the log levels for all loggers simultaneously, you can use the setGlobalLogLevel(level) method from '@sap-cloud-sdk/util'. For more details, you can also refer to our documentation here.

Do let me know if that answers your question. If not, please provide some more details about your custom implementation and we will get back to you.

Hi @deekshas8,

our final goal is to have a log level on demand. It means that we need to implement our custom logic (which calculates current log level) for each logger we're using.

There're 3 different loggers used by CAP framework. In one of them we can replace global createLogger function. The other one cf-nodejs-logging-support is also based on Winston. But it has a method to rewrite the final logging function called custom-sink-function which allows us to put our custom logic.

The third type is cloud-sdk logger. Yes, there's a setGlobalLogLevel method but it's not clear how it can be re-calculated and re-triggered on each logging. That's our point. Do you have some idea what can be done here?

Thank you.

tiosteel avatar Sep 21 '21 13:09 tiosteel

Hi @tiosteel ,

If I understand correctly, you need a setter function as provided in cf-nodejs-logging-support to put your custom logic. The SDK does not expose such a method currently.

You could however create a custom transport as shown here and put your logic here and then add this transport to your logger instead. Do keep in mind that the SDK sets a default value (console) for the transport.

Let me know if this answers your question.

Regards.

deekshas8 avatar Sep 22 '21 12:09 deekshas8

Hi @tiosteel ,

If I understand correctly, you need a setter function as provided in cf-nodejs-logging-support to put your custom logic. The SDK does not expose such a method currently.

You could however create a custom transport as shown here and put your logic here and then add this transport to your logger instead. Do keep in mind that the SDK sets a default value (console) for the transport.

Let me know if this answers your question.

Regards.

Hi @deekshas8,

it sounds like exactly what we need - a place to put a custom logic in. However could you please hold the question for a few more days just in case of big issues with a custom transport implementation?

Thanks a lot!

tiosteel avatar Sep 22 '21 13:09 tiosteel

Hey @tiosteel, did it work? ;)

marikaner avatar Oct 05 '21 09:10 marikaner

Hey @tiosteel, did it work? ;)

Hi, @marikaner and @deekshas8 Actually I didn't find a way to assign my new transport globally.

The thing is I'm not using cloud-sdk logger directly, but I'm calling other packages which are using lots of functions of cloud-sdk who call the logger.

tiosteel avatar Oct 05 '21 15:10 tiosteel

Hi @tiosteel , Thanks for providing more details about your use case. The SDK does not currently provide a way to set the transports (custom or otherwise) globally, which is a valid use case. I will add this feature request to our backlog.

Could you please share the time line for your project? Are you working on a PoC project or live system?

deekshas8 avatar Oct 06 '21 09:10 deekshas8

Hi @deekshas8,

thanks you for the response. I'm working on a new SAP cloud product. Currently there's a staging system with yet no real customers. The feature I request is a very far from being critical. Though it can simplify the development and support process really well especially in a multi-tenant environment.

tiosteel avatar Oct 06 '21 09:10 tiosteel

Hi @Alexshov, @tiosteel,

We implemented the feature in @sap-cloud-sdk/util to support setting the transports globally. Now you can pass a transport(custom or otherwise) as an argument to do it:

setGlobalTransports(new winston.transports.File(options));

This function also accepts an array with multiple transports as an argument. You can set them globally at once:

setGlobalTransports([httpTransport, streamTransport]);

Updated documentation is here.

Since the feature is implemented, we close this. I hope it can help you solve the problem. Please re-open or open a new issue if you have any further questions. Best regards, Shoji Soma

shojisoma avatar Sep 12 '22 10:09 shojisoma