#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
use POSIX qw( strftime );

my $message = '';
my @tags;
GetOptions(
    'm=s' => \$message,
    't=s' => \@tags,
);

die "Your message may not contain tabs\n" if $message =~ m/\t/;
for my $tag (@tags) {
    die "Your tags may not contain commas\n" if $tag =~ m/,/;
    die "Your tags may not contain tabs\n"   if $tag =~ m/\t/;
}

my @parts;
push @parts, sprintf( "identity:%s", 'michael@ndrix.com' );
push @parts, sprintf( "time:%s",     strftime( '%FT%TZ', gmtime ) );
push @parts, sprintf( "tags:%s",     join( ',', @tags ) ) if @tags;
push @parts, sprintf( "message:%s",  $message );
my $line = join "\t", @parts;
print "$line\n";

#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
use POSIX qw( strftime );
use Time::HiRes qw( gettimeofday );

my $message = '';
my @tags;
GetOptions(
    'm=s' => \$message,
    't=s' => \@tags,
);

die "Your message may not contain tabs\n" if $message =~ m/\t/;
for my $tag (@tags) {
    die "Your tags may not contain commas\n" if $tag =~ m/,/;
    die "Your tags may not contain tabs\n"   if $tag =~ m/\t/;
}

my @parts;
push @parts, sprintf( "identity:%s", 'michael@ndrix.com' );
push @parts, sprintf( "time:%s",     iso8601_now() );
push @parts, sprintf( "tags:%s",     join( ',', @tags ) ) if @tags;
push @parts, sprintf( "message:%s",  $message );
my $line = join "\t", @parts;
print "$line\n";

sub iso8601_now {
    my ( $seconds, $microseconds ) = gettimeofday();
    my $fraction = sprintf( '%06d', $microseconds );
    return strftime( "%FT%T.${fraction}Z", gmtime($seconds) );
}

Include microseconds in the time stamp
Include microseconds in the time stamp

It's easy enough to include microseconds that it might as well be
included from the outset.

The idea of this rough program is to store entries in a giant time
line (one time line per "identity").  Each entry records a message and
some tags along with it.  The output of clk-in.pl is suitable for
storing in a file with one record per line.  A nice benefit of this
arrangement is that "cat time-line-A time-line-B | sort > time-line"
can merge two time lines.

It will probably make sense to add whitespace padding at the end of
each line so that the time line file can be treated as a list of fixed
width records.

Signed-off-by: Michael Hendricks <17b9e1c64588c7fa6419b4d29dc1f4426279ba01@ndrix.org>
