]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
script: add --logging-format
authorKarel Zak <kzak@redhat.com>
Wed, 19 Jun 2019 13:47:44 +0000 (15:47 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 8 Oct 2019 11:11:53 +0000 (13:11 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
term-utils/script.1
term-utils/script.c

index 9c558b1294bb639266ad8254db5414c4c21d95a1..3f0550f3ee9cccafb3ad0d4ba772b95683ada776 100644 (file)
@@ -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.
index 91d24eb12517917a8c4e0ed66cfc76d00ae24aa2..6569c98f4907321787aaeef6e8c9cc0542d33942 100644 (file)
@@ -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 "<delta> <offset>" format */
-       SCRIPT_FMT_TIMING_MULTI,        /* multiple streams in format "<type> <delta> <offset|etc> */
+       SCRIPT_FMT_TIMING_SIMPLE,       /* (classic) in format "<delta> <offset>" */
+       SCRIPT_FMT_TIMING_MULTI,        /* (advanced) multiple streams in format "<type> <delta> <offset|etc> */
 };
 
 struct script_log {
@@ -208,6 +208,7 @@ static void __attribute__((__noreturn__)) usage(void)
 
        fputs(_(" -T, --log-timing <file>       log timing information to file\n"), out);
        fputs(_(" -t[<file>], --timing[=<file>] deprecated alias to -T (default file is stderr)\n"), out);
+       fputs(_(" -m, --logging-format <name>   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)