Syslog icon indicating copy to clipboard operation
Syslog copied to clipboard

Add ability to specify appName on per log message

Open sticilface opened this issue 8 years ago • 6 comments

Hi,

use senario: I have several libraries running on the same ESP, doing a variety of things. With debugging enabled I'd like to be able to send debug messages from different bit of software on the same device. so the device name is the same, but the app name is different.

Would be great to have overloads to be able to specify the log level and app name for a message.

what do you think?

sticilface avatar Feb 01 '17 18:02 sticilface

Yes it's possible to implement. There is only one problem with logf functions without pri parameter because of varargs. You cannot have defined both logf(char *, ...) and logf(char *, char *, ...).

Anyway in one of my project I call appName before log / logf methods to do same as you describe:

IPAddress ip = WiFi.localIP();
syslog.appName("network").logf(LOG_INFO, "Assigned %s.local [%u.%u.%u.%u]", DEVICE_HOSTNAME, ip[0], ip[1], ip[2], ip[3]);

Only caveats is that appName store the value for following calls of log / logf. So you have it everywhere.

arcao avatar Feb 01 '17 21:02 arcao

yes. i realised that. and there is no function to fetch it, set the new one, then set it back to the old one!

sticilface avatar Feb 02 '17 09:02 sticilface

i wonder what the most elegant solution would be. Think its worth having!

sticilface avatar Feb 02 '17 09:02 sticilface

I've come up with a method that might work. I'm going to try an roll it into my own syslog attempt for my ESPManager software. I've written a string class with derived versions myStringf and mystgingf_P with constructors that take the .... This allows you to do this:

log( "appName", myStringf_P( PSTR("Test %u"), "123" ); 
log( "appName", myStringf("Test %u", "123" ); 
log( "appName", "123" ); 

Using the right move semantics makes it efficient...

sticilface avatar Feb 22 '17 22:02 sticilface

I've use some of your code to write my own syslog client, mainly the log mask stuff and message generation. I've given you credit for it at the top of the .h is that ok. There is no licence in the repo so I want to check? Its all none profit, open source stuff.

sticilface avatar Feb 23 '17 14:02 sticilface

I closed this by accident. sorry.

sticilface avatar Mar 07 '17 22:03 sticilface