+static int open_new_logfile(struct dataparser_struct *dt, int channel)
+{
+ char path[2048];
+ struct tm *tm;
+ time_t cur_time = time(NULL);
+
+ tm = localtime(&cur_time);
+ strftime(path, sizeof(path), dt->cfg->log_path, tm);
+
+ store_int_variable_value_to_array("channel", channel, dt->cfg);
+ replace_variables_with_values(path, sizeof(path), dt->cfg);
+
+ pr_debug("Opening %s for writing the log file\n", path);
+
+ dt->outfd[channel] = open(path, O_CREAT | O_APPEND | O_WRONLY, 0664);
+ if (dt->outfd[channel] < 0) {
+ pr_err("Failed to open file %s for writing: %m\n",
+ path);
+ return -1;
+ }
+
+ return 0;
+}
+