<?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>Read the log file backend FS</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/114961/read-the-log-file-backend-fs</link><description>Hello Nordic team, 
 
 I want to be able to save the log into a file and then read it in order to send it&amp;#39;s content via HID. 
 
 I&amp;#39;ve managed to make the log back end FS work (I can see the file&amp;#39;s size increasing). 
 But when I want to read it&amp;#39;s content</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 04 Feb 2026 13:47:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/114961/read-the-log-file-backend-fs" /><item><title>RE: Read the log file backend FS</title><link>https://devzone.nordicsemi.com/thread/560347?ContentTypeID=1</link><pubDate>Wed, 04 Feb 2026 13:47:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:faf680bd-477d-471d-b73a-be3ec689a553</guid><dc:creator>MehdiZ</dc:creator><description>&lt;p&gt;Hi Martin,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m facing a similar problem.&lt;/p&gt;
&lt;p&gt;What I&amp;#39;m trying to achieve is to&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Disable logging&lt;/li&gt;
&lt;li&gt;Delete old log file and create new log file (or truncate the existing file)&lt;/li&gt;
&lt;li&gt;Enable logging&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And for the same reasons you describe(the file_t structure inside the logging backend), I&amp;#39;m unable to cleanly delete/truncate the log file.&lt;/p&gt;
&lt;p&gt;Did you find a solution to your issue?&lt;/p&gt;
&lt;p&gt;Thanks in advance,&lt;/p&gt;
&lt;p&gt;Mehdi&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Read the log file backend FS</title><link>https://devzone.nordicsemi.com/thread/504067?ContentTypeID=1</link><pubDate>Thu, 26 Sep 2024 21:16:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2070aecf-4fb1-4bed-8058-dc09273782a5</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hi Martin,&lt;/p&gt;
&lt;p&gt;Sorry, I don&amp;#39;t have any input here. But I am very interested if you find out more on this from the zephyr community.&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Read the log file backend FS</title><link>https://devzone.nordicsemi.com/thread/504028?ContentTypeID=1</link><pubDate>Thu, 26 Sep 2024 15:35:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d26ef78a-fe14-4eb9-a979-db0506203077</guid><dc:creator>Martdur</dc:creator><description>&lt;p&gt;The issues is that the&amp;nbsp;struct fs_file_t is both created in the application code and in the log_backend_fs driver.&lt;/p&gt;
&lt;p&gt;This isn&amp;#39;t very convenient as it is right now.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m trying to figure it out how I can pass the struct as a pointer in order to modify it from the app.&lt;/p&gt;
&lt;p&gt;There is a ctx field in the backend struct that can be useful.&lt;/p&gt;
&lt;p&gt;Another way to do it will be to add the deletion in one of the log_backend api functions.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If you have any-input how to do so I&amp;#39;ll be glad to hear it and I can propose the changes on the zephyr github.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks in advance.&lt;/p&gt;
&lt;p&gt;Best regards.&lt;/p&gt;
&lt;p&gt;Martin.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Read the log file backend FS</title><link>https://devzone.nordicsemi.com/thread/504003?ContentTypeID=1</link><pubDate>Thu, 26 Sep 2024 13:23:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:248404df-bd0d-497d-9ac4-41fc89de4830</guid><dc:creator>Martdur</dc:creator><description>&lt;p&gt;Is there a way to do so ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For the moment I do :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;	int ret = fs_open(&amp;amp;this-&amp;gt;file, this-&amp;gt;path.path, FS_O_WRITE);
	if (ret &amp;lt; 0)
	{
		LOG_ERR(&amp;quot;Error opening file: %d&amp;quot;, ret);
		return ret;
	}
	
	ret = fs_truncate(&amp;amp;file, 0);
	if (ret &amp;lt; 0)
	{
		LOG_ERR(&amp;quot;Error truncating file: %d&amp;quot;, ret);
		return ret;
	}
	else
	{
		LOG_INF(&amp;quot;File content cleared successfully&amp;quot;);
	}

	ret = fs_seek(&amp;amp;this-&amp;gt;file,
				  0,
				  FS_SEEK_SET);
	fs_sync(&amp;amp;file);
	fs_close(&amp;amp;file);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve check the size everything is fine the size is set to 0 and the position is at the beginning of the file.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;But as soon as I received some log message, they are written at the old end of file position and the size is increased to the original size + the new log.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;It&amp;#39; seems that the log_backend_fs use another stored position and size that the file system does.&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t understand why because in&amp;nbsp;&lt;span&gt;log_backend_fs.c we use:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;static struct fs_file_t fs_file;&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Martin.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Read the log file backend FS</title><link>https://devzone.nordicsemi.com/thread/503954?ContentTypeID=1</link><pubDate>Thu, 26 Sep 2024 11:24:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:22a66e58-2eba-49ed-b621-f5448122b2c6</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hmm.. what if you empty the content of the file, but keep the file?&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Read the log file backend FS</title><link>https://devzone.nordicsemi.com/thread/503901?ContentTypeID=1</link><pubDate>Thu, 26 Sep 2024 08:45:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:45816f8f-db53-4981-93d6-6ea2e36edf5c</guid><dc:creator>Martdur</dc:creator><description>&lt;p&gt;I&amp;#39;ve managed to read the content of the log file using :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;const struct log_backend *backend = log_backend_get(0);
