Add something like __MODULE__ and __FUNCTION__ and __LINE__ #1833
Replies: 11 comments
-
Could be a good idea! I'd be interested in seeing what other languages use for this syntax wise. I recall NodeJS uses a |
Beta Was this translation helpful? Give feedback.
-
ElixirHas "Called #{__MODULE__}.#{__ENV__.function |> elem(0)}() in #{__ENV__.file}:#{__ENV__.line}"
# Called Elixir.Foo.bar() in /abs/path/to/test.exs:5 PHPHas these:
Source: https://www.php.net/manual/en/language.constants.magic.php RubyHas See: https://ruby-doc.org/core-2.5.0/doc/keywords_rdoc.html C++Seem to have Python
Source: https://docs.python.org/3/reference/datamodel.html#the-standard-type-hierarchy => Sub header JavaSeems to lack them, but allows to fetch values from the Stack Trace: https://www.recitalsoftware.com/blogs/152-howto-use-file-and-line-in-java-programs DartSeems to lack them, but allows to fetch similar values via Stack Trace: https://stackoverflow.com/a/65742207 SwiftHas them: https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#ID390 As of note swift also supports fetching of a NodeJSSeems to have PerlAt least has C#Not directly available, have to go through stacktrace or CallerInformation |
Beta Was this translation helpful? Give feedback.
-
After going through a languages the C-inherited I'd suggest to add these, if possible:
|
Beta Was this translation helpful? Give feedback.
-
Looks like it's overwhelmingly |
Beta Was this translation helpful? Give feedback.
-
Would these inject these values:
I feel like keeping file and dir separated may be helpful, also for cross platform compat? Else FILE could be a unix path ( |
Beta Was this translation helpful? Give feedback.
-
String sounds good. I could imagine
|
Beta Was this translation helpful? Give feedback.
-
Maybe a keyword could be added that yields a well structured Tuple to be consumed by custom logging/tracing/reporting tools such as stdout logging or sentry. // here `trace` would be an assumed keyword
// replacing `trace` with a truple of the constants above, resolved at compile time.
// `sentry.log` would be some userland module/function.
sentry.log(trace, "my_msg")` |
Beta Was this translation helpful? Give feedback.
-
I still think |
Beta Was this translation helpful? Give feedback.
-
Since every Gleam source file is a module, we could just use |
Beta Was this translation helpful? Give feedback.
-
Crashes come with a stacktrace so that's already covered 👍 |
Beta Was this translation helpful? Give feedback.
-
I would recommend against anything platform specific here as it could break caching across platforms. Similarly goes for adding stuff like |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
in
foo.gleam
:I would use this in production for things like Sentry.io logging.
Beta Was this translation helpful? Give feedback.
All reactions