New logging mechanics #1873
-
Hey, so we've decided to migrate our code-base to recent version of Mongoose. Looking good going fine (..) so far. Thought I would share my thoughts about the seemingly refactored logging mechanics. As of now, by default, at a certain moment of processing the library has a full string for each log message on the stack. Now, the custom callback function definition has changed. It now no longer is given the full buffer along with its size but is invoked on a per-byte basis through logc(). Here are my doubts/comments:
May I dare to ask what was the rationale?
I found the above sample handler in docs. Previously nobody prevented the callback function from doing in-ram buffering on a per-message basis. also please excuse this off-the-topic question, but - why does custom-file-system handlers now return void* instead of a concretized pointer of a file descriptor? |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 8 replies
-
From what I remember (and IIRC): We got completely rid of any use of printf()-like functions. Some useful extensions required a heavy use of memory allocation and/or guessing abilities; these was greatly simplified by using character-based output, keeping the UI simple and so less error-prone. My impression is that Hope this answers your questions |
Beta Was this translation helpful? Give feedback.
-
@scaprile thank you for your response. void * might be much more general, but it is way more error-prone. Notice that delete (void*) does not take into account the actual memory allocation of the object and the caller of delete needs to be aware of the object type, do reinterpret_cast to the concrete pointer and only then call delete. Were there any changes made to how API for connections is used? In our project (https://gridnet.org) we take extremely heavy use of Mongoose. Were there any changes done to connection's API? I mean, without doing any changes to our-code base, when we form connections to external endpoints, with Mongoose acting as client (..) with TLS enables (or even without I dunno) the socket does never transition into a 'writable' 'edible' state Even though the CONNECTED callback had fired.. We never receive any response from a remote endpoint. We haven't investigated this further though we've been spending an entire day porting.. without much success so far. Calling same functions and stuff.... From the API perspective, the logging callback changed (..) the file-system handlers changed but still we are unable to get basic data-connectivity up and running with Mongoose acting as a client. |
Beta Was this translation helpful? Give feedback.
-
We are porting from version 7.4 Were there changes made to how the user-defined-object is passed along the callbacks? |
Beta Was this translation helpful? Give feedback.
-
Hello? Are these platform specific issues we're experiencing? |
Beta Was this translation helpful? Give feedback.
-
Mongoose uses its own family of printf functions, where the lowest level is this: size_t mg_xprintf(void (*out)(char, void *), void *param, const char *fmt, ...); It outputs a formatted string to a "printer function". We chose a signature for that "printer function" to be a per-byte printer: typedef void (*mg_pfn_t)(char, void *); The alternative was to use a "memory chunk" printer: typedef void (*mg_pfn_t)(const void *buf, size_t len, void *); Why did we use a per-byte printer? Because it is simpler. Yes it is not that as efficient as an alternative, but in our design priorities, simplicity stays above performance. In this particular case, the alternative is also simple enough, so we might reconsider - if there is an evidence that the performance hit is significant in a real production use cases. |
Beta Was this translation helpful? Give feedback.
-
@cpq @scaprile kindly thank you for your assistance and all of your responses. Since, as of now, the conversations shed no light on the possible reasons behind the issues we've seemed to encounter with versions > 7.4, For now we'll keep riding 7.4 which simply works for us without any issue at all - can't thus afford more hours on this, as of now. |
Beta Was this translation helpful? Give feedback.
-
@rafalsk thanks. Though re-reading what you've written, I still don't understand what's your issue. |
Beta Was this translation helpful? Give feedback.
@rafalsk
Mongoose uses its own family of printf functions, where the lowest level is this:
It outputs a formatted string to a "printer function". We chose a signature for that "printer function" to be a per-byte printer:
The alternative was to use a "memory chunk" printer:
Why did we use a per-byte printer? Because it is simpler. Yes it is not that as efficient as an alternative, but in our design priorities, simplicity stays above performance.
In this particular case, the alternative is also simple enough, …