Skip to content

Commit

Permalink
Implement RFC0067
Browse files Browse the repository at this point in the history
  • Loading branch information
rkallos authored and SeanTAllen committed Jul 18, 2020
1 parent e393e9a commit 4d4cb92
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/logger/_test.pony
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class _TestObjectLogging is _LoggerTest[U64]
logger'(Error) and logger'.log(U64(42))

primitive _TestFormatter is LogFormatter
fun apply(msg: String, loc: SourceLoc): String =>
fun apply(lvl: LogLevel, msg: String, loc: SourceLoc): String =>
msg + "\n"

actor _TestStream is OutStream
Expand Down
11 changes: 8 additions & 3 deletions packages/logger/logger.pony
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ override the standard formatting, you can create an object that implements:
```pony
interface val LogFormatter
fun apply(
level: LogLevel,
msg: String,
file_name: String,
file_linenum: String,
Expand All @@ -97,15 +98,19 @@ type LogLevel is

primitive Fine
fun apply(): U32 => 0
fun string(): String iso^ => recover "FINE".clone() end

primitive Info
fun apply(): U32 => 1
fun string(): String iso^ => recover "INFO".clone() end

primitive Warn
fun apply(): U32 => 2
fun string(): String iso^ => recover "WARN".clone() end

primitive Error
fun apply(): U32 => 3
fun string(): String iso^ => recover "ERRR".clone() end

class val Logger[A]
let _level: LogLevel
Expand All @@ -128,7 +133,7 @@ class val Logger[A]
level() >= _level()

fun log(value: A, loc: SourceLoc = __loc): Bool =>
_out.print(_formatter(_f(consume value), loc))
_out.print(_formatter(_level, _f(consume value), loc))
true

primitive StringLogger
Expand All @@ -149,10 +154,10 @@ interface val LogFormatter
See `DefaultLogFormatter` for an example of how to implement a LogFormatter.
"""
fun apply(msg: String, loc: SourceLoc): String
fun apply(lvl: LogLevel, msg: String, loc: SourceLoc): String

primitive DefaultLogFormatter is LogFormatter
fun apply(msg: String, loc: SourceLoc): String =>
fun apply(lvl: LogLevel, msg: String, loc: SourceLoc): String =>
let file_name: String = loc.file()
let file_linenum: String = loc.line().string()
let file_linepos: String = loc.pos().string()
Expand Down

0 comments on commit 4d4cb92

Please sign in to comment.