<div dir="ltr"><div>Cheers,</div><div><br></div><div> I don't think there is any particular strategy, at least not one I'd know of either :) So it is mostly ad-hoc, to keep smaller verbosity numbers reasonably quiet, and sufficient info to see the logic progression at a given debug level (e.g. if major milestones of a routine are logged at level N, further traces like "I saw value X here" would be N+1 or more). De-facto verbosities fizzle out at 6, but generally it is an int value, so...<br></div><div><br></div><div> Regarding syslog/stdout/stderr, the upsdebugx*() methods are defined here and near: <a href="https://github.com/networkupstools/nut/blob/ad70749f243527e774c3f03a08228430143396e9/common/common.c#L1205">https://github.com/networkupstools/nut/blob/ad70749f243527e774c3f03a08228430143396e9/common/common.c#L1205</a> and end up calling vupslog() at which can report to stderr (not stdout) and/or syslog, based on settings - see around <a href="https://github.com/networkupstools/nut/blob/ad70749f243527e774c3f03a08228430143396e9/common/common.c#L1011">https://github.com/networkupstools/nut/blob/ad70749f243527e774c3f03a08228430143396e9/common/common.c#L1011</a>. The
UPSLOG_STDERR bit is set by default, but cleared in the background() method, along with raising the <span class="gmail-pl-en">UPSLOG_SYSLOG bit</span>. By default enabled debug means staying foreground, so the bits are not changed. However "recently" the explicit -F/-B flags were added to manipulate fore-/back-grounding independently of debug (default behavior remains as it was).<br></div><div><br></div><div> Note that daemons started under service management frameworks like SMF or systemd can remain in "foreground" mode (with backgrounding handled by framework forking itself), so continue logging to stderr with messages landing into systemd journal or SMF service-instance log file.<br></div><div><br></div><div> A few programs are more explicit about this, e.g.:</div><div>````</div><div>:; git grep -n syslogbit_set<br>
common/common.c:130:void syslogbit_set(void)<br>
include/common.h:234:void syslogbit_set(void);<br>
<br>clients/upssched.c:1341: syslogbit_set();<br>drivers/main.c:1052: syslogbit_set();<br>server/upsd.c:1827: syslogbit_set();<br></div><div>````<br></div><div><br></div><div>>
So upsdebugx should therefore 1) not have the driver name and 2) should have a function, for things that aren't clearly locatable. Correct? <br></div><div><br></div><div>1) I don't think it prints a driver name (at least not by itself - maybe some drivers or other programs pass format strings which hardcode such stuff).</div><div>2) a common incantation is `upsdebugx(NUM, "%s: some text", __func__);` to take advantage of modern compilers providing the __func__ macro. Technically also __FILE__ and __LINE__ may be used. Neither is guaranteed across the portability board however, but that is likely to only bite very old systems nowadays. The `configure` script tries some fallbacks for __func__ but not for others.<br></div><div><br></div><div>As for
s_upsdebug_ascii() - I do not think it is a perfectly good idea to change it (maybe is - not much used in NUT codebase; but possibly some forks have more use for it). <br></div><div>It sounds reasonable however to define and implement a different method for this purpose, when you expect that sort of content - and call it where suitable.</div><div><br></div><div>Maybe makes sense to create a typical hexdump printer along the lines of <a href="https://gist.github.com/jimklimov/07913a3e30a7d7ec50e9c946117c994f#file-jenkins-credump-L17-L41">https://gist.github.com/jimklimov/07913a3e30a7d7ec50e9c946117c994f#file-jenkins-credump-L17-L41</a> (that particular code is groovy, but trivial to convert elsewhere).</div><div><br></div><div>Jim<br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Jan 15, 2023 at 5:12 PM Greg Troxel <<a href="mailto:gdt@lexort.com">gdt@lexort.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I am looking at bestfortress and trying to figure out and fix some<br>
things, which is causing me to try to improve logging first. A few<br>
questions:<br>
<br>
0) The developer guide doesn't seem to address any of this, or did I<br>
miss it?<br>
<br>
1) It seems upsdebugx prints to stdout instead of syslog if in<br>
foreground. That's great but I didn't figure it out from docs.<br>
<br>
2) I didn't find a plan for debug levels, so I made one up for<br>
bestfortress and put it in comments. Did I miss a plan? Should there<br>
be on in common.h? someplace else? Probably it's ok for each driver<br>
to have its own plan.<br>
<br>
3) It looks like upsdebugx either prints (if foreground) or syslog, and<br>
if syslog one gets the program name. So upsdebugx should therefore 1)<br>
not have the driver name and 2) should have a function, for things that<br>
aren't clearly locatable. Correct?<br>
<br>
4) I want to print mostly-ASCII strings with non-ASCII escaped. Is<br>
there a routine to convert strings? s_upsdebug_ascii output is<br>
difficult for mostly-ascii. There is a log of a read string "\nOK" that<br>
is messy (and there's a real bug lurking that this exposes).<br>
<br>
I think I want (actually I want octal because I was raised PDP-11, but<br>
not trying to rock that boat):<br>
<br>
ABCD\{LF}EFG\[89]\\<br>
<br>
or similar for printf("ABCD\nEFG%c\\", 0x89). The point is to be<br>
- compact for mostly ascii<br>
- unambigous<br>
- guaranteed printable only<br>
- otherwise as simple as possible<br>
<br>
How would people feel about adjusting upsdebug_ascii to do this? I<br>
would consider a PR if it is ok, and skip the effort if not.<br>
<br>
<br>
<br>
_______________________________________________<br>
Nut-upsdev mailing list<br>
<a href="mailto:Nut-upsdev@alioth-lists.debian.net" target="_blank">Nut-upsdev@alioth-lists.debian.net</a><br>
<a href="https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsdev" rel="noreferrer" target="_blank">https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsdev</a><br>
</blockquote></div>