Private module-level globals

I have a module with a root source file.

I want to share an instance of a scoped logger throughout my module.

One option is to put it in my root source file:

root.zig

pub const logger = std.log.scoped(.gatorcat);

And use it in other files like:

const logger = @import("root.zig").logger;

However, this has the downside that I will be exposing logger as part of my public-facing API (to users that import my module as a dependency).

Should I accept this?
Or create some sort of root_private.zig and share the logger internally that way?
Am I missing some other way to do this?

Call it log, instead of logger.
When you need it:

log.info("gatorcat scoped logger", .{});

For each file:

const log = std.log.scoped(.gatorcat);
4 Likes