Chris's Wiki :: blog/programming/DontBreakUpMessages Commentshttps://utcc.utoronto.ca/~cks/space/blog/programming/DontBreakUpMessages?atomcommentsDWiki2014-12-20T11:24:39ZRecent comments in Chris's Wiki :: blog/programming/DontBreakUpMessages.By Matrixik on /blog/programming/DontBreakUpMessagestag:CSpace:blog/programming/DontBreakUpMessages:9961facf698d89b6f03bbfcc855dd25a0af37ef0Matrixik<div class="wikitext"><p>dozzie: you can do something similar in Go with <a href="https://github.com/inconshreveable/log15">https://github.com/inconshreveable/log15</a></p>
<pre>
log.Error("CE_NOTE", log.Ctx{
"message": "iscsi connection unable to connect to target",
"connection": conn_oid,
"target": sess_name,
})
</pre>
</div>2014-12-20T11:24:39ZBy Chris Siebenmann on /blog/programming/DontBreakUpMessagestag:CSpace:blog/programming/DontBreakUpMessages:d866a0c30ac0bb99678375ad0d208dd37fead663Chris Siebenmann<div class="wikitext"><p>dozzie: I think I was unclear in my entry. I'm okay with the form you
used here because the actual textual message is all on one line, so
it's easy to search for. In my example I'd have been happy if the two
literal strings were one string, ie '<code>"iscsi connection(%u) unable to
connect to target %s"</code>'.</p>
<p>(It actually requires slightly unnatural contortions to break them up;
the first string has a trailing space before the closing <code>"</code> because C
string concatenation doesn't create one for you.)</p>
</div>2014-10-03T20:13:32ZBy ozan yigit on /blog/programming/DontBreakUpMessagestag:CSpace:blog/programming/DontBreakUpMessages:bbfd4892125c46db0289013ddee7e96f3caad498ozan yigithttps://plus.google.com/+ozanozyigit/posts<div class="wikitext"><p>hmm my sympaties. reminds me of a related situation: a long time ago i needed to search and analyze multi-line function declarations and calls [often with many longHungarianNotationNames :)]. I wrote a code matcher with a simplified C-like-language parser that understood the structure of comments, strings, function headers, blocks, and function calls, flatten them so I can pattern match across function declarations and function calls. don't remember offhand if I concatenated the strings - this is pre-C99 - though that would be an easy fix.</p>
</div>2014-10-03T15:12:07ZBy dozzie on /blog/programming/DontBreakUpMessagestag:CSpace:blog/programming/DontBreakUpMessages:2f4e4d7f20c9e18bdaa7be47cdd2dea1bf2cb914dozzie<div class="wikitext"><p>Actually, it's not quite worth it to have such long lines. But there is
a method, which results as side effects in both, short code lines and messages
kept in a single line. It's logging with structure. In Perl or Python it would
go like this:</p>
<pre>
$logger->error("CE_NOTE", {
message => "iscsi connection unable to connect to target",
connection => $icp->conn_oid,
target => $icp->conn_sess->sess_name,
});
logger.error("CE_NOTE", {
"message": "iscsi connection unable to connect to target",
"connection": $icp->conn_oid,
"target": $icp->conn_sess->sess_name,
})
</pre>
<p>My colleague did (after my few hints) something of similar usage in C++ (with
`std::initializer_list`). I bet one could do such thing for C (probably with
some printf-like formatting), but I don't write much C recently and I didn't
have an opportunity to think about it for real uses.</p>
</div>2014-09-30T18:35:21Z