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

Add LogLevel as argument to LogFormatter #3597

Merged
merged 1 commit into from
Jul 18, 2020
Merged

Conversation

rkallos
Copy link
Contributor

@rkallos rkallos commented Jul 18, 2020

RFC text

Closes #3594

@@ -97,15 +98,19 @@ type LogLevel is

primitive Fine
fun apply(): U32 => 0
fun string(): String iso^ => recover String(4).>append("FINE") end
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

@SeanTAllen SeanTAllen Jul 18, 2020

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()

Copy link
Contributor Author

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 =>
Copy link
Member

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?

Copy link
Contributor Author

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"

Copy link
Member

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
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

@rkallos rkallos force-pushed the rfc0067 branch 2 times, most recently from 07b1e36 to 556a12e Compare July 18, 2020 15:37
@SeanTAllen SeanTAllen added the changelog - changed Automatically add "Changed" CHANGELOG entry on merge label Jul 18, 2020
@SeanTAllen SeanTAllen changed the title Implement RFC0067: Add LogLevel argument to LogFormatter (issue #3594) Add LogLevel argument to LogFormatter Jul 18, 2020
@SeanTAllen SeanTAllen changed the title Add LogLevel argument to LogFormatter Add LogLevel as argument to LogFormatter Jul 18, 2020
@SeanTAllen SeanTAllen mentioned this pull request Jul 18, 2020
@SeanTAllen
Copy link
Member

Sweet. Thanks @rkallos. Now we can move forward with the Corral change.

@SeanTAllen SeanTAllen merged commit 4d4cb92 into ponylang:master Jul 18, 2020
github-actions bot pushed a commit that referenced this pull request Jul 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog - changed Automatically add "Changed" CHANGELOG entry on merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFC: Add a log_level argument to logger.LogFormatter
2 participants