log_backend_deactivate(backend);
this-&amp;gt;Create();
PrintAllFileChar();
this-&amp;gt;Close();
log_backend_activate(backend,NULL);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The issues I&amp;#39;m facing now is that I can&amp;#39;t delete the log file recreate it and then reactivate the log_backend.&lt;/p&gt;
&lt;p&gt;When I do so :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;this-&amp;gt;Close();
this-&amp;gt;Delete();
log_backend_init(backend);
log_backend_activate(backend, NULL);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The log doesn&amp;#39;t write data in the file anymore.&lt;/p&gt;
&lt;p&gt;Am I missing somethings ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The behavior that I want is that when I read the content of the file I delete all that has been read.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Read the log file backend FS</title><link>https://devzone.nordicsemi.com/thread/503799?ContentTypeID=1</link><pubDate>Wed, 25 Sep 2024 14:25:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:879d69ca-f5f2-47ca-927b-c43f09ea65bc</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Looking at the example I can find it uses:&lt;/p&gt;
&lt;p&gt;CONFIG_LOG_BACKEND_FS_FILE_SIZE=128&lt;br /&gt;CONFIG_LOG_BACKEND_FS_FILES_LIMIT=4&lt;/p&gt;
&lt;p&gt;Maybe it will just go back to the first file when the last file is filled?&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Read the log file backend FS</title><link>https://devzone.nordicsemi.com/thread/503798?ContentTypeID=1</link><pubDate>Wed, 25 Sep 2024 14:24:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5bca268c-889d-4cc9-9f4a-f30b021c1fd1</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Can you try to reduce size and increase the number of files? e.g.&lt;/p&gt;
&lt;p&gt;CONFIG_LOG_BACKEND_FS_FILE_SIZE=1000&lt;br /&gt;CONFIG_LOG_BACKEND_FS_FILES_LIMIT=1000&lt;/p&gt;
&lt;p&gt;That I would expect you can read files that have been filled at least?&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Read the log file backend FS</title><link>https://devzone.nordicsemi.com/thread/503758?ContentTypeID=1</link><pubDate>Wed, 25 Sep 2024 12:55:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:053f95ad-d87b-4ec0-a726-463413310704</guid><dc:creator>Martdur</dc:creator><description>&lt;p&gt;Hello Kenneth,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks for the answer.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve already tried to close the file, this leading to an hardfault (While closing the file).&lt;/p&gt;
&lt;p&gt;I&amp;#39;m using the Kconfig to activate the log file :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;
CONFIG_FILE_SYSTEM_IMAGE_PATH=&amp;quot;/lfs_ext_flash&amp;quot;
#Log file backend
CONFIG_LOG_BACKEND_FS=y
CONFIG_LOG_BACKEND_FS_DIR=&amp;quot;/lfs_ext_flash&amp;quot;
CONFIG_LOG_BACKEND_FS_FILE_SIZE=6400000
CONFIG_LOG_BACKEND_FS_FILES_LIMIT=1&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Is there a way to re-direct the log_backend_fs to another file or to stop it at runtime ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Because right now it appears that I can&amp;#39;t do anything with this file with this feature activated.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards.&lt;/p&gt;
&lt;p&gt;Martin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Read the log file backend FS</title><link>https://devzone.nordicsemi.com/thread/503751?ContentTypeID=1</link><pubDate>Wed, 25 Sep 2024 12:32:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1bd4b121-c1cf-44c7-aece-76b6cfd6d901</guid><dc:creator>Kenneth</dc:creator><description>[quote user=""]&lt;p&gt;But when I want to read it&amp;#39;s content I get an hard fault.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I think I need to stop the log to be written to the file before reading it.&lt;/p&gt;[/quote]
&lt;p&gt;I think it sounds reasonable that you should close the file before reading it. Maybe you need to even switch between writing and reading, and have some buffers where you can store data intermittently. Maybe you can also create several files, such that you can read files that are currently not being written to. I don&amp;#39;t have any good pointers here, this is very much up how you have made the log backend write to the file system in the first place, but I think you are on the right path on how I would have solved it at least.&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>