<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Enhance NRF LOG to include line number in prefix</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/44436/enhance-nrf-log-to-include-line-number-in-prefix</link><description>Hello, 
 I want to modify the NRF logging module to include the line number where the log was originated. 
 In the past I created a wrapper macro that called NRF_LOG_INFO twice, once with the desired prefix and one with the actual string I wanted to print</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 06 Mar 2019 10:18:45 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/44436/enhance-nrf-log-to-include-line-number-in-prefix" /><item><title>RE: Enhance NRF LOG to include line number in prefix</title><link>https://devzone.nordicsemi.com/thread/174493?ContentTypeID=1</link><pubDate>Wed, 06 Mar 2019 10:18:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:18b21223-950d-4aa3-aebd-85b75afe93f8</guid><dc:creator>Andy</dc:creator><description>&lt;p&gt;Mm I think this will have the same issue as with the macro, i.e. the arguments won&amp;#39;t get parsed.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Enhance NRF LOG to include line number in prefix</title><link>https://devzone.nordicsemi.com/thread/174484?ContentTypeID=1</link><pubDate>Wed, 06 Mar 2019 10:05:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ced887e4-e56c-4bec-84fd-8a4c4d698de6</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;in your header:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static inline void log_with_location( char * stuff )
{
   NRF_LOG_INFO(&amp;quot;%-25s:%4d:%8lu: %s&amp;quot;, __FILE__, __LINE__, timestamp(), stuff );
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;in your code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;quot;log_with_location.h&amp;quot;

:
:

   log_with_location( stuff ); // If __LINE__ and __FILLE__ get expanded here, 
                               // they will refer to this location!

:
:
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Enhance NRF LOG to include line number in prefix</title><link>https://devzone.nordicsemi.com/thread/174372?ContentTypeID=1</link><pubDate>Tue, 05 Mar 2019 18:06:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6fd0af7a-d228-4f19-91d3-2c5955980374</guid><dc:creator>Andy</dc:creator><description>&lt;p&gt;Assuming that it works, what would the inline function look like?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Enhance NRF LOG to include line number in prefix</title><link>https://devzone.nordicsemi.com/thread/174371?ContentTypeID=1</link><pubDate>Tue, 05 Mar 2019 18:05:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:44fed906-68bc-48c4-b501-0ebc2708e65c</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;like I said, it depends on when the __FILE__ and __LINE__ get expanded in an inline file - it&amp;#39;s only useful if they get expanded at the point where the function is inlined (ie, the call).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Enhance NRF LOG to include line number in prefix</title><link>https://devzone.nordicsemi.com/thread/174370?ContentTypeID=1</link><pubDate>Tue, 05 Mar 2019 18:02:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5d042d5d-0a59-4962-9be2-568c425c4563</guid><dc:creator>Andy</dc:creator><description>&lt;p&gt;Yeah, calling NRF_LOG_INFO multiple times (which is what I don&amp;#39;t want to do):&lt;/p&gt;
&lt;p&gt;&lt;span&gt;#define debug(...) do { NRF_LOG_INFO(&lt;/span&gt;&lt;span&gt;&amp;quot;%-25s:%4d:%8lu: &amp;quot;&lt;/span&gt;&lt;span&gt;, __FILE__, __LINE__, timestamp()); NRF_LOG_INFO(__VA_ARGS__); } while(0)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;How would an inline function call be different? What would it look like?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Enhance NRF LOG to include line number in prefix</title><link>https://devzone.nordicsemi.com/thread/174364?ContentTypeID=1</link><pubDate>Tue, 05 Mar 2019 17:15:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:144014d8-c5c6-4905-bdc3-4b141d55c73e</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;But that&amp;#39;s &lt;em&gt;macros&lt;/em&gt; - I&amp;#39;m talking about a proper &lt;em&gt;function&lt;/em&gt; call.&lt;/p&gt;
&lt;p&gt;For macros, you&amp;#39;d have to get down &amp;amp; dirty with the stringification stuff ... ?&lt;/p&gt;
&lt;p&gt;&lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f62e.svg" title="Open mouth"&gt;&amp;#x1f62e;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;But you said you already had this working with macros?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Enhance NRF LOG to include line number in prefix</title><link>https://devzone.nordicsemi.com/thread/174360?ContentTypeID=1</link><pubDate>Tue, 05 Mar 2019 16:34:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:401aefb8-67f5-4fba-8b34-45b63979f081</guid><dc:creator>Andy</dc:creator><description>&lt;p&gt;i.e. if I called debug(&amp;quot;x = %d&amp;quot;, x); it would print&lt;/p&gt;
&lt;p&gt;main.c: 100: 23: x = %d&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Enhance NRF LOG to include line number in prefix</title><link>https://devzone.nordicsemi.com/thread/174359?ContentTypeID=1</link><pubDate>Tue, 05 Mar 2019 16:32:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8c607563-9895-46d2-9e53-791c269ce693</guid><dc:creator>Andy</dc:creator><description>&lt;p&gt;I already tried something like that:&lt;/p&gt;
&lt;p&gt;#define debug(...)&amp;nbsp;NRF_LOG_INFO(&lt;span&gt;&amp;quot;%-25s:%4d:%8lu: %s&amp;quot;&lt;/span&gt;, __FILE__, __LINE__, timestamp(), __VA_ARGS__)&lt;/p&gt;
&lt;p&gt;But the arguments weren&amp;#39;t being processed.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Enhance NRF LOG to include line number in prefix</title><link>https://devzone.nordicsemi.com/thread/174358?ContentTypeID=1</link><pubDate>Tue, 05 Mar 2019 16:24:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3ff91bfa-c7ce-4790-936a-3830bf5506d7</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;I was thinking of making the inline function the thing that you actually place in your code - so the line where it&amp;#39;s called is the one you want&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Enhance NRF LOG to include line number in prefix</title><link>https://devzone.nordicsemi.com/thread/174353?ContentTypeID=1</link><pubDate>Tue, 05 Mar 2019 16:15:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eb39560e-9c61-4fe8-a4a7-ece00d4037bc</guid><dc:creator>Andy</dc:creator><description>&lt;p&gt;Mm I&amp;#39;m not sure, but neither of those cases is useful to me. It will either always show the line where it was defined, or it will always show the line where it was called (which would always be in nrf_log_frontend.c)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Enhance NRF LOG to include line number in prefix</title><link>https://devzone.nordicsemi.com/thread/174331?ContentTypeID=1</link><pubDate>Tue, 05 Mar 2019 15:13:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:52aebbe7-b472-445b-bf02-e92281350963</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;Just a thought:&lt;/p&gt;
&lt;p&gt;If you use an &amp;#39;&lt;strong&gt;inline&lt;/strong&gt;&amp;#39; function, do __FILE__ and __LINE__ expand according to where the function was defined, or where it was inlined (called) ... ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Enhance NRF LOG to include line number in prefix</title><link>https://devzone.nordicsemi.com/thread/174320?ContentTypeID=1</link><pubDate>Tue, 05 Mar 2019 14:44:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:da55325a-05e3-4aaa-847e-84704b9685b1</guid><dc:creator>Andy</dc:creator><description>&lt;p&gt;To be more specific, how would I create a function that returns different line numbers of calls that happened elsewhere in the code?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Enhance NRF LOG to include line number in prefix</title><link>https://devzone.nordicsemi.com/thread/174319?ContentTypeID=1</link><pubDate>Tue, 05 Mar 2019 14:43:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3b798bf8-ccec-4f03-909e-12a24a9c3e6e</guid><dc:creator>Andy</dc:creator><description>&lt;p&gt;How would I use that?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Enhance NRF LOG to include line number in prefix</title><link>https://devzone.nordicsemi.com/thread/174309?ContentTypeID=1</link><pubDate>Tue, 05 Mar 2019 14:27:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4b3ed812-761a-4647-9b06-1786ba5105b5</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t know if this is what you&amp;#39;re after, but maybe you&amp;#39;d want to modify an already existing function, I.E. modify the NRF_LOG USES_TIMESTAMP function to instead of timestamps, output the line you want. Or at least use that function as a template.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Enhance NRF LOG to include line number in prefix</title><link>https://devzone.nordicsemi.com/thread/174301?ContentTypeID=1</link><pubDate>Tue, 05 Mar 2019 14:18:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7af4153d-5232-4186-b7c0-47c31c67b01e</guid><dc:creator>Andy</dc:creator><description>&lt;p&gt;At least not without creating a wrapper macro that calls NRF_LOG_INFO twice, which is what I already did.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Enhance NRF LOG to include line number in prefix</title><link>https://devzone.nordicsemi.com/thread/174300?ContentTypeID=1</link><pubDate>Tue, 05 Mar 2019 14:17:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1f742a7a-74b3-46e6-ab30-7b4c5c9452cb</guid><dc:creator>Andy</dc:creator><description>&lt;p&gt;Yeah, that&amp;#39;s basically what I want to do, but it&amp;#39;s not trivial as far as I can tell.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Enhance NRF LOG to include line number in prefix</title><link>https://devzone.nordicsemi.com/thread/174294?ContentTypeID=1</link><pubDate>Tue, 05 Mar 2019 14:10:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c048b4a9-9539-4970-ae48-08c9505d5a44</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;Yes, I would say you&amp;#39;d have to pass __LINE__ as parameter, and have your formatter put that into the string...&lt;/p&gt;
&lt;p&gt;Something like this:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://stackoverflow.com/a/15885297/4618900"&gt;https://stackoverflow.com/a/15885297/4618900&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;EDIT&lt;/p&gt;
&lt;p&gt;Fix link&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Enhance NRF LOG to include line number in prefix</title><link>https://devzone.nordicsemi.com/thread/174285?ContentTypeID=1</link><pubDate>Tue, 05 Mar 2019 14:00:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:599c7ea6-ec0d-486e-b9e0-7931b53eab24</guid><dc:creator>Andy</dc:creator><description>&lt;p&gt;And I think I&amp;#39;d have to modify starting from the macros, inserting __LINE__ somewhere.&lt;/p&gt;
&lt;p&gt;If I add __LINE__ somewhere in the string formatter module it will print the line in that source file, not the line where the NRF_LOG_INFO macro was initially called from.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Enhance NRF LOG to include line number in prefix</title><link>https://devzone.nordicsemi.com/thread/174281?ContentTypeID=1</link><pubDate>Tue, 05 Mar 2019 13:50:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96f481b3-30e9-420a-bf1c-88f8f24a064d</guid><dc:creator>Andy</dc:creator><description>&lt;p&gt;I know I have to modify the source... I&amp;#39;m asking for some hints about what to modify. The logging module is kind of like a cascade of macros. One after another after another.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Enhance NRF LOG to include line number in prefix</title><link>https://devzone.nordicsemi.com/thread/174277?ContentTypeID=1</link><pubDate>Tue, 05 Mar 2019 13:43:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9c581ad5-5585-4581-a53a-4040a4d9482b</guid><dc:creator>awneil</dc:creator><description>[quote userid="15909" url="~/f/nordic-q-a/44436/enhance-nrf-log-to-include-line-number-in-prefix"]What would be the best way to do this?[/quote]
&lt;p&gt;Examine the source of the existing logging functions, and modify to suit.&lt;/p&gt;
&lt;p&gt;Only the string formatting should be affected - not the transmission functions.&lt;/p&gt;
&lt;p&gt;You will probably need to understand how variadic functions work in &amp;#39;C&amp;#39; ...&lt;/p&gt;
&lt;p&gt;&lt;a href="https://en.cppreference.com/w/c/variadic"&gt;https://en.cppreference.com/w/c/variadic&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>