nbdkit_timestamp(3)

πŸ“¦
version 1.48.1 Β· 4 versions
, in fedora 44

✨ nbdkit_timestamp β€” it's giving clock energy πŸ•πŸ’–

okay bestie so this is a page from the nbdkit manual, and it's about one tiny little function that hands you a timestamp you can slap into your log messages. it's so cute and so useful, you're gonna be obsessed πŸ’…


🌸 NAME 🌸

nbdkit_timestamp β€” generate a timestamp for log messages ✨


πŸŽ€ SYNOPSIS πŸŽ€

#include <nbdkit-plugin.h>

const char *nbdkit_timestamp (void);

like, that's it. one function, zero arguments, maximum slay 🫢


πŸ’– DESCRIPTION πŸ’–

so nbdkit_timestamp generates a timestamp as a printable string, and you can add it to your debug or error messages (peep nbdkit_debug(3) and nbdkit_error(3) for that, iykyk).

you can use it 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

okay so the timestamps show the wallclock time in approximately ISO 8601 format, but less ugly. we love that for us. 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 β€” no cap, that's just how it is πŸͺŸ)

and bestie, you can also separate the nbdkit_timestamp() call from the place where it's used, which lets you accurately timestamp, for example, the exact 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;
}

literally the main character energy of logging πŸ’…


⭐ RETURN VALUE ⭐

the function returns a constant string allocated in thread-local storage. that string is valid until the next call to nbdkit_timestamp in the same thread. so don't go holding onto it forever, okay? πŸ™ˆ

it never returns NULL. in the (very unlikely) case that there was an error generating the timestamp, the string "!" is returned. dramatic but honest πŸ’€


πŸ¦‹ 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

all the languages ate, periodt 🌈


🌟 HISTORY 🌟

nbdkit_timestamp was added in nbdkit 1.48. a legend was born ✨


πŸ‘€ SEE ALSO πŸ‘€

go read them, they're all bangers fr fr πŸ“š


πŸ’œ AUTHORS πŸ’œ

Richard W.M. Jones β€” icon behavior πŸ‘‘


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.

and that's the whole page bestie πŸ₯° this came from nbdkit-1.48.1, dated 2026-08-29, and it's page nbdkit_timestamp(3) of the manual. go forth and timestamp everything πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from