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 NoOpFactory implicit in package object #681

Closed

Conversation

armanbilge
Copy link
Member

This is the no-op equivalent of:

implicit def loggerFactoryforSync[F[_]: Sync]: Slf4jFactory[F] = new Slf4jFactory[F] {

Copy link
Member

@danicheg danicheg left a comment

Choose a reason for hiding this comment

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

We intentionally didn't add an implicit method when adding NoOpFactory, see. I personally beware of this kind of thing since it accidentally may hurt someone in $PROD. Especially considering that some $IDE can suggest import when implicit value is required. But I can be overthinking about this. So, if the majority will be happy with this implicit method, I will be happy too.

@armanbilge
Copy link
Member Author

Especially considering that some $IDE can suggest import when implicit value is required.

If this is so dangerous then I argue that LoggerFactory actually should not be an implicit at all. Since there can be multiple implementations, doesn't this go against our philosophy anyway?

@danicheg
Copy link
Member

Since there can be multiple implementations, doesn't this go against our philosophy anyway?

Sorry, I don't quite follow your idea. I mean that if this method is just for tests, then it shouldn't be too hard to create an implicit instance on the user side. Or, probably, we can add this method straightforwardly to the testing module. Then it'd be a little safer from accidental bugs. But again, all of this could be just my imagination.

@armanbilge
Copy link
Member Author

Ok, fair enough. My motivation is that currently there is no LoggerFactory for Scala.js. But maybe better to solve that problem directly.

We will have a bigger problem for Scala Native, because there is no standard logging framework there.

@armanbilge
Copy link
Member Author

Or, probably, we can add this method straightforwardly to the testing module.

To be fair, it's already isolated to the no-op module. If no-op was part of core that would be a bigger problem, but seems just as hard to add a no-op dependency as it is to add testing dependency :)

@danicheg
Copy link
Member

If no-op was part of core that would be a bigger problem, but seems just as hard to add a no-op dependency as it is to add testing dependency :)

Yeah, true. Probably initial authors considering this fine. So I'm speaking just as a random guy from the community 🙇🏻‍♂️

@lorandszakacs
Copy link
Member

LGTM. The implicit LoggerFactory for a Sync in slf4j module is way more dangerous :D and if we live with that we can at least be consistent about it.

@armanbilge
Copy link
Member Author

armanbilge commented Aug 23, 2022

@lorandszakacs actually I'm considering to retract this PR 😅

After some discussion I think it is wrong for LoggerFactory to be passed around implicitly, as I mentioned in #681 (comment).

question: should LoggerFactory be an implicit or explicit parameter? Seeing as there are multiple implementations (slf4j, noop, maybe something from otel4s in the future) seems to go against our usual philosophy for implicits?

oh and this PR would throw one more source of LoggerFactory into the mix 🙂

To which @ChristopherDavenport replies:

Multiple implementations is explicit.

https://discord.com/channels/632277896739946517/839254871646404638/1011694989870366770

Instead, I think we should deprecate and discourage implicit use of the Sl4fj factory.

@lorandszakacs
Copy link
Member

I also lean towards deprecating the implicit creation of the factory in slf4j, in which case this indeed should be closed 😄

But I do not agree with encouraging people to not pass LoggerFactory implicitly, only with its automagic implicit creation. At the end of the day how many users will have more than one instance of a LoggerFactory in their codebase? And if they do, there always various ways of newtype-ing, or subclassing it, etc. to solve the problem. For large codebases with literally hundreds of classes 90% of which do logging users will probably pass these around implicitly.

@bplommer
Copy link
Contributor

Why not provide this as a convenience but in an implicits namespace, like we do with (for example) the cats-effect global runtime? That way it's not just "floating around out there" but it's available in a convenient form when needed.

@lorandszakacs
Copy link
Member

@armanbilge Shall we close this PR, and see if @bplommer's idea lands either in #683 or a follow-up?

@armanbilge
Copy link
Member Author

Ah yes, I think we're all agreed we don't want to do this.

@armanbilge armanbilge closed this Sep 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants