Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: add support for @LOCATION, for more convenient logging/tracing, without needing to combine @FILE, @LINE at runtime #19488

Merged

Conversation

spytheman
Copy link
Member

@spytheman spytheman commented Oct 1, 2023

// abc
// def

fn abc() {
	eprintln(@LOCATION)
}

struct MyStruct {
}

fn MyStruct.new() MyStruct {
	eprintln(@LOCATION)
	return MyStruct{}
}

fn (s MyStruct) mymethod() {
	eprintln(@LOCATION)
}

eprintln(@LOCATION)
abc()
MyStruct.new().mymethod()
eprintln(@LOCATION)

produces:

/Users/delyanangelov/code/misc/2023_10_01__19/loc.v:20, main.main
/Users/delyanangelov/code/misc/2023_10_01__19/loc.v:5, main.abc
/Users/delyanangelov/code/misc/2023_10_01__19/loc.v:12, main.MyStruct.new (static)
/Users/delyanangelov/code/misc/2023_10_01__19/loc.v:17, main.MyStruct{}.mymethod
/Users/delyanangelov/code/misc/2023_10_01__19/loc.v:23, main.main

@spytheman spytheman changed the title all: add support for @LOCATION, for more convenient logging/tracing, without needing to combine @FILE, @LINE at runtime all: add support for @LOCATION, for more convenient logging/tracing, without needing to combine @FILE, @LINE at runtime Oct 1, 2023
@spytheman
Copy link
Member Author

spytheman commented Oct 1, 2023

This PR, also fixes dump(@FILE), dump(@LINE) etc, which printed the expanded version twice before, instead of showing the source name @FILE, @LINE etc, once, and then the expanded value, i.e.

0[20:19:46]@m1: (feature/at_location_pseudo_variable) ~/code/v $ v run l.v ## master
[l.v:3] 3: 3
0[20:19:52]@m1: (feature/at_location_pseudo_variable) ~/code/v $ ./v run l.v ## this PR
[l.v:3] @LINE: 3

doc/docs.md Show resolved Hide resolved
@Larpon
Copy link
Contributor

Larpon commented Oct 1, 2023

This is a huge time saver when used with return error(@LOCATION + 'message') or similar for locating where an error originally comes from

@spytheman
Copy link
Member Author

spytheman commented Oct 1, 2023

This is a huge time saver when used with return error(@LOCATION + 'message') or similar for locating where an error originally comes from

Should I add a space at the end of @LOCATION, to ease that (it currently does not have one)?

@spytheman spytheman merged commit 8d98a21 into vlang:master Oct 2, 2023
46 checks passed
@spytheman spytheman deleted the feature/at_location_pseudo_variable branch October 2, 2023 04:49
@lmptg
Copy link

lmptg commented Oct 2, 2023

This is a huge time saver when used with return error(@LOCATION + 'message') or similar for locating where an error originally comes from

Should I add a space at the end of @LOCATION, to ease that (it currently does not have one)?

Late to the party,

I do not think that it is necessary at this point in time - I can think of use-cases where you'd maybe not want an automatic white space. I can imagine that some errors might not need an extra message with simply error(@LOCATION) - and having error automatically strip white space from messages seems like a weird side effect. Also adding format to a comptime var feels odd

All good for now IMO 👍

@JalonSolov
Copy link
Contributor

Agreed... don't add a space at the end of @LOCATION - that's not the location any longer if you do.

Wertzui123 pushed a commit to Wertzui123/v that referenced this pull request Oct 8, 2023
…, without needing to combine `@FILE`, `@LINE` at runtime (vlang#19488)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants