How to find out the source path of a function at compile time?

Hello there,

I’m very happy to tell you that my Zig OS is progressing well, I just implemented some ANSI Escape Sequence handling (for a framebuffer console).
But now I wanted to make a (relatively simple) kernel logging system that ideally prints out where the log message comes from. So I got the idea to print out the source path of a function relative to the root module.
That means, if I had a file src/kernel/terminal/UART.zig and in that file I had a putChar function and the root module was src/kernel/main.zig, I would like to output something like [terminal/UART.putChar], so [path.function]. Is anything like this possible in Zig?

Looking forwards,
Samuel Fiedler

Yes, @src returns the SourceLocation of its call.
fn_name is the function name, file,line and column are the source positions.

3 Likes

Oh, looked everywhere in langref but there :slight_smile: