summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Steven Schubiger <stsc@refcnt.org>2019-02-27 21:36:42 +0100
committerGravatar Steven Schubiger <stsc@refcnt.org>2019-02-27 21:36:42 +0100
commitf7129232181024d51c0ea234a49e3525c464e3d6 (patch)
tree82f807e2612fa21bdf6ef51db49503f92a0a6c04
parentc8d98f146989adf92c440e78b47b554b427ddf79 (diff)
downloadcolorize-f7129232181024d51c0ea234a49e3525c464e3d6.tar.gz
Print timestamp at top of debug output
-rw-r--r--colorize.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/colorize.c b/colorize.c
index f91af67..59cab41 100644
--- a/colorize.c
+++ b/colorize.c
@@ -253,6 +253,7 @@ static char *exclude;
static const char *program_name;
+static void print_tstamp (FILE *);
static void process_opts (int, char **);
static void process_opt_attr (const char *);
static void write_attr (const struct attr *, unsigned int *);
@@ -327,6 +328,7 @@ main (int argc, char **argv)
#if DEBUG
log = open_file (DEBUG_FILE, "w");
+ print_tstamp (log);
#endif
attr[0] = '\0';
@@ -370,6 +372,31 @@ main (int argc, char **argv)
exit (EXIT_SUCCESS);
}
+static void
+print_tstamp (FILE *log)
+{
+ time_t t;
+ struct tm *tm;
+ char str[128];
+ size_t written;
+
+ t = time (NULL);
+ tm = localtime (&t);
+ if (tm == NULL)
+ {
+ perror ("localtime");
+ exit (EXIT_FAILURE);
+ }
+ written = strftime (str, sizeof (str), "%Y-%m-%d %H:%M:%S %Z", tm);
+ if (written == 0)
+ vfprintf_fail (formats[FMT_GENERIC], "strftime: 0 returned");
+
+ fprintf (log, "%s\n", str);
+ while (written--)
+ fprintf (log, "=");
+ fprintf (log, "\n");
+}
+
#define PRINT_HELP_EXIT() \
print_help (); \
exit (EXIT_SUCCESS);