Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

enhancement: logX should not be a string interpolator #35

Closed
pfn opened this issue Aug 20, 2014 · 7 comments
Closed

enhancement: logX should not be a string interpolator #35

pfn opened this issue Aug 20, 2014 · 7 comments

Comments

@pfn
Copy link

pfn commented Aug 20, 2014

it removes room for one to use other string interpolators, e.g. for formatting (f)

also, logX doesn't do anything special other than insert the variables. no reason to use string interp. and it looks ugly

logV"foo"() ? yuck :(

logV(f"$interp%02d") that's pretty reasonable (all other implicits for logtag, etc. are ok)

@dant3
Copy link

dant3 commented Aug 21, 2014

+1, noticed that too recently. It will look more reasonable as 1-arg fn, so you could write logV "foo" instead of logV"foo"()

----- Reply message -----
ïÔ: "Perry" notifications@github.com
ëÏÍÕ: "macroid/macroid" macroid@noreply.github.com
ôÅÍÁ: [macroid] enhancement: logX should not be a string interpolator (#35)
äÁÔÁ: ÓÒ, Á×Ç. 20, 2014 23:39

it removes room for one to use other string interpolators, e.g. for formatting (f)

also, logX doesn't do anything special other than insert the variables. no reason to use string interp. and it looks ugly

logV"foo"() ? yuck :(

logV(f"$interp%02d") that's pretty reasonable (all other implicits for logtag, etc. are ok)

Reply to this email directly or view it on GitHubhttps://github.com//issues/35.

@stanch
Copy link
Collaborator

stanch commented Aug 21, 2014

Agreed. The initial intuition was that s"" is very convenient to use with logging, but with time I find the result more and more ugly. 1-arg function, however, wouldn’t work with default log tag, or am I missing something?

@stanch
Copy link
Collaborator

stanch commented Aug 21, 2014

What about this?

// manual tag
log("tag").d("foo")

// no tag
log.d("foo")

// implicit tag
implicit val logTag = LogTag("tag")
log.d("foo")

stanch added a commit that referenced this issue Aug 21, 2014
@dant3
Copy link

dant3 commented Aug 21, 2014

1arg function like this should work fine:

logD(msg: String)(implicit logTag: LogTag)

It can have a friend like this

logD(logTag: String, msg: String)

But your approach with log.d should work too, however Im not sure about it runtime efficiency vs above, since log(x) should return ongoing logger with tag supplied as I see it.

@stanch
Copy link
Collaborator

stanch commented Aug 21, 2014

Weird, I can’t enable formatting in your comment. Anyway, could you elaborate?

scala> def logD(msg: String)(implicit a: Int = 1) = msg
logD: (msg: String)(implicit a: Int)String

scala> logD "foo"
<console>:1: error: ';' expected but string literal found.
       logD "foo"
            ^

It would also be definitely broken because of overloading (to support Throwable arguments).

If you are really concerned about runtime efficiency, it should probably be made into a macro.

@dant3
Copy link

dant3 commented Aug 21, 2014

Yep, It can't be used without parentheses, of course, only like here: http://scastie.org/6297
I'm not sure how macro will help here (they are still sort of dark magic for me, I'm still learning scala)

stanch added a commit that referenced this issue Mar 9, 2015
@stanch
Copy link
Collaborator

stanch commented Apr 6, 2015

I’ve just noticed that the commit referenced here went into M4. I’m not very happy about the object creation overhead. Regardless, do you guys think we actually need any logging functionality in Macroid? Probably slf4j-android + scala-logging give the same effect with more flexibility...

stanch added a commit that referenced this issue Apr 12, 2015
This functionality does not really belong in Macroid.
A possible replacement is a combination of [1] and [2].
Also see #35.

[1] http://www.slf4j.org/android/
[2] https://github.com/typesafehub/scala-logging
@stanch stanch closed this as completed Apr 12, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants