nbdkit_timestamp(3)

NAME
nbdkit_timestamp - generate a timestamp for log messages

SYNOPSIS
 #include <nbdkit-plugin.h>

 const char *nbdkit_timestamp (void);

DESCRIPTION
"nbdkit_timestamp" generates a timestamp as a printable string which may be added to debug or error messages (see nbdkit_debug(3), nbdkit_error(3)).

It can be used like this:

 nbdkit_debug ("%s: this is a debug message", nbdkit_timestamp ());

which would produce a debug message like this:

 debug: 2026-01-01 12:00:00.000333: this is a debug message

The timestamps show the wallclock time in approximately ISO 8601 format, but less ugly. They are always shown in UTC, in 24 hour notation, to the nearest microsecond. (On Windows, timestamps use the same format but are rounded to the nearest millisecond.)

You can also separate the nbdkit_timestamp() call from the place where it is used, allowing you to accurately timestamp, for example, the point when a system call was invoked:

 const char *ts = nbdkit_timestamp ();
 int r = pwrite (fd, ...);
 if (r == -1) {
   /* The error message shows the time that pwrite started. */
   nbdkit_error ("%s: pwrite: %m", ts);
   return -1;
 }

RETURN VALUE
The function returns a constant string allocated in thread-local storage. The string is valid until the next call to "nbdkit_timestamp" in the same thread.

It never returns "NULL". In the (very unlikely) case that there was an error generating the timestamp, the string "!" is returned.

LANGUAGE BINDINGS
In nbdkit-ocaml-plugin(3):

 NBDKit.timestamp : unit -> string

In nbdkit-python-plugin(3):

 import nbdkit
 ts = nbdkit.timestamp()

In nbdkit-rust-plugin(3):

 use nbdkit::*;
 pub fn timestamp() -> String

HISTORY
"nbdkit_timestamp" was added in nbdkit 1.48.

SEE ALSO
nbdkit(1), nbdkit_debug(3), nbdkit_error(3), nbdkit-plugin(3), nbdkit-filter(3).

AUTHORS
Richard W.M. Jones

COPYRIGHT
Copyright Red Hat

LICENSE
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

•   Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

•   Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

•   Neither the name of Red Hat nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.