log.zig icon indicating copy to clipboard operation
log.zig copied to clipboard

Change API to reduce typing

Open demizer opened this issue 5 years ago • 0 comments

With Zig 0.6.0, any functions "interfacing" with io.out_stream() via fmt.format() need to pass a literal struct with the format string. So if Logger.logDebug() is used without placeholders in the format string, then users must still pass an empty struct literal. This looks like Logger.logDebug("hello", .{});.

I propose typing be reduced in two ways:

  1. Remove the redundant log before Debug to allow the function to become Logger.Debug()
  2. Add the Debugf function for use cases where formatting place holders are needed. The new function would look like Logger.Debugf("hello {}\n", .{world});.

This will allow Logger.Debug("hi"); to continue to work as originally intended, but also give users the ability to use format strings when needed but also not have to type empty struct literals every time when format strings are not needed.

I will submit a PR for these changes for approval.

Thanks!

demizer avatar May 04 '20 01:05 demizer