#Is there a standard or popular logging API that is not based on string mushing?

1 messages · Page 1 of 1 (latest)

loud trench
#

Im just starting to learn zig. Is there a strongly typed logging api that allows capturing data as individual strongly typed data.

I notice there is a std.log api, but it appears to require mushing the log data into a string. Is there an alternate api for people who internationalize their code and want to be able to separately store the field data rather than mush it into a string, like the Uber Zap api?

logger.Info("CACHE_FETCH_FAILED",
  // Strongly typed structured Field values.
  zap.String("url", url),
  zap.String("ip", session.IP()),
  zap.Int("attempt", 3),
  zap.Duration("backoff", time.Second),
)
proper wyvern
#

would it be functionally different to passing in a struct?

log.debug("{any}", .{
  .{
    .url = url,
    .ip = session.IP(),
    .attempt = 3,
    .backoff = time.Seond,
  },
});
robust spoke
#

that can't be internationalized

loud trench
#

Technically yes, its a bit different, with a structured logger, underneath you still have the raw fields, so you can, for exampe

  • log those fields to a database, perhaps mapping the fields to individual database fields
  • later on, print those fields on a log screen (inserted into an a internationalised formatting string) for the current users language.

For example, imagine a spanish user or an english user opening the log screen of your webapp and seeing the log strings generated internationalised with the correct fields in the correct spot in the log message.

robust spoke
#

zig doesn't have an api like you want in its standard library. there might be an existing zig implementation, but I don't know one. if there's a c implementation of what you want, you can use it with zig. otherwise, you'll have to make it yourself (and maybe publish it as a package for other people to use)