Skip to main content

Mojo function

source_location

source_location() -> SourceLocation

Returns the location for where this function is called.

This currently doesn't work when called in a parameter expression.

Example:

from reflection import source_location

fn log_message(msg: String):
    var loc = source_location()
    print("[", loc.file_name, ":", loc.line, "]", msg)

fn main():
    log_message("hello")  # Prints: [ /path/to/file.mojo : 4 ] hello

Returns:

SourceLocation: The location information of the source_location() call.

Was this page helpful?