Add --log-append option

Add --log-append option which makes tio append to any existing log file.

This also changes the default behaviour of tio from appending to
overwriting any existing log file. Now you have to use this new option
to make tio append.
This commit is contained in:
Martin Lund 2023-04-28 20:50:31 +02:00
parent 3bedd85e7c
commit 148a3c1da1
7 changed files with 28 additions and 2 deletions

View file

@ -22,6 +22,7 @@ no-autoconnect = disable
hexadecimal = disable
timestamp = disable
log = disable
log-append = disable
log-strip = disable
local-echo = disable
color = bold

View file

@ -141,6 +141,11 @@ The filename can be manually set using the \-\-log-file option.
Set log filename.
.TP
.BR " \-\-log-append
Append to log file.
.TP
.BR " \-\-log-strip

View file

@ -108,6 +108,10 @@ OPTIONS
Set log filename.
--log-append
Append to log file.
--log-strip
Strip control characters and escape sequences from log.

View file

@ -198,6 +198,10 @@ static int data_handler(void *user, const char *section, const char *name,
asprintf(&c.log_filename, "%s", value);
option.log_filename = c.log_filename;
}
else if (!strcmp(name, "log-append"))
{
option.log_append = read_boolean(value, name);
}
else if (!strcmp(name, "log-strip"))
{
option.log_strip = read_boolean(value, name);

View file

@ -69,8 +69,17 @@ int log_open(const char *filename)
log_filename = filename;
// Open log file in append write mode
// Open log file
if (option.log_append)
{
// Appends to existing log file
fp = fopen(filename, "a+");
}
else
{
// Truncates existing log file
fp = fopen(filename, "w+");
}
if (fp == NULL)
{
tio_warning_printf("Could not open log file %s (%s)", filename, strerror(errno));

View file

@ -74,6 +74,7 @@ struct option_t option =
.ri_pulse_duration = 100,
.no_autoconnect = false,
.log = false,
.log_append = false,
.log_filename = NULL,
.log_strip = false,
.local_echo = false,
@ -119,6 +120,7 @@ void print_help(char *argv[])
printf(" -L, --list-devices List available serial devices by ID\n");
printf(" -l, --log Enable log to file\n");
printf(" --log-file <filename> Set log filename\n");
printf(" --log-append Append to log file\n");
printf(" --log-strip Strip control characters and escape sequences\n");
printf(" -m, --map <flags> Map characters\n");
printf(" -c, --color 0..255|bold|none|list Colorize tio text (default: bold)\n");

View file

@ -48,6 +48,7 @@ struct option_t
unsigned int ri_pulse_duration;
bool no_autoconnect;
bool log;
bool log_append;
bool log_strip;
bool local_echo;
enum timestamp_t timestamp;