Logging: Filter out unwanted newlines
055804e89e
changed the outgoing
SCPI message termination by always adding a newline. This results
in the following log output:
sr: [00:00.003102] scpi: Opening VXI device vxi/192.168.178.43.
sr: [00:00.005648] scpi_vxi: Successfully sent SCPI command: '*IDN?
'.
sr: [00:00.005931] scpi: Got response: 'YOKOGAWA,710130,91HC30402,F3.73', length 31.
This patch restores the previous unterminated SCPI message logging:
sr: [00:00.005462] scpi: Opening VXI device vxi/192.168.178.43.
sr: [00:00.007515] scpi_vxi: Successfully sent SCPI command: '*IDN?'.
sr: [00:00.007860] scpi: Got response: 'YOKOGAWA,710130,91HC30402,F3.73', length 31.
As it's located in the general logging mechanism, we deal with any
additional (and unwanted) newlines this way.
This commit is contained in:
parent
e264ebded8
commit
4d6d660b83
22
src/log.c
22
src/log.c
|
@ -163,7 +163,8 @@ static int sr_logv(void *cb_data, int loglevel, const char *format, va_list args
|
|||
{
|
||||
uint64_t elapsed_us, minutes;
|
||||
unsigned int rest_us, seconds, microseconds;
|
||||
int ret;
|
||||
char *raw_output, *output;
|
||||
int raw_len, raw_idx, idx, ret;
|
||||
|
||||
/* This specific log callback doesn't need the void pointer data. */
|
||||
(void)cb_data;
|
||||
|
@ -186,10 +187,25 @@ static int sr_logv(void *cb_data, int loglevel, const char *format, va_list args
|
|||
ret = fputs("sr: ", stderr);
|
||||
}
|
||||
|
||||
if (ret < 0 || g_vfprintf(stderr, format, args) < 0
|
||||
|| putc('\n', stderr) < 0)
|
||||
if (ret < 0 || (raw_len = g_vasprintf(&raw_output, format, args)) < 0)
|
||||
return SR_ERR;
|
||||
|
||||
output = g_malloc0(raw_len + 1);
|
||||
|
||||
/* Copy the string without any unwanted newlines. */
|
||||
raw_idx = idx = 0;
|
||||
while (raw_idx < raw_len) {
|
||||
if (raw_output[raw_idx] != '\n') {
|
||||
output[idx] = raw_output[raw_idx];
|
||||
idx++;
|
||||
}
|
||||
raw_idx++;
|
||||
}
|
||||
|
||||
g_fprintf(stderr, "%s\n", output);
|
||||
g_free(raw_output);
|
||||
g_free(output);
|
||||
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue