Skip to content

Cleaner, more elegant logging #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 13, 2019
Merged

Cleaner, more elegant logging #24

merged 9 commits into from
Feb 13, 2019

Conversation

ubidefeo
Copy link
Collaborator

@ubidefeo ubidefeo commented Feb 5, 2019

ATTENTION: requires consulting the Cloud team before merging
I have refactored the logging entirely and added one extra level of verbosity (4).
It is now leaner and cleaner.
I also implemented firmware version check and compare but have an issue with WiFiNINA reporting the incorrect version (1.2.0) as latest.

- updated logging levels per message type (more in the future)
- cleaned up redundancies
- increased performances
- messages only printed during change of state (once)
- tested on MKR1000 and MKR1010
NOTE: WiFINina wrongly reports "1.2.0" when WiFi.firmwareVersion() is invoked, although version "1.2.1" is set in the source files
Copy link
Contributor

@aentinger aentinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request looks good to me ;) I've one suggestion though ... the debugMessage function could be slightly rewritten in order to accomodate variable arguments - then sprintf does not need to be used so much and the code becomes much cleaner to read.

A short example:

#include <stdio.h>
#include <stdarg.h>
...
void debugMessage(uint8_t const debug_level, char const * fmt, ...) {
  char debug_buf[64] = {0};

  va_list args;

  va_start (args, fmt);
  uint16_t const length = vsnprintf (debug_bug, 64, fmt, args);
  va_end   (args);

  Serial.print(debug_buf);
}

Usage would be then like: Instead of

*msgBuffer = 0;
sprintf(msgBuffer, "WiFi.status(): %d", WiFi.status());
debugMessage(msgBuffer, 4);

do this

debugMessage(4, "WiFi.status(): %d", WiFi.status());

@ubidefeo
Copy link
Collaborator Author

ubidefeo commented Feb 7, 2019

hey @lxrobotics
thanks for taking a look.
That method is being rewritten entirely because its place is definitely not as an inline in that Class.
I guess this will have to be merged before I finish that, but for now it's a sufficient way to output information.
I like the variable arguments count option a lot, didn't even think about it.
I'll make sure it's in the rewriting and then I'll work out a better implementation for the Classes I'll work on including ArduinoIoTCloud :)

ubidefeo and others added 5 commits February 7, 2019 22:44
Managed exit cases for GETTIME state. Removed IDLE state.
Managed exit cases for IOT_STATUS_CLOUD_CONNECTED, removed unused states
…nager

Revert "Managed exit cases for IOT_STATUS_CLOUD_CONNECTED, removed unused states"
@facchinm facchinm merged commit bff5110 into master Feb 13, 2019
@ubidefeo ubidefeo deleted the connection-manager branch February 20, 2019 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants