I just spent 1 or 2 hours trying to debug why this simple usage case does not work at all
Syslog *mySyslog;
WiFiUDP myUdp;
void start_syslog(void){
char hostname[64];
read_hostname_from_config(&hostname); // read NULL terminated string from EEPROM, SD-card, etc.
mySyslog = new Syslog(
myUdp
hostname,
2222,
"myhostname",
"appName"
LOG_LOCAL3,
SYSLOG_PROTO_IETF);
}
Basically this code would run but when I try and use mySyslog->log I get false as a return value. I spent a while troubleshooting my code before I looked at your implementation of Syslog.cpp. It was pretty obvious that my problem was the constructor just stores the pointer, not copies it. If you read the configuration from some dynamic source it means you can't pass in a stack variable.
I switched to using a global array for my hostname and it worked fine.
I think this implementation is fine, but it might save others some headache if you added notes warning them the constructor does not make deep copies and the caller must keep the memory segment around and unaltered.
I just spent 1 or 2 hours trying to debug why this simple usage case does not work at all
Basically this code would run but when I try and use
mySyslog->log
I get false as a return value. I spent a while troubleshooting my code before I looked at your implementation ofSyslog.cpp
. It was pretty obvious that my problem was the constructor just stores the pointer, not copies it. If you read the configuration from some dynamic source it means you can't pass in a stack variable.I switched to using a global array for my hostname and it worked fine.
I think this implementation is fine, but it might save others some headache if you added notes warning them the constructor does not make deep copies and the caller must keep the memory segment around and unaltered.