Skip Menu |

This queue is for tickets about the App-Timestamper CPAN distribution.

Report information
The Basics
Id: 106258
Status: resolved
Priority: 0/
Queue: App-Timestamper

People
Owner: Nobody in particular
Requestors: PERLANCAR [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Format options
It'd be nice to offer an option for the timestamp format, e.g.: <UNIXTIMESTAMP>\ttext [<UNIXTIMESTAMP>]text [2015-08-05T21:33:00Z]text and so on.
Hi PERLANCAR, thanks for your report. On Wed Aug 05 10:34:06 2015, PERLANCAR wrote: Show quoted text
> It'd be nice to offer an option for the timestamp format, e.g.: > > <UNIXTIMESTAMP>\ttext > [<UNIXTIMESTAMP>]text > [2015-08-05T21:33:00Z]text >
My problem with your suggestion is that it can easily be implemented by a post-processing filter, like (untested): ... | perl -lapE '/\A([^\t]+)\t(.*)\z/ and print "[$1]$2"' furthermore, it will add complexity to the program, may hurt performance, may require adding more dependencies, and it stands against the UNIX philosophy that a command line tool should perform one task and perform it well. So I'm very reluctant to implement your suggestion. If you're so inclined you can write your own customisable processor for the output of App::Timestamper, and release it as a separate CPAN distribution, and I will consider linking to it from App-Timestamper's documentation. But I'm not too keen on adding unnecessary https://en.wikipedia.org/wiki/Feature_creep to App-Timestamper, especially given that I demonstrated it can be implemented by post-processing the [well-formed and well-defined] output. Hope that helps. Regards, -- Shlomi Fish
On 2015-08-05 11:57:52, SHLOMIF wrote: Show quoted text
> [...] and it stands > against the UNIX philosophy that a command line tool should perform > one task and perform it well.
At least this statement should not stand uncontradicted. Even cat(1), which is one of the most simple pipe-capable UNIX programs, lists eight options in its manpage on my FreeBSD box. The Linux version has even some more. In contrast, timestamper has zero options, which is quite _unusual_ for a UNIX tool. I am not the issue requester, but I would find it reasonable to add the possibility to use some common style of datetime formatting here. Implementation possibilities would be strftime (which would not add a non-core dependency to the module) or CLDR (which would add DateTime as a dependency, but this could be made optional). And there are techniques where this can be done without any performance penalties for the simple UNIX timestamp output. How could it look like? If using the strftime approach and we use date(1) as a existing UNIX tool which does datetime formatting, it could be as simple as: ... | timestamper +%FT%T which looks quite elegant comparing with any postprocessing solution. (An open question would be the handling of fraction seconds. strftime can handle only integer seconds, so one would have to invent an additional conversion specification, or hack %S and %T to add the fractional portion of the second. CLDR can handle the fractional portion)
Hi Shlomi, Thanks for your response. Show quoted text
> furthermore, it will add complexity to the program, may hurt > performance, may require adding more dependencies,
About performance: I'm not arguing that formatting Unix timestamp into ISO8601 or RFC822 format adds some overhead than just printing the timestamp. But this overhead is in the order of a couple of microseconds and should not matter for a lot of cases. And, for cases in which this matters, one can just use the raw Unix timestamp format. As for dependencies, one would only need the POSIX module (core since 5.0). Show quoted text
> and it stands > against the UNIX philosophy that a command line tool should perform > one task and perform it well.
True, but the tricky part is defining what constitutes as "one task" ;-) If the task is to be "print (or prepend) timestamp to input lines" (as the name "timestamper" would suggest, since the name is not "unix-timestamper"), then providing several date formats is not unreasonable.
Hi PERLANCAR, On Thu Aug 06 00:41:53 2015, PERLANCAR wrote: Show quoted text
> Hi Shlomi, > > Thanks for your response. >
> > furthermore, it will add complexity to the program, may hurt > > performance, may require adding more dependencies,
> > About performance: I'm not arguing that formatting Unix timestamp into > ISO8601 or RFC822 format adds some overhead than just printing the > timestamp. But this overhead is in the order of a couple of > microseconds and should not matter for a lot of cases. And, for cases > in which this matters, one can just use the raw Unix timestamp format.
Well, it may also add overhead of conditionals/etc. to choose between the options. Show quoted text
> > As for dependencies, one would only need the POSIX module (core since > 5.0).
Like Slaven noted - strftime() does not handle fractional seconds. Show quoted text
>
> > and it stands > > against the UNIX philosophy that a command line tool should perform > > one task and perform it well.
> > True, but the tricky part is defining what constitutes as "one task" > ;-)
In general, a single task in my opinion, is one which cannot be done by chaining the tool to another processing tool, which in this case is possible. Show quoted text
> If the task is to be "print (or prepend) timestamp to input lines" > (as the name "timestamper" would suggest, since the name is not "unix- > timestamper"), then providing several date formats is not > unreasonable. >
Well, you can always do it as a separate stage and this way keep "timestamper" free of unnecessary features , which I'll have to maintain for back-compat until infinity. If you don't like it, then either write a post-processor or fork App-Timestamper or whatever. And I might as well call it "gnu-linux-unix-perl-timestamper". ;-)
Hi all! Please see https://metacpan.org/pod/App::Timestamper#COMMON-REQUESTS for what I hope is an adequate resolution of this bug. Now you can have the time formatting and a pony. RESOLVEDing. Regards, -- Shlomi Fish