-
-
Notifications
You must be signed in to change notification settings - Fork 419
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
Add LogLevel as argument to LogFormatter #3597
Conversation
packages/logger/logger.pony
Outdated
@@ -97,15 +98,19 @@ type LogLevel is | |||
|
|||
primitive Fine | |||
fun apply(): U32 => 0 | |||
fun string(): String iso^ => recover String(4).>append("FINE") end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't need String(4) etc, the constant
"FINE"
will work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm getting compilation errors on 0.35.1:
/home/richard/code/pony/ponyc/packages/logger/logger.pony:101:32: can't recover to this capability
fun string(): String iso^ => recover iso "FINE" end
^
Info:
/home/richard/code/pony/ponyc/packages/logger/logger.pony:101:44: expression type is String val
fun string(): String iso^ => recover iso "FINE" end
^
I went with trying to return String iso^
so LogLevel implements the Stringable interface. I don't see much harm in returning String val
, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how we currently do in the rest of the standard library:
https://playground.ponylang.io/?gist=4d72cefd46cf9a24ba5e78d4e6e597de
So let's go with that for consistency.
Here's some examples:
primitive ExecveError
fun string(): String iso^ => "ExecveError".clone()
primitive PipeError
fun string(): String iso^ => "PipeError".clone()
primitive ForkError
fun string(): String iso^ => "ForkError".clone()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes. That is much nicer.
Done.
|
||
primitive DefaultLogFormatter is LogFormatter | ||
fun apply(msg: String, loc: SourceLoc): String => | ||
fun apply(lvl: LogLevel, msg: String, loc: SourceLoc): String => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should the default print the log level?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm leaning toward no. I think it violates expectations slightly by printing the log level used in create()
, rather than the log level used in the boolean before logging. E.g:
let logger = StringLogger(Info, env.out)
logger(Error) and logger.log("blah") // would print "INFO: blah"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm leaning towards no as well.
@@ -85,14 +90,14 @@ class _TestObjectLogging is _LoggerTest[U64] | |||
|
|||
fun level(): LogLevel => Fine | |||
|
|||
fun tag expected(): String => "42\n" | |||
fun tag expected(): String => "FINE: 42\n" | |||
|
|||
fun log(logger': Logger[U64]) => | |||
logger'(Error) and logger'.log(U64(42)) | |||
|
|||
primitive _TestFormatter is LogFormatter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there is much value in these test changes. I'd prefer to see them remain as they were.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
07b1e36
to
556a12e
Compare
Sweet. Thanks @rkallos. Now we can move forward with the Corral change. |
RFC text
Closes #3594