eclipse-californium / californium

CoAP/DTLS Java Implementation
https://www.eclipse.org/californium/
Other
730 stars 367 forks source link

I wanna save the whole logs of SenML JSON. #2189

Closed huny0501 closed 1 year ago

huny0501 commented 1 year ago

Hello, I am using leshan server demo.

I wanna save the whole logs of SenML JSON.

But, I can see small part of SenML Logs, As follows. I am using "ReadResponse.getCoapResponse()" method

ACK-2.05   MID=47482, Token=0CDC5F06A1BD4A12, OptionSet={"Content-Format":"application/senml+json"},
 "[{"bn":"/3/0/","n":"0","vs":"Les".. 405 bytes
ACK-2.05   MID=47483, Token=10C5614C176080C1, OptionSet={"Content-Format":"application/senml+json"},
 "[{"bn":"/4/0/","n":"9","v":6},{"".. 85 bytes

As you know, I wanna see whole SenML JSON.

Is it possible?

If it is possible, How can I do it?

I will wait your reply :)

boaks commented 1 year ago

You have already an analysis of the issue from the leshan project.

But you didn't answer the question, where you call the "logger" (or where the logger gets called).

Please add the class and line number of that log statement.

boaks commented 1 year ago

And, maybe, if you want to see to complete Payload of the ReadResponse, you may also ask in Leshan, if that's possible there. Maybe you just use the ReadResponse itself instead of the "ReadResponse.getCoapResponse()".

huny0501 commented 1 year ago

Thanks... I will check more :)

boaks commented 1 year ago

Just to mention:

If your code calls the LOGGER, an easy way would be:

if (MediaTypeRegistry.isPrintable( response.getOptions().getContentFormat())) {
   LOGGER.info("{} : {}", response, response.getPayloadString());
} else {
   LOGGER.info("{} : {}", response);
}

(that only works, if the payload has a printable content format)

If you use a MessageInterceptor e.g. MessageTracer you will need to provide a custom version.

Years ago, we decided to "truncate" the payload for logging in order to save resources. The main purpose of the Californium internal logging is to see, if the RFC 7252 is obeyed. Considering the payload is then more the focus on the next layer. To be frank, I don't know, why you need to log the complete payload. Unless you use a blockwise transfer, CoAP is straight forward. When you start to use blockwise then I'm also not aware of any issue, at least not when the response is reassembled and forwarded as response.

So, maybe you also tell, what you're searching for.

huny0501 commented 1 year ago

I made a simple application using leshan&californium. So there is no a lot of payload log so I wanna see whole of logs :)

I am using "org.eclipse.leshan.core.response.ReadResponse" I display ReadResponse directly. Yes I can see whole of payload, but it is not json format. I wanna see SenML Json Format, sorry

I succeeded to see whole of log by changing the source code. I attached californium-core 3.9.0 source instead of jar(lib) and changed it.

https://github.com/eclipse-californium/californium/blob/507d75c5442253f7a8706401bde5d1c88e134505/californium-core/src/main/java/org/eclipse/californium/core/coap/Message.java#L641-L643

protected String getPayloadTracingString() { // Display payload until 3072 byte return StringUtil.toDisplayString(payload, 3072); }

I succeeded but I think it is not efficient Is this for the best? Can I set this from Californium.properties OR on so on...? If there is no more method, I will use it :D

boaks commented 1 year ago

So there is no a lot of payload log so I wanna see whole of logs :)

Yes, that's your usage. And others have other requirements.

I display ReadResponse directly. Yes I can see whole of payload, but it is not json format.

I'm confused. What should that mean?

I succeeded but I think it is not efficient Is this for the best? Can I set this from Californium.properties OR on so on...? If there is no more method, I will use it :D

There is no property to change the toString() behavior. For the very very most user, it is too easy to prepare the content of the logging for their requirement exactly when the logger is called. That's simply straight forward and very common. So, as long as you don't show the code, where the logger is called in your case, it's just too time consuming to try to help you.

huny0501 commented 1 year ago

OK Thanks! Thank you all the time :)