IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: 1.0
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

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 std.reflection import source_location

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

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

Returns:

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