API optimization - Logging

Hi,

Trying to work on optimizing API calls and finding out where all the logging calls come from.

Whenever a Cloud Code is executed, I find something like the following in my logs :

10:40:6.873 | SERVER_CODE | INFO | [542290] [ANALYSE CODE] codePath: /opt/backendless/repo/my-app-id/files/servercode/CODELESS/myService/DRAFT
10:40:6.875 | SERVER_CODE | INFO | [542290] Building Model..
10:40:7.26 | SERVER_CODE | INFO | [542290] ServerCode Model built in 151ms
10:40:7.26 | SERVER_CODE | INFO | [542290] Services (1):
10:40:7.26 | SERVER_CODE | INFO | [542290] myService (services/myService/index.js)
10:40:7.28 | SERVER_CODE | INFO | [542290] Processing finished in 165.776ms
10:40:7.609 | SERVER_CODE | INFO | [542301] [ANALYSE CODE] codePath: /opt/backendless/repo/my-app-id/files/servercode/CODELESS/myService/DRAFT
10:40:7.611 | SERVER_CODE | INFO | [542301] Building Model..
10:40:7.756 | SERVER_CODE | INFO | [542301] ServerCode Model built in 145ms
10:40:7.756 | SERVER_CODE | INFO | [542301] Services (1):
10:40:7.756 | SERVER_CODE | INFO | [542301] myService (services/myService/index.js)
10:40:7.758 | SERVER_CODE | INFO | [542301] Processing finished in 161.078ms

(in this example, my app id and service name have been replaced by placeholders for confidentiality reasons)

My question is : do these log entries count as API calls ? And if so, is it one call, 2 calls (it seems it is built twice), or worst of all 12 calls (one for each line) ?

I understand I can avoid having these lines logged by defining a log level higher than INFO for SERVER_CODE. But still, the logging API would be called and then the content discarded, right ? So it would still count as API calls, wouldn’t it ?

Thanks for your clarifications.

@Nicolas_REMY

do these log entries count as API calls ?

Looks like it counts like 12 calls.

the logging API would be called and then the content discarded, right ?

No, JS-CodeRunner will not send logs to the server, if the log level is lower than you have set in the log management.

Regards

So what you are saying, @viktor.liablin , is that this counts as 12 API calls within the same second, for logging informations that are not specifically asked for or wanted, and the only solution would be to raise the log level above INFO.

Strange. I must say it does not sound particularly fair now that pricing depends upon it.

Is there a reason why this is not set at the lowest log level ? (that would be TRACE, right ?) Because the only way to get DEBUG or INFO logs on Cloud Code will immediately result in a very steep price.

Or is there a way to deactivate these log calls altogether ?

Anyways, thanks for the clarification.

@Nicolas_REMY

You can create your own loggers (log-categories) to log messages within your business logic and customize their levels as you see fit. There is no need to use only the Server-Code logger inside the business logic. Therefore, you can turn off its logs (by setting it to OFF or by leveling it up to ERROR) while the custom loggers are configured as you wish.
Please note that TRACE is not the minimum, but the maximum logging level, that is, it is actually equivalent to ALL.

Yes, I meant “minimum” in the sense of minimum importance, but it does generate a maximum of content :slight_smile:

In any case, what you recommend is to actually not use the built-in SERVER_CODE logger, and to use custom loggers instead. Got it.

It’s just weird that the default behavior will actually be the one costing more, and we have to take measures in order to reduce the price.