Giter VIP home page Giter VIP logo

Comments (5)

renancaju avatar renancaju commented on June 2, 2024

It would still need a standard way to generate UUID's with the ZIO library, which I don't think there is right now.

from zio-logging.

pshemass avatar pshemass commented on June 2, 2024

I see what you mean but I'm not exactly convinced to your approach
in pipe example

val pipe = for {
  user <- UserRepository.findById(userId).logError(e => s"Error finding user: $e")
  credit <- BalanceRepository.getBalanceByUserId(userId).logInfo(b => s"Balance of $b found")
} yield ()

I like logError part but not logInfo part. I would write this

val pipe = for {
  user <- UserRepository.findById(userId).logError(e => s"Error finding user: $e")
  credit <- BalanceRepository.getBalanceByUserId(userId)
  _ <- log.info(b => s"Balance of $b found")
} yield ()

for withCorrelatationId and withLoggerName I would say no. I prefer to have something like

import LogAnnotation._
log.annotate(CorrelationId(), Name("UserBalanceService"), OtherRandomAnnotation("foo")) {
  pipe
}

what do you think @renancaju about this?

from zio-logging.

renancaju avatar renancaju commented on June 2, 2024

About the logInfo bit, yeah, I guess it's not great. But imagine you just want to log the result like this:

_ <- BalanceRepository.getBalanceByUserId(userId).logInfo(_.toString)

I feel it would be better than:

balance <- BalanceRepository.getBalanceByUserId(userId)
_ <- log.info(balance.toString)

About the annotation composability you proposed, you mean making LogAnnotation a trait and creating case classes extending that trait like CorrelationId, Name, etc? Or those case classes would extends some other trait that would be like LogAnnotation recipes?

One thing I like better in the syntax I proposed is that you avoid nesting and give emphasis to the business logic (the pipe) instead of logging (which is the first thing that appears if you use the current syntax).

Of course, these are opinions based on my usage only and totally subjective. Other people might feel differently.

from zio-logging.

pshemass avatar pshemass commented on June 2, 2024

as you mentioned this is all subjective. For me for in scala or do in haskell ware created to help organize code in sequence vertically so argument with one liner in for doesn't resonate with me :)

even with today structure you can do this

log.locally(CorrelationId(Some(uuid)).andThen(Name("loggerName" :: Nil)){ pipe }

maybe it's a matter to add shortcut for that. What do you think?

from zio-logging.

renancaju avatar renancaju commented on June 2, 2024

Sorry, I guess I missed the apply method on LogAnnotation that returns a LogContext => LogContext, which makes everything compose nicely...

I guess the only improvement in my suggestions would be regarding the generation of UUIDs automatically. But since there is no standard way of doing so with ZIO, I guess it would not be in the scope of zio-logging. Maybe an external zio-utils package could solve it.

Sorry to waste your time! For me it was really valuable, cause I learned something from this interaction 😄

from zio-logging.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.