From: Karel Zak Date: Wed, 19 Jun 2019 13:47:44 +0000 (+0200) Subject: script: add --logging-format X-Git-Tag: v2.35-rc1~162 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=daee4d95aea711cf77c1e86ed52864d1241c49d3;p=thirdparty%2Futil-linux.git script: add --logging-format Signed-off-by: Karel Zak --- diff --git a/term-utils/script.1 b/term-utils/script.1 index 9c558b1294..3f0550f3ee 100644 --- a/term-utils/script.1 +++ b/term-utils/script.1 @@ -40,10 +40,13 @@ script \- make typescript of terminal session .RI [ file ] .SH DESCRIPTION .B script -makes a typescript of everything displayed on your terminal. It is useful for -students who need a hardcopy record of an interactive session as proof of an -assignment, as the typescript file can be printed out later with -.BR lpr (1). +makes a typescript of everything on your terminal session. The terminal +data are stored in raw form to the log file and information about timing +to another (optional) structured log file. The timing log file is necessary to replay +the session later by +.B scriptreplay (1) +and to store additional information about the session. +.PP Since version 2.35 .B script supports multiple streams and allows to log input and output to separate @@ -118,6 +121,12 @@ Log timing information to the \fIfile\fR. Two timing file formats are supporte now. The classic format is used when only one stream (input or output) logging is enabled. The multi-stream format is used on \fB\-\-log\-io\fR or when \fB\-\-log\-in\fR and \fB\-\-log\-out\fR are used together. +See also \fB\-\-log\-format\fR. +.TP +\fB\-m\fR, \fB\-\-log\-format\fR \fIformat\fR +Force use 'advanced' or 'classic' format. The default is the classic format to +log only output and the advanced format when input as well as output logging is +requested. .sp .RS .B Classic format @@ -126,7 +135,7 @@ The log contains two fields, separated by a space. The first field indicates how much time elapsed since the previous output. The second field indicates how many characters were output this time. .sp -.B Multi-stream format +.B Advanced (multi-stream) format .PP The first field is entry type itentifier ('I'nput, 'O'utput, 'H'eader, 'S'ignal). The socond field is how much time elapsed since the previous entry, and rest of the entry is type specific data. diff --git a/term-utils/script.c b/term-utils/script.c index 91d24eb125..6569c98f49 100644 --- a/term-utils/script.c +++ b/term-utils/script.c @@ -111,8 +111,8 @@ UL_DEBUG_DEFINE_MASKNAMES(script) = UL_DEBUG_EMPTY_MASKNAMES; */ enum { SCRIPT_FMT_RAW = 1, /* raw slave/master data */ - SCRIPT_FMT_TIMING_SIMPLE, /* timing info in classic " " format */ - SCRIPT_FMT_TIMING_MULTI, /* multiple streams in format " */ + SCRIPT_FMT_TIMING_SIMPLE, /* (classic) in format " " */ + SCRIPT_FMT_TIMING_MULTI, /* (advanced) multiple streams in format " */ }; struct script_log { @@ -208,6 +208,7 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_(" -T, --log-timing log timing information to file\n"), out); fputs(_(" -t[], --timing[=] deprecated alias to -T (default file is stderr)\n"), out); + fputs(_(" -m, --logging-format force to 'classic' or 'advanced' format\n"), out); fputs(USAGE_SEPARATOR, out); fputs(_(" -a, --append append to the log file\n"), out); @@ -950,6 +951,7 @@ int main(int argc, char **argv) {"log-out", required_argument, NULL, 'O'}, {"log-io", required_argument, NULL, 'B'}, {"log-timing", required_argument, NULL, 'T'}, + {"logging-format", required_argument, NULL, 'm'}, {"output-limit", required_argument, NULL, 'o'}, {"quiet", no_argument, NULL, 'q'}, {"timing", optional_argument, NULL, 't'}, @@ -977,7 +979,7 @@ int main(int argc, char **argv) script_init_debug(); - while ((ch = getopt_long(argc, argv, "aB:c:efI:O:o:qT:t::Vh", longopts, NULL)) != -1) { + while ((ch = getopt_long(argc, argv, "aB:c:efI:O:o:qm:T:t::Vh", longopts, NULL)) != -1) { err_exclusive_options(ch, longopts, excl, excl_st); @@ -1016,6 +1018,14 @@ int main(int argc, char **argv) case 'q': ctl.quiet = 1; break; + case 'm': + if (strcasecmp(optarg, "classic") == 0) + format = SCRIPT_FMT_TIMING_SIMPLE; + else if (strcasecmp(optarg, "advanced") == 0) + format = SCRIPT_FMT_TIMING_MULTI; + else + errx(EXIT_FAILURE, _("unssuported logging format: '%s'"), optarg); + break; case 't': if (optarg && *optarg == '=') optarg++; @@ -1057,6 +1067,10 @@ int main(int argc, char **argv) format = outfile && infile ? SCRIPT_FMT_TIMING_MULTI : SCRIPT_FMT_TIMING_SIMPLE; + + else if (format == SCRIPT_FMT_TIMING_SIMPLE && outfile && infile) + errx(EXIT_FAILURE, _("log multiple streams is mutually " + "exclusive with 'classic' format")); if (outfile) log_associate(&ctl, &ctl.out, timingfile, format); if (infile)