Logging API never works consistently !!

Hi -

I am facing in-consistency issues since many weeks with ‘Logging API’ - which is my sole medium for debug logging in server code.

If I do, say 'Backendless.Logging.setLogReportingPolicy(5,20) - I start getting below exception.

BackendlessException{ code: ‘0’, message: ‘You have no permission to thread manipulation’ }

And if I do Backendless.Logging.setLogReportingPolicy(0,1) - 80% times I don’t get all my debug logs.

Backendless.Logging.flush() helps - but again not always - and its pain to put it after every few logs.

The documentation has answers for both:https://backendless.com/documentation/business-logic/java/bl_logging.htm

specifically see the highlighted part:
http://support.backendless.com/public/attachments/d405eed3ee3ab0b8a6c738ec595bb890.jpg</img>

Hi Mark - Sorry that was typo - I meant Backendless.Logging.setLogReportingPolicy(1,) only.

The issue is using this - the log doesn’t always appear - sometimes we get the log after half hour, sometimes immediately, sometimes don’t get it at all.

Hi Aditya,

We need some sample or a description of the use case which would reproduce the problem. For example, if you provide the code with Backendless.Loggin.flush() where it’s not working, it would help a lot.

For now we can barely help you since we can’t find a way to run into the same problem. The behaviour you describe doesn’t reproduce in plain cases:

the log doesn't always appear - sometimes we get the log after half hour, sometimes immediately, sometimes don't get it at all.

Hi -

To reproduce, just write below empty beforeRegister() and afterRegister() event handlers - with only debug logs.

Then try to register user from an android app.

I never get all debug statements - I just ran it - and I only got 1 debug statement - out of 6.

@Override
public void beforeRegister( RunnerContext context, HashMap userValue ) throws Exception {
Backendless.Logging.setLogReportingPolicy(1,0);
Logger logger = Backendless.Logging.getLogger(“com.mytest.services.GenericUserEventHandler”);

logger.debug("In GenericUserEventHandler: beforeRegister");
logger.debug("Before: beforeRegister: "+HeadersManager.getInstance().getHeaders().toString());
logger.debug("beforeRegister:"+context.toString());
Backendless.Logging.flush();

}

@Override
public void afterRegister( RunnerContext context, HashMap userValue, ExecutionResult<HashMap> result ) throws Exception
{
Backendless.Logging.setLogReportingPolicy(1,0);
Logger logger = Backendless.Logging.getLogger(“com.mytest.services.GenericUserEventHandler”);

logger.debug("In GenericUserEventHandler: afterRegister");
logger.debug("Before: afterRegister: "+HeadersManager.getInstance().getHeaders().toString());
logger.debug("afterRegister:"+context.toString());
Backendless.Logging.flush();

}

Can you please try to run the same code as a plain java code, not inside of business logic? Will the behaviour be the same?

You mean as as backend API - and then call it from app ??

I mean just running the following code directly from your app:

Backendless.Logging.setLogReportingPolicy(1,0);
Logger logger = Backendless.Logging.getLogger("com.mytest.services.GenericUserEventHandler");
logger.debug("In GenericUserEventHandler: beforeRegister");
logger.debug("Before: beforeRegister: "+HeadersManager.getInstance().getHeaders().toString());
logger.debug("beforeRegister:"+context.toString());
Backendless.Logging.flush();

It looks same to me. I added below code in app after register success.

Backendless.Logging.setLogReportingPolicy(1,0);
Logger logger = Backendless.Logging.getLogger("com.mytest.services.GenericUserEventHandler");
logger.debug("registration success");
logger.debug("From App: In GenericUserEventHandler: beforeRegister");
logger.debug("From App: Before: beforeRegister: "+ HeadersManager.getInstance().getHeaders().toString());
Backendless.Logging.flush();

AND I GET ONLY 1 DEBUG LINE FROM BOTH SERVERCODE AND APP CODE (listed below).

2016-08-12 13:17:12,721 | com.mytest.services.GenericUserEventHandler | DEBUG | In GenericUserEventHandler: afterRegister
2016-08-12 13:17:13,868 | com.mytest.services.GenericUserEventHandler | DEBUG | From App: Before: beforeRegister: {secret-key=BB557D9A-4C9C-84FE-FFA1-B15A476D7400, api-version=1.0, user-token=24CF533A-A6B4-9F92-FF84-62EC8790AD00, application-type=ANDROID, application-id=09667F8B-98A7-E6B9-FFEB-B2B6EE831A00}

Can you please provide your app ID so that I could test it on your app? I couldn’t reproduce it with my test app, all three logs from the code snippet above have been written to the log file (sometimes with a little delay though).

My app id si 09667F8B-98A7-E6B9-FFEB-B2B6EE831A00

Hi Aditya,

The issue has been fixed and will be available with the next release (within 1-2 weeks).