You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/06/04 03:17:56 UTC

[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a change in pull request #3842: Added automatic log rotation, when log file is opened.

xiaoxiang781216 commented on a change in pull request #3842:
URL: https://github.com/apache/incubator-nuttx/pull/3842#discussion_r645261641



##########
File path: drivers/syslog/syslog_filechannel.c
##########
@@ -108,6 +168,12 @@ FAR struct syslog_channel_s *syslog_file_channel(FAR const char *devpath)
       syslog_dev_uninitialize(g_syslog_file_channel);
     }
 
+  /* Rotate the log file, if needed. */
+
+#ifdef CONFIG_SYSLOG_FILE_ROTATE
+  log_rotate(devpath);

Review comment:
       how to handle the long live device? some device may run many day and then the log size will become very very big. It's better to detect the file size reach to the limitation in the write/putc/force_putc callback. We can save the initial file size after opening the file, and increase this value in these callback and rename the file once the limitation reach.

##########
File path: drivers/syslog/syslog_filechannel.c
##########
@@ -50,6 +54,62 @@
 
 FAR static struct syslog_channel_s *g_syslog_file_channel;
 
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#ifdef CONFIG_SYSLOG_FILE_ROTATE
+static void log_rotate(FAR const char *log_file)
+{
+  int fd;
+  off_t size;
+  struct stat f_stat;
+  char *backup_file;

Review comment:
       add FAR

##########
File path: drivers/syslog/syslog_filechannel.c
##########
@@ -50,6 +54,62 @@
 
 FAR static struct syslog_channel_s *g_syslog_file_channel;
 
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#ifdef CONFIG_SYSLOG_FILE_ROTATE
+static void log_rotate(FAR const char *log_file)
+{
+  int fd;
+  off_t size;
+  struct stat f_stat;
+  char *backup_file;
+
+  /* Get the size of the current log file. */
+
+  fd = open(log_file, O_RDONLY);

Review comment:
       it's prefer to call nx_xxx or file_xxx in kernel space.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